DFace SDK  1.8.5
symbol.h
1 //
2 // Created by asy on 10/20/18.
3 //
4 
5 #ifndef DFACE_SYMBOL_H
6 #define DFACE_SYMBOL_H
7 
8 #include "dface/dface_detect.h"
9 #include "dface/dface_pose.h"
10 #include "dface/dface_compare.h"
11 #include "dface/dface_recognize.h"
12 #include "dface/dface_infrared.h"
13 #ifdef _WIN32
14 #include <Windows.h>
15 #else
16 #include <dlfcn.h>
17 #endif
18 
19 
20 #ifdef _WIN32
21 //加载动态库
22 static HMODULE handle = LoadLibraryEx("libdface.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
23 #else
24 //加载动态库
25 static void *handle = dlopen("libdfacepro.so", RTLD_LAZY);
26 #endif
27 
28 
33 inline dface::DfaceDetect* load_dface_detect(std::string model_path){
34 #ifdef _WIN32
35  if (handle == NULL)
36  {
37  throw "libdfacepro.dll library failed to load";
38  }
39  //获得人脸检测工厂函数
40  dface::CreateDetect* createDetect = (dface::CreateDetect*)GetProcAddress(handle, "create_detect");
41  if (createDetect == NULL) {
42  throw "DfaceDetect failed to create";
43  }
44 #else
45  if (!handle)
46  {
47  throw "libdfacepro.so library failed to load";
48  }
49  //获得人脸检测工厂函数
50  dface::CreateDetect* createDetect = (dface::CreateDetect*)dlsym(handle, "create_detect");
51  const char* dlsym_error = dlerror();
52  if (dlsym_error) {
53  throw "DfaceDetect failed to create";
54  }
55 #endif
56  return createDetect(model_path);
57 }
58 
63 inline void destory_dface_detect(dface::DfaceDetect* p){
64 #ifdef _WIN32
65  //获得人脸检测通道工厂销毁函数
66  dface::DestroyDetect* destroyDetect = (dface::DestroyDetect*)GetProcAddress(handle, "destroy_detect");
67  if (destroyDetect == NULL) {
68  throw "DfaceDetect failed to destory";
69  }
70 #else
71  //获得人脸检测通道工厂销毁函数
72  dface::DestroyDetect* destroyDetect = (dface::DestroyDetect*)dlsym(handle, "destroy_detect");
73  const char* dlsym_error = dlerror();
74  if (dlsym_error) {
75  throw "DfaceDetect failed to destory";
76  }
77 #endif
78  //销毁检测通道
79  destroyDetect(p);
80 }
81 
82 
89 inline dface::DfaceRecognize* load_dface_recognize(std::string model_path, int accuracy) {
90 #ifdef _WIN32
91  DWORD dwError = 0;
92  if (handle == NULL)
93  {
94  throw "libdfacepro.dll library failed to load";
95  }
96 
97  //获得人脸识别通道工厂函数
98  dface::CreateRecognize* createRecognize = (dface::CreateRecognize*)GetProcAddress(handle, "create_recognize");
99  if (createRecognize == NULL) {
100  throw "DfaceRecognize failed to create";
101  }
102 #else
103  if (!handle)
104  {
105  throw "libdfacepro.so library failed to load";
106  }
107 
108  //获得人脸识别通道工厂函数
109  dface::CreateRecognize* createRecognize = (dface::CreateRecognize*)dlsym(handle, "create_recognize");
110  const char* dlsym_error = dlerror();
111  if (dlsym_error) {
112  throw "DfaceRecognize failed to create";
113  }
114 
115 #endif
116  return createRecognize(model_path, accuracy);
117 }
118 
119 
124 inline void destory_dface_recognize(dface::DfaceRecognize* p){
125 #ifdef _WIN32
126  //获得人脸识别通道工厂销毁函数
127  dface::DestroyRecognize* destroyRecognize = (dface::DestroyRecognize*)GetProcAddress(handle, "destroy_recognize");
128  if (destroyRecognize == NULL) {
129  throw "DfaceRecognize failed to destory";
130  }
131 #else
132  //获得人脸检测通道工厂销毁函数
133  dface::DestroyRecognize* destroyRecognize = (dface::DestroyRecognize*)dlsym(handle, "destroy_recognize");
134  char* dlsym_error = dlerror();
135  if (dlsym_error) {
136  throw "DfaceRecognize failed to destory";
137  }
138 #endif
139  destroyRecognize(p);
140 }
141 
142 
148 inline dface::DfaceCompare* load_dface_compare(std::string model_path, int accuracy)
149 {
150 #ifdef _WIN32
151  DWORD dwError = 0;
152  //加载动态库
153  if (handle == NULL)
154  {
155  throw "libdfacepro.dll library failed to load";
156  }
157  //获得人脸比对通道工厂函数
158  dface::CreateCompare* createCompare = (dface::CreateCompare*)GetProcAddress(handle, "create_compare");
159  if (createCompare == NULL) {
160  throw "DfaceCompare failed to create";
161  }
162 #else
163  if (!handle)
164  {
165  throw "libdfacepro.so library failed to load";
166  }
167  //获得人脸比对通道工厂函数
168  dface::CreateCompare* createCompare = (dface::CreateCompare *)dlsym(handle, "create_compare");
169  const char* dlsym_error = dlerror();
170  if (dlsym_error) {
171  throw "DfaceCompare failed to create";
172  }
173 #endif
174  return createCompare(model_path, accuracy);
175 }
176 
177 
182 inline void destory_dface_compare(dface::DfaceCompare* p){
183 #ifdef _WIN32
184  //获得人脸比对通道工厂销毁函数
185  dface::DestroyCompare *destroyCompare = (dface::DestroyCompare *)GetProcAddress(handle, "destroy_compare");
186  if (destroyCompare == NULL) {
187  throw "DfaceCompare failed to destory";
188  }
189 #else
190  //获得人脸比对通道工厂销毁函数
191  dface::DestroyCompare *destroyCompare = (dface::DestroyCompare*)dlsym(handle, "destroy_compare");
192  const char* dlsym_error = dlerror();
193  if (dlsym_error) {
194  throw "DfaceCompare failed to destory";
195  }
196 #endif
197  //销毁人脸比对通道
198  destroyCompare(p);
199 }
200 
201 
206 inline dface::DfacePose* load_dface_pose(std::string model_path)
207 {
208 #ifdef _WIN32
209  DWORD dwError = 0;
210  //加载动态库
211  if (handle == NULL)
212  {
213  throw "libdfacepro.dll library failed to load";
214  }
215  //获得人脸姿态通道工厂函数
216  dface::CreatePose* createPose = (dface::CreatePose*)GetProcAddress(handle, "create_pose");
217  if (createPose == NULL) {
218  throw "DfacePose failed to create";
219  }
220 #else
221  if (!handle)
222  {
223  throw "libdfacepro.so library failed to load";
224  }
225  //获得人脸姿态通道工厂函数
226  dface::CreatePose * createPose = (dface::CreatePose*)dlsym(handle, "create_pose");
227  const char* dlsym_error = dlerror();
228  if (dlsym_error) {
229  throw "DfacePose failed to create";
230  }
231 #endif
232  return createPose(model_path);
233 }
234 
235 
240 inline void destory_dface_pose(dface::DfacePose* p){
241 #ifdef _WIN32
242  //获得人脸比对通道工厂销毁函数
243  dface::DestroyPose *destroyPose = (dface::DestroyPose*)GetProcAddress(handle, "destroy_pose");
244  if (destroyPose == NULL) {
245  throw "DfacePose failed to destory";
246  }
247 #else
248  //获得人脸比对通道工厂销毁函数
249  dface::DestroyPose *destroyPose = (dface::DestroyPose*)dlsym(handle, "destroy_pose");
250  const char* dlsym_error = dlerror();
251  if (dlsym_error) {
252  throw "DfacePose failed to destory";
253  }
254 #endif
255  //销毁人脸比对通道
256  destroyPose(p);
257 }
258 
259 
264 inline dface::DfaceInfrared* load_dface_infrared(std::string model_path)
265 {
266 #ifdef _WIN32
267  DWORD dwError = 0;
268  //加载动态库
269  if (handle == NULL)
270  {
271  throw "libdfacepro.dll library failed to load";
272  }
273  //获得红外活体检测通道工厂函数
274  dface::CreateInfrared* createInfrared = (dface::CreateInfrared*)GetProcAddress(handle, "create_infrared");
275  if (createInfrared == NULL) {
276  throw "DfaceInfrared failed to create";
277  }
278 #else
279  if (!handle)
280  {
281  throw "libdfacepro.so library failed to load";
282  }
283  //获得红外活体检测通道工厂函数
284  dface::CreateInfrared * createInfrared = (dface::CreateInfrared*)dlsym(handle, "create_infrared");
285  const char* dlsym_error = dlerror();
286  if (dlsym_error) {
287  throw "DfaceInfrared failed to create";
288  }
289 #endif
290  return createInfrared(model_path);
291 }
292 
293 
298 inline void destory_dface_infrared(dface::DfaceInfrared* p){
299 #ifdef _WIN32
300  //获得人脸比对通道工厂销毁函数
301  dface::DestroyInfrared *destroyInfrared = (dface::DestroyInfrared*)GetProcAddress(handle, "destroy_infrared");
302  if (destroyInfrared == NULL) {
303  throw "DfaceInfrared failed to destory";
304  }
305 #else
306  //获得红外活体检测通道工厂销毁函数
307  dface::DestroyInfrared *destroyInfrared = (dface::DestroyInfrared*)dlsym(handle, "destroy_infrared");
308  const char* dlsym_error = dlerror();
309  if (dlsym_error) {
310  throw "DfaceInfrared failed to destory";
311  }
312 #endif
313  //销毁红外活体检测通道
314  destroyInfrared(p);
315 }
316 
317 
318 #endif //DFACE_SYMBOL_H
DFace人脸识别(特征提取)API抽象层(DFaceRecognize)
Definition: dface_recognize.h:41
DFace人脸姿态API抽象层(DFacePose)
Definition: dface_pose.h:40
DFace红外线活体检测API抽象层(DfaceInfrared)
Definition: dface_infrared.h:39
DFace人脸检测API抽象层(DFaceDetect)
Definition: dface_detect.h:39
DFace人脸比对API抽象层(DFaceCompare)
Definition: dface_compare.h:40