houxiao
2017-06-28 004e5b3424f02b2b413a52d7162594c4cc5c5547
add compare bin proto

git-svn-id: http://192.168.1.226/svn/proxy@668 454eff88-639b-444f-9e54-f578c98de674
1个文件已添加
7个文件已修改
114 ■■■■ 已修改文件
FaceServer/STFaceCache.cpp 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/STFaceCache.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/compare2.jpg 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/face_daemon_proto.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/main_face_daemon.cpp 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/sample_face_search.cpp 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/sample_face_search.h 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/test_client_compare.cpp 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/STFaceCache.cpp
@@ -23,6 +23,16 @@
    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
@@ -320,3 +330,14 @@
    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;
}
FaceServer/STFaceCache.h
@@ -20,7 +20,7 @@
    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!
FaceServer/compare2.jpg
FaceServer/face_daemon_proto.h
@@ -53,7 +53,7 @@
{
    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)
    {}
FaceServer/main_face_daemon.cpp
@@ -183,12 +183,11 @@
    //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)
FaceServer/sample_face_search.cpp
@@ -133,6 +133,17 @@
        //    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;
@@ -178,6 +189,35 @@
    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) {
FaceServer/sample_face_search.h
@@ -10,10 +10,10 @@
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)
    {}
};
@@ -41,6 +41,8 @@
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);
FaceServer/test_client_compare.cpp
@@ -67,20 +67,38 @@
    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();