add compare bin proto
git-svn-id: http://192.168.1.226/svn/proxy@668 454eff88-639b-444f-9e54-f578c98de674
| | |
| | | STFaceCacheContext() : handle_verify(nullptr), handle_detect(nullptr) |
| | | { |
| | | } |
| | | |
| | | stface_handles getStFaceHandles() |
| | | { |
| | | //return (stface_handles*)this; |
| | | |
| | | stface_handles handles; |
| | | handles.handle_verify = handle_verify; |
| | | handles.handle_detect = handle_detect; |
| | | return handles; |
| | | } |
| | | }; |
| | | |
| | | struct STFaceDBContext |
| | |
| | | else |
| | | return FDP_FaceDetectResult(img.db_id, idx, 0); |
| | | } |
| | | |
| | | FDP_FaceDetectResult STFaceCache::compare(const STFaceImage& img1, const STFaceImage& img2) |
| | | { |
| | | stface_ctx_map_t& dbContext(*(stface_ctx_map_t*)_dbContext); |
| | | STFaceCacheContext& cacheContext(*(STFaceCacheContext*)_cacheContext); |
| | | |
| | | stface_handles handles(cacheContext.getStFaceHandles()); |
| | | float c = stface_compare(handles, img1, img2); |
| | | FDP_FaceDetectResult result(0, 0, int(c * 1000)); |
| | | return result; |
| | | } |
| | |
| | | FDP_FaceDetectResult detect(const STFaceImage& img); |
| | | FDP_FaceDetectResult add(const STFaceImage& img); |
| | | fdr_vec_t search(const STFaceImage& img); |
| | | FDP_FaceDetectResult compare(const STFaceImage& img); |
| | | FDP_FaceDetectResult compare(const STFaceImage& img1, const STFaceImage& img2); |
| | | |
| | | //#todo need a delete img, if business not linked faceid and its personid |
| | | // they can delete it and save/find again! |
| | |
| | | {
|
| | | int32_t db_id;
|
| | | int32_t st_id; // sensetime id
|
| | | int16_t confidence; // 1000 times of float confidence
|
| | | int16_t confidence; // 1000 times of float confidence, less than zero means error
|
| | |
|
| | | FDP_FaceDetectResult(int32_t _db_id, int32_t _st_id, int _confidence) : db_id(_db_id), st_id(_st_id), confidence(_confidence)
|
| | | {}
|
| | |
| | | //fclose(pFile);
|
| | | //pFile = nullptr;
|
| | |
|
| | | //fdr_vec_t result;
|
| | | //FDP_FaceDetectResult fdrResult = g_STFaceCache.add(stfaceImg);
|
| | | //result.push_back(fdrResult);
|
| | | //
|
| | | //int ret = (fdrResult.db_id == 0 ? -1 : 0);
|
| | | //return send_SensetimeFaceDetectResultJson(client, result, ret);
|
| | | fdr_vec_t result;
|
| | | FDP_FaceDetectResult fdrResult = g_STFaceCache.compare(stfaceImg1, stfaceImg2);
|
| | | result.push_back(fdrResult);
|
| | |
|
| | | return send_SensetimeFaceDetectResultJson(client, result, 0);
|
| | | }
|
| | |
|
| | | bool ev_dispatcher_proto_pb(EVClientStub& client)
|
| | |
| | | // fclose(pFile); |
| | | //} |
| | | } |
| | | else if (image.mb_type == MB_Frame::MBFT_JPEG) |
| | | { |
| | | Mat matTmp = imdecode(_InputArray(image.buff, image.size), CV_LOAD_IMAGE_COLOR); |
| | | |
| | | //imwrite("aaa.jpg", matTmp); |
| | | |
| | | imgbufSize = matTmp.total() * matTmp.elemSize(); |
| | | memcpy(imgbuf, matTmp.ptr(), imgbufSize); |
| | | |
| | | stimgfmt = CV_PIX_FMT_BGR888; |
| | | } |
| | | else |
| | | { |
| | | LOG_WARN << "mb frame type not support" << LOG_ENDL; |
| | |
| | | return p_feature; |
| | | } |
| | | |
| | | float stface_compare(stface_handles& handles, const STFaceImage& image1, const STFaceImage& image2) |
| | | { |
| | | cv_feature_t* f1 = stface_extract_feature(handles, image1); |
| | | if (f1 == nullptr) |
| | | { |
| | | LOGP(INFO, "can't find face in image1"); |
| | | return -1.0; |
| | | } |
| | | |
| | | cv_feature_t* f2 = stface_extract_feature(handles, image2); |
| | | if (f2 == nullptr) |
| | | { |
| | | cv_verify_release_feature(f1); |
| | | LOGP(INFO, "can't find face in image1"); |
| | | return -1.0; |
| | | } |
| | | |
| | | float score = -1.0; |
| | | cv_result_t cv_result = cv_verify_compare_feature(handles.handle_verify, f1, f2, &score); |
| | | if (cv_result != CV_OK) { |
| | | LOGP(DEBUG, "cv_verify_compare_feature failed, error code %d", cv_result); |
| | | score = -1.0; |
| | | } |
| | | |
| | | cv_verify_release_feature(f1); |
| | | cv_verify_release_feature(f2); |
| | | return score; |
| | | } |
| | | |
| | | int stface_db_add(stface_handles& handles, const char *image_path) { |
| | | cv_feature_t *p_feature = stface_extract_feature(handles, image_path); |
| | | if (!p_feature) { |
| | |
| | | struct stface_handles |
| | | { |
| | | cv_handle_t handle_verify; |
| | | cv_handle_t handle_db; |
| | | cv_handle_t handle_detect; |
| | | cv_handle_t handle_db; |
| | | |
| | | stface_handles() : handle_verify(nullptr), handle_db(nullptr), handle_detect(nullptr) |
| | | stface_handles() : handle_verify(nullptr), handle_detect(nullptr), handle_db(nullptr) |
| | | {} |
| | | }; |
| | | |
| | |
| | | cv_feature_t *stface_extract_feature(stface_handles& handles, const char *image_path); |
| | | cv_feature_t *stface_extract_feature(stface_handles& handles, const STFaceImage& image); |
| | | |
| | | float stface_compare(stface_handles& handles, const STFaceImage& image1, const STFaceImage& image2); |
| | | |
| | | int stface_db_add(stface_handles& handles, const char *image_path); |
| | | int stface_db_add(stface_handles& handles, const STFaceImage& image); |
| | | |
| | |
| | | FDP_Image* fdpImage2 = nullptr;
|
| | | {
|
| | | fdpImage2 = new (mesg + evpHeader->size) FDP_Image;
|
| | |
|
| | | |
| | | fdpImage2->db_id = 0; // -1
|
| | | fdpImage2->mb_type = MB_Frame::MBFT_RGB565; // 14
|
| | | fdpImage2->width = 52;
|
| | | fdpImage2->height = 52;
|
| | | fdpImage2->mb_type = MB_Frame::MBFT_JPEG; // 14
|
| | | fdpImage2->width = 198;
|
| | | fdpImage2->height = 154;
|
| | |
|
| | | FILE* pFile = fopen("face-13-w52-h52.rgb565", "rb");
|
| | | FILE* pFile = fopen("compare2.jpg", "rb");
|
| | | fdpImage2->size = fread(fdpImage2->buff, 1, length, pFile);
|
| | | fclose(pFile);
|
| | | pFile = nullptr;
|
| | |
|
| | | |
| | | evpHeader->size += sizeof(FDP_Image) + fdpImage2->size;
|
| | | fdpImage2->hton();
|
| | | }
|
| | | } |
| | | |
| | | //FDP_Image* fdpImage2 = nullptr;
|
| | | //{
|
| | | // fdpImage2 = new (mesg + evpHeader->size) FDP_Image;
|
| | | //
|
| | | // fdpImage2->db_id = 0; // -1
|
| | | // fdpImage2->mb_type = MB_Frame::MBFT_RGB565; // 14
|
| | | // fdpImage2->width = 52;
|
| | | // fdpImage2->height = 52;
|
| | | // |
| | | // FILE* pFile = fopen("face-13-w52-h52.rgb565", "rb");
|
| | | // fdpImage2->size = fread(fdpImage2->buff, 1, length, pFile);
|
| | | // fclose(pFile);
|
| | | // pFile = nullptr;
|
| | | //
|
| | | // evpHeader->size += sizeof(FDP_Image) + fdpImage2->size;
|
| | | // fdpImage2->hton();
|
| | | //}
|
| | |
|
| | | length = evpHeader->size;
|
| | | evpHeader->hton();
|