diff --git a/003_aligned.png b/003_aligned.png new file mode 100644 index 0000000..d73c3f3 Binary files /dev/null and b/003_aligned.png differ diff --git a/plugins/ai_face_recog/ai_face_recog_node.cpp b/plugins/ai_face_recog/ai_face_recog_node.cpp index a12545e..b3f125c 100644 --- a/plugins/ai_face_recog/ai_face_recog_node.cpp +++ b/plugins/ai_face_recog/ai_face_recog_node.cpp @@ -13,6 +13,12 @@ #include #include +// For test image loading +#define STB_IMAGE_IMPLEMENTATION +#define STBI_ONLY_PNG +#define STBI_NO_FAILURE_STRINGS +#include "../../third_party/rknpu2/examples/3rdparty/stb/stb_image.h" + #include "ai_scheduler.h" #include "face/face_result.h" #include "node.h" @@ -709,6 +715,49 @@ public: const float thr_margin = cfg ? cfg->thr_margin : 0.0f; LogInfo("[ai_face_recog] start id=" + id_ + " align=" + std::string(align ? "true" : "false") + " thr_accept=" + std::to_string(thr_accept) + " thr_margin=" + std::to_string(thr_margin)); + + // ========== TEST: Load aligned image and run inference ========== +#if defined(RK3588_ENABLE_RKNN) + { + const char* test_img_path = "./003_aligned.png"; + int img_w = 0, img_h = 0, img_c = 0; + unsigned char* img_data = stbi_load(test_img_path, &img_w, &img_h, &img_c, 3); + if (img_data && img_w == 112 && img_h == 112) { + std::cerr << "[TEST] Loaded " << test_img_path << " (" << img_w << "x" << img_h << "x" << img_c << ")\n"; + + InferInput in; + in.width = 112; + in.height = 112; + in.is_nhwc = true; + in.data = img_data; + in.size = 112 * 112 * 3; + in.type = RKNN_TENSOR_UINT8; + + auto r = AiScheduler::Instance().InferBorrowed(model_handle_, in); + if (r.success && !r.outputs.empty()) { + std::vector emb; + if (DecodeEmbedding(r.outputs[0], emb)) { + L2Normalize(emb); + std::cerr << "[TEST] RKNN embedding[0:8]: "; + for (int i = 0; i < 8 && i < static_cast(emb.size()); ++i) { + std::cerr << emb[i] << " "; + } + std::cerr << "\n"; + } else { + std::cerr << "[TEST] DecodeEmbedding failed\n"; + } + } else { + std::cerr << "[TEST] Inference failed: " << r.error << "\n"; + } + stbi_image_free(img_data); + } else { + if (img_data) stbi_image_free(img_data); + std::cerr << "[TEST] Skip: " << test_img_path << " not found or wrong size\n"; + } + } +#endif + // ========== END TEST ========== + return true; }