Video Analysis底层库拆分,sdk的go封装
chenshijun
2019-10-22 b7340a34ff68f018a4aa0e7aada3b7feaabd2fe1
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifdef __cplusplus
extern "C"{
#endif
 
#include "csdk.h"
 
#ifdef __cplusplus
}
#endif
 
#include "csrc/all.hpp"
 
using namespace csdk_wrap;
 
static sdkface *face = NULL;
static sdkyolo *yolo = NULL;
 
int c_api_face_detector_init(const int tm, const int gi, const int minFaces, const int rollAngle){
    if (!face) face = new sdkface();
    return face->init_face_detector(tm, gi, minFaces, rollAngle);
}
 
int c_api_face_property_init(const int tm){
    if (!face) face = new sdkface();
    return face->init_face_property(tm);
}
 
int c_api_face_extractor_init(const int tm, const int gi){
    if (!face) face = new sdkface();
    return face->init_face_extractor(tm, gi);
}
 
int c_api_face_tracker_init(const int tm, const int gi, const int wid, const int hei,
                            const int maxFaces, const int detinterval, const int sampleSize){
    if (!face) face = new sdkface();
    if (face) printf("create sdk face success\n");
    return face->init_face_tracker(tm, gi, wid, hei, maxFaces, detinterval, sampleSize);
}
 
int c_api_face_track_resize(const int chan, const int wid, const int hei){
    return face->face_track_resize(chan, wid, hei);
}
 
YoloHandle c_api_yolo_init(
    const char *fcfg, const char *fweights, const char *fname,
    const int gpu_index){
    
    if (!yolo) yolo = new sdkyolo;
    return yolo->init_yolo(fcfg, fweights, fname, gpu_index);    
}
 
void c_api_release(){
    if (face) delete face;
    if (yolo) delete yolo;
}
 
////////////////////////////////////////////////
 
cFacePos* c_api_face_detect(int *faceCount, uchar*data, const int w, const int h, const int channel){
    if (!face) return NULL;
    
    const cIMAGE img{data, w, h, 3};
    cFacePos *fpos = NULL;
 
    int ret = face->face_detect(&img, channel, (void**)&fpos, faceCount);
 
    if (ret <= 0) return NULL;
    return fpos;
}
 
cThftResult c_api_face_property(const cFacePos* pos, uchar*data, const int w, const int h, const int channel){
    if (!face) return cThftResult{-1,-1,-1,-1,-1};
 
    const cIMAGE img{data, w, h, 3};
    return face->face_property(*pos, &img, channel);
}
 
uchar* c_api_face_extract(int *featLen, const cFacePos* pos, uchar*data, const int w, const int h, const int channel){
    if (!face) return NULL;
 
    const cIMAGE img{data, w, h, 3};
    uchar *feat = NULL;
    int ret = face->face_extract_feature(*pos, &img, channel, (void**)&feat, featLen);
    if (ret <= 0) return NULL;
    return feat;
}
 
float c_api_face_compare(uchar *feat1, uchar *feat2){
    if (!face) return NULL;
    return face->face_compare(feat1, feat2);
}
 
cFaceInfo* c_api_face_track(int *fCount, uchar *data, const int wid, const int hei, const int channel){
    if (!face) return NULL;
    const cIMAGE img{data, wid, hei, 3};
 
    cFaceInfo *info = NULL;
    int ret = face->face_track(&img, channel, (void**)&info, fCount);
    if (ret <= 0) return NULL;
    return info;
}
 
 
/// yolo api
cObjInfo* c_api_yolo_detect(YoloHandle handle, int *objCount, uchar*data, const int w, const int h, const float thrsh, const int use_means){
    if (!yolo) return NULL;
 
    const cIMAGE img{data, w, h, 3};
    cObjInfo *info = NULL;
    int ret = yolo->yolo_detect(handle, &img, thrsh, use_means, (void**)&info, objCount);
    if (ret <= 0) return NULL;
    return info;
}
 
const char* c_api_yolo_obj_name(const int typ){
    if (!yolo) return NULL;
 
    return yolo->yolo_obj_name_by_type(typ);
}