Video Analysis底层库拆分,sdk的go封装
zhangmeng
2019-10-21 0c7eb3a82f4ae7366b82ae58181d7ccc274d4e3b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "extractor.h"
 
#include "THFeature_i.h"
#include "csdk_struct.h"
 
namespace csdk_wrap{
 
    int init_face_extractor(const int tm, const int gi, VecFunc &vec){
        int ret = 0;
        if (gi < 0) {
            ret = EF_Init(tm);
        } else {
            EF_Param *param = new EF_Param[tm];
            for (int i = 0; i < tm; i++) {
                param[i].nDeviceID = gi;
            }
            ret = EF_Init_Ex(tm, param);
            delete[] param;
        }
        if(ret != tm){
            printf("create face extractor failed!\n");;
        }else{
            vec.emplace_back([]{EF_Release();});
        }
        return ret;
    }
 
    unsigned char* face_extract_feature(int *featLen, const cFacePos &pos, const cIMAGE *img, const int chan){
        if(!img){
            printf("face extract error, image or pos null\n");
            return NULL;
        }
        *featLen = EF_Size();
        unsigned char *feat = (unsigned char*)malloc(*featLen);
        auto ret = EF_Extract(chan, (BYTE*)(img->data), img->width, img->height, 3, (THFI_FacePos*)(&pos), feat);
        
        if(ret != 1){
            printf("face extract error %d\n", ret);
            free(feat);
            *featLen = 0;
            return NULL;
        }
        return feat;
    }
 
    float face_compare(unsigned char *feat1, unsigned char *feat2){
        if (!feat1 || !feat2){
            return 0.0f;
        }
 
        return EF_Compare(feat1, feat2);
    }
 
}