DFACE C++  5.0.0
symbol.h
Go to the documentation of this file.
1 // Hang Zhou Xiao Kong Cheng Xiang Ke Ji You Xian Gong Si is pleased to support DFACE SDK LIBRARY.
2 //
3 // Copyright © 2018, Hang Zhou Xiao Kong Cheng Xiang Ke Ji You Xian Gong Si Holding Limited//
4 
5 #ifndef DFACE_SYMBOL_H
6 #define DFACE_SYMBOL_H
7 
8 #include <stdio.h>
9 #include "dface_detect.h"
10 #include "dface_pose.h"
11 #include "dface_compare.h"
12 #include "dface_recognize.h"
13 #include "dface_nir_liveness.h"
14 #include "dface_rgb_liveness.h"
15 #include "dface_track.h"
16 #include "dface_assessment.h"
17 #include "dface_attribute.h"
18 #include "dface_accredit.h"
19 
20 
21 #ifdef _WIN32
22 #include <Windows.h>
23 #else
24 #include <dlfcn.h>
25 #endif
26 
27 #ifdef _WIN32
28 //dynamic load library
29 static HMODULE handle = LoadLibraryEx(L"libdface.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
30 #else
31 //dynamic load library
32 static void *handle = dlopen("libdfacepro.so", RTLD_LAZY);
33 #endif
34 
35 
41 inline dface::DfaceDetect* load_dface_detect(const std::string &model_path, int precision){
42 #ifdef _WIN32
43  if (handle == NULL)
44  {
45  printf("library failed to load.\n");
46  return nullptr;
47  }
48  dface::CreateDetect* createDetect = (dface::CreateDetect*)GetProcAddress(handle, "create_detect");
49 #else
50  if (!handle)
51  {
52  printf("library failed to load.\n");
53  return nullptr;
54  }
55  dface::CreateDetect* createDetect = (dface::CreateDetect*)dlsym(handle, "create_detect");
56  const char* dlsym_error = dlerror();
57  if (dlsym_error) {
58  printf("%s", dlsym_error);
59  return nullptr;
60  }
61 #endif
62  return createDetect(model_path, precision);
63 }
64 
70  if(p == nullptr){
71  return;
72  }
73 #ifdef _WIN32
74  dface::DestroyDetect* destroyDetect = (dface::DestroyDetect*)GetProcAddress(handle, "destroy_detect");
75 #else
76  dface::DestroyDetect* destroyDetect = (dface::DestroyDetect*)dlsym(handle, "destroy_detect");
77  const char* dlsym_error = dlerror();
78  if (dlsym_error) {
79  printf("%s", dlsym_error);
80  return;
81  }
82 #endif
83  destroyDetect(p);
84 }
85 
86 
91 inline dface::DfaceAssessment* load_dface_assessment(const std::string &model_path){
92 #ifdef _WIN32
93  if (handle == NULL)
94  {
95  printf("library failed to load.\n");
96  return nullptr;
97  }
98  dface::CreateAssessment* createAssessment = (dface::CreateAssessment*)GetProcAddress(handle, "create_assessment");
99 #else
100  if (!handle)
101  {
102  printf("library failed to load.\n");
103  return nullptr;
104  }
105  dface::CreateAssessment* createAssessment = (dface::CreateAssessment*)dlsym(handle, "create_assessment");
106  const char* dlsym_error = dlerror();
107  if (dlsym_error) {
108  printf("%s", dlsym_error);
109  return nullptr;
110  }
111 #endif
112  return createAssessment(model_path);
113 }
114 
120  if(p == nullptr){
121  return;
122  }
123 #ifdef _WIN32
124  dface::DestroyAssessment* destroyAssessment = (dface::DestroyAssessment*)GetProcAddress(handle, "destroy_assessment");
125 #else
126  dface::DestroyAssessment* destroyAssessment = (dface::DestroyAssessment*)dlsym(handle, "destroy_assessment");
127  const char* dlsym_error = dlerror();
128  if (dlsym_error) {
129  printf("%s", dlsym_error);
130  return;
131  }
132 #endif
133  destroyAssessment(p);
134 }
135 
136 
137 
142 inline dface::DfaceAttribute* load_dface_attribute(const std::string &model_path){
143 #ifdef _WIN32
144  if (handle == NULL)
145  {
146  printf("library failed to load.\n");
147  return nullptr;
148  }
149  dface::CreateAttribute* createAttribute = (dface::CreateAttribute*)GetProcAddress(handle, "create_attribute");
150 #else
151  if (!handle)
152  {
153  printf("library failed to load.\n");
154  return nullptr;
155  }
156  dface::CreateAttribute* createAttribute = (dface::CreateAttribute*)dlsym(handle, "create_attribute");
157  const char* dlsym_error = dlerror();
158  if (dlsym_error) {
159  printf("%s", dlsym_error);
160  return nullptr;
161  }
162 #endif
163  return createAttribute(model_path);
164 }
165 
171  if(p == nullptr){
172  return;
173  }
174 #ifdef _WIN32
175  dface::DestroyAttribute* destroyAttribute = (dface::DestroyAttribute*)GetProcAddress(handle, "destroy_attribute");
176 #else
177  dface::DestroyAttribute* destroyAttribute = (dface::DestroyAttribute*)dlsym(handle, "destroy_attribute");
178  const char* dlsym_error = dlerror();
179  if (dlsym_error) {
180  printf("%s", dlsym_error);
181  return;
182  }
183 #endif
184  destroyAttribute(p);
185 }
186 
187 
188 
194 inline dface::DfaceRecognize* load_dface_recognize(const std::string &model_path, int precision) {
195 #ifdef _WIN32
196  DWORD dwError = 0;
197  if (handle == NULL)
198  {
199  printf("library failed to load.\n");
200  return nullptr;
201  }
202  dface::CreateRecognize* createRecognize = (dface::CreateRecognize*)GetProcAddress(handle, "create_recognize");
203 #else
204  if (!handle)
205  {
206  printf("library failed to load.\n");
207  return nullptr;
208  }
209 
210  dface::CreateRecognize* createRecognize = (dface::CreateRecognize*)dlsym(handle, "create_recognize");
211  const char* dlsym_error = dlerror();
212  if (dlsym_error) {
213  printf("%s", dlsym_error);
214  return nullptr;
215  }
216 #endif
217  return createRecognize(model_path, precision);
218 }
219 
220 
225  if(p == nullptr){
226  return;
227  }
228 #ifdef _WIN32
229  dface::DestroyRecognize* destroyRecognize = (dface::DestroyRecognize*)GetProcAddress(handle, "destroy_recognize");
230 #else
231  dface::DestroyRecognize* destroyRecognize = (dface::DestroyRecognize*)dlsym(handle, "destroy_recognize");
232  char* dlsym_error = dlerror();
233  if (dlsym_error) {
234  printf("%s", dlsym_error);
235  return;
236  }
237 #endif
238  destroyRecognize(p);
239 }
240 
241 
245 inline dface::DfaceCompare* load_dface_compare(const std::string &model_path, int feature_precision)
246 {
247 #ifdef _WIN32
248  DWORD dwError = 0;
249  if (handle == NULL)
250  {
251  printf("library failed to load.\n");
252  return nullptr;
253  }
254  dface::CreateCompare* createCompare = (dface::CreateCompare*)GetProcAddress(handle, "create_compare");
255 #else
256  if (!handle)
257  {
258  printf("library failed to load.\n");
259  return nullptr;
260  }
261  dface::CreateCompare* createCompare = (dface::CreateCompare *)dlsym(handle, "create_compare");
262  const char* dlsym_error = dlerror();
263  if (dlsym_error) {
264  printf("%s", dlsym_error);
265  return nullptr;
266  }
267 #endif
268  return createCompare(model_path, feature_precision);
269 }
270 
271 
276  if(p == nullptr){
277  return;
278  }
279 #ifdef _WIN32
280  dface::DestroyCompare *destroyCompare = (dface::DestroyCompare *)GetProcAddress(handle, "destroy_compare");
281 #else
282  dface::DestroyCompare *destroyCompare = (dface::DestroyCompare*)dlsym(handle, "destroy_compare");
283  const char* dlsym_error = dlerror();
284  if (dlsym_error) {
285  printf("%s", dlsym_error);
286  return;
287  }
288 #endif
289  destroyCompare(p);
290 }
291 
292 
297 inline dface::DfacePose* load_dface_pose(const std::string &model_path)
298 {
299 #ifdef _WIN32
300  DWORD dwError = 0;
301  if (handle == NULL)
302  {
303  printf("library failed to load.\n");
304  return nullptr;
305  }
306  dface::CreatePose* createPose = (dface::CreatePose*)GetProcAddress(handle, "create_pose");
307 #else
308  if (!handle)
309  {
310  printf("library failed to load.\n");
311  return nullptr;
312  }
313  dface::CreatePose * createPose = (dface::CreatePose*)dlsym(handle, "create_pose");
314  const char* dlsym_error = dlerror();
315  if (dlsym_error) {
316  printf("%s", dlsym_error);
317  return nullptr;
318  }
319 #endif
320  return createPose(model_path);
321 }
322 
323 
328  if(p == nullptr){
329  return;
330  }
331 #ifdef _WIN32
332  dface::DestroyPose *destroyPose = (dface::DestroyPose*)GetProcAddress(handle, "destroy_pose");
333 #else
334  dface::DestroyPose *destroyPose = (dface::DestroyPose*)dlsym(handle, "destroy_pose");
335  const char* dlsym_error = dlerror();
336  if (dlsym_error) {
337  printf("%s", dlsym_error);
338  return;
339  }
340 #endif
341  destroyPose(p);
342 }
343 
344 
349 inline dface::DfaceNIRLiveness* load_dface_nir_liveness(const std::string &model_path)
350 {
351 #ifdef _WIN32
352  DWORD dwError = 0;
353  if (handle == NULL)
354  {
355  printf("library failed to load.\n");
356  return nullptr;
357  }
358  dface::CreateNIRLiveness* createNirLiveness = (dface::CreateNIRLiveness*)GetProcAddress(handle, "create_nir_liveness");
359 #else
360  if (!handle)
361  {
362  printf("library failed to load.\n");
363  return nullptr;
364  }
365  dface::CreateNIRLiveness * createNirLiveness = (dface::CreateNIRLiveness*)dlsym(handle, "create_nir_liveness");
366  const char* dlsym_error = dlerror();
367  if (dlsym_error) {
368  printf("%s", dlsym_error);
369  return nullptr;
370  }
371 #endif
372  return createNirLiveness(model_path);
373 }
374 
375 
380  if(p == nullptr){
381  return;
382  }
383 #ifdef _WIN32
384  dface::DestroyNIRLiveness *destoryNirLiveness = (dface::DestroyNIRLiveness*)GetProcAddress(handle, "destroy_nir_liveness");
385 #else
386  dface::DestroyNIRLiveness *destoryNirLiveness = (dface::DestroyNIRLiveness*)dlsym(handle, "destroy_nir_liveness");
387  const char* dlsym_error = dlerror();
388  if (dlsym_error) {
389  printf("%s", dlsym_error);
390  return;
391  }
392 #endif
393  destoryNirLiveness(p);
394 }
395 
396 
397 
403 inline dface::DfaceRGBLiveness* load_dface_rgb_liveness(const std::string &model_path, int level)
404 {
405 #ifdef _WIN32
406  DWORD dwError = 0;
407  if (handle == NULL)
408  {
409  printf("library failed to load.\n");
410  return nullptr;
411  }
412  dface::CreateRGBLiveness* createRgbLiveness = (dface::CreateRGBLiveness*)GetProcAddress(handle, "create_rgb_liveness");
413 #else
414  if (!handle)
415  {
416  printf("library failed to load.\n");
417  return nullptr;
418  }
419  dface::CreateRGBLiveness * createRgbLiveness = (dface::CreateRGBLiveness*)dlsym(handle, "create_rgb_liveness");
420  const char* dlsym_error = dlerror();
421  if (dlsym_error) {
422  printf("%s", dlsym_error);
423  return nullptr;
424  }
425 #endif
426  return createRgbLiveness(model_path, level);
427 }
428 
429 
434  if(p == nullptr){
435  return;
436  }
437 #ifdef _WIN32
438  dface::DestroyRGBLiveness *destroyRgbLiveness = (dface::DestroyRGBLiveness*)GetProcAddress(handle, "destroy_rgb_liveness");
439 #else
440  dface::DestroyRGBLiveness *destroyRgbLiveness = (dface::DestroyRGBLiveness *)dlsym(handle, "destroy_rgb_liveness");
441  const char* dlsym_error = dlerror();
442  if (dlsym_error) {
443  printf("%s", dlsym_error);
444  return;
445  }
446 #endif
447  destroyRgbLiveness(p);
448 }
449 
450 
451 
461 inline dface::DfaceTrack* load_dface_track(const std::string &model_path, int frame_width, int frame_height, int max_age = 200, int min_hit = 3)
462 {
463 #ifdef _WIN32
464  DWORD dwError = 0;
465  if (handle == NULL)
466  {
467  printf("library failed to load.\n");
468  return nullptr;
469  }
470  dface::CreateTrack* createTrack = (dface::CreateTrack*)GetProcAddress(handle, "create_track");
471 #else
472  if (!handle)
473  {
474  printf("library failed to load.\n");
475  return nullptr;
476  }
477  dface::CreateTrack * createTrack = (dface::CreateTrack *)dlsym(handle, "create_track");
478  const char* dlsym_error = dlerror();
479  if (dlsym_error) {
480  printf("%s", dlsym_error);
481  return nullptr;
482  }
483 #endif
484  return createTrack(model_path, frame_width, frame_height, max_age, min_hit);
485 }
486 
487 
492  if(p == nullptr){
493  return;
494  }
495 #ifdef _WIN32
496  dface::DestroyTrack *destroyTrack = (dface::DestroyTrack*)GetProcAddress(handle, "destroy_track");
497 #else
498  dface::DestroyTrack *destroyTrack = (dface::DestroyTrack *)dlsym(handle, "destroy_track");
499  const char* dlsym_error = dlerror();
500  if (dlsym_error) {
501  printf("%s", dlsym_error);
502  return;
503  }
504 #endif
505  destroyTrack(p);
506 }
507 
508 
514 {
515 #ifdef _WIN32
516  DWORD dwError = 0;
517  if (handle == NULL)
518  {
519  printf("library failed to load.\n");
520  return nullptr;
521  }
522  CreateAccredit* createAccredit = (CreateAccredit*)GetProcAddress(handle, "create_accredit");
523 #else
524  if (!handle)
525  {
526  printf("library failed to load.\n");
527  return nullptr;
528  }
529  CreateAccredit * createAccredit = (CreateAccredit *)dlsym(handle, "create_accredit");
530  const char* dlsym_error = dlerror();
531  if (dlsym_error) {
532  printf("%s", dlsym_error);
533  return nullptr;
534  }
535 #endif
536  return createAccredit();
537 }
538 
539 
544  if(p == nullptr){
545  return;
546  }
547 #ifdef _WIN32
548  DestroyAccredit *destroyAccredit = (DestroyAccredit*)GetProcAddress(handle, "destroy_accredit");
549 #else
550  DestroyAccredit *destroyAccredit = (DestroyAccredit *)dlsym(handle, "destroy_accredit");
551  const char* dlsym_error = dlerror();
552  if (dlsym_error) {
553  printf("%s", dlsym_error);
554  return;
555  }
556 #endif
557  destroyAccredit(p);
558 }
559 
560 
564 inline void free_dface(){
565 #ifdef _WIN32
566  if(handle != NULL){
567  FreeLibrary(handle);
568  }
569 #else
570  if(handle){
571  dlclose(handle);
572  }
573 #endif
574 }
575 
576 #endif //DFACE_SYMBOL_H
DfaceTrack * CreateTrack(const std::string &model_path, int frame_width, int frame_height, int max_age, int min_hit)
Definition: dface_track.h:68
DfaceNIRLiveness * CreateNIRLiveness(const std::string &model_path)
Definition: dface_nir_liveness.h:57
void destory_dface_nir_liveness(dface::DfaceNIRLiveness *p)
Definition: symbol.h:379
DfaceAccredit * CreateAccredit()
Definition: dface_accredit.h:136
void destory_dface_assessment(dface::DfaceAssessment *p)
Definition: symbol.h:119
DfaceAssessment * CreateAssessment(const std::string &model_path)
Definition: dface_assessment.h:50
void DestroyCompare(DfaceCompare *dc)
Definition: dface_compare.h:59
void DestroyRGBLiveness(DfaceRGBLiveness *instance)
Definition: dface_rgb_liveness.h:57
void DestroyNIRLiveness(DfaceNIRLiveness *dc)
Definition: dface_nir_liveness.h:63
FaceRecognize API.
Definition: dface_recognize.h:17
DfaceAttribute * CreateAttribute(const std::string &model_path)
Definition: dface_attribute.h:62
DfaceCompare * CreateCompare(const std::string &model_path, int feature_precision)
Definition: dface_compare.h:53
FaceRGBLiveness API.
Definition: dface_rgb_liveness.h:19
void DestroyDetect(DfaceDetect *dc)
Definition: dface_detect.h:77
dface::DfaceTrack * load_dface_track(const std::string &model_path, int frame_width, int frame_height, int max_age=200, int min_hit=3)
Definition: symbol.h:461
DfaceAccredit * load_dface_accredit()
Definition: symbol.h:513
void DestroyTrack(DfaceTrack *rc)
Definition: dface_track.h:74
void destory_dface_attribute(dface::DfaceAttribute *p)
Definition: symbol.h:170
void destory_dface_pose(dface::DfacePose *p)
Definition: symbol.h:327
FaceNIRLiveness API.
Definition: dface_nir_liveness.h:17
DfacePose * CreatePose(const std::string &model_path)
Definition: dface_pose.h:65
void destory_dface_rgb_liveness(dface::DfaceRGBLiveness *p)
Definition: symbol.h:433
dface::DfaceRGBLiveness * load_dface_rgb_liveness(const std::string &model_path, int level)
Definition: symbol.h:403
DfaceRGBLiveness * CreateRGBLiveness(const std::string &model_path, int level)
Definition: dface_rgb_liveness.h:51
License API.
Definition: dface_accredit.h:14
void destory_dface_accredit(DfaceAccredit *p)
Definition: symbol.h:543
dface::DfacePose * load_dface_pose(const std::string &model_path)
Definition: symbol.h:297
FaceTrack API.
Definition: dface_track.h:17
FaceAttribute API.
Definition: dface_attribute.h:18
dface::DfaceAttribute * load_dface_attribute(const std::string &model_path)
Definition: symbol.h:142
void destory_dface_track(dface::DfaceTrack *p)
Definition: symbol.h:491
void destory_dface_detect(dface::DfaceDetect *p)
Definition: symbol.h:69
void DestroyAssessment(DfaceAssessment *dc)
Definition: dface_assessment.h:56
dface::DfaceCompare * load_dface_compare(const std::string &model_path, int feature_precision)
Definition: symbol.h:245
dface::DfaceNIRLiveness * load_dface_nir_liveness(const std::string &model_path)
Definition: symbol.h:349
void DestroyRecognize(DfaceRecognize *rc)
Definition: dface_recognize.h:54
void DestroyAccredit(DfaceAccredit *dc)
Definition: dface_accredit.h:142
void DestroyAttribute(DfaceAttribute *dc)
Definition: dface_attribute.h:68
void DestroyPose(DfacePose *dc)
Definition: dface_pose.h:71
dface::DfaceDetect * load_dface_detect(const std::string &model_path, int precision)
Definition: symbol.h:41
dface::DfaceRecognize * load_dface_recognize(const std::string &model_path, int precision)
Definition: symbol.h:194
DfaceRecognize * CreateRecognize(const std::string &model_path, int precision)
Definition: dface_recognize.h:48
FaceAssessment API.
Definition: dface_assessment.h:18
dface::DfaceAssessment * load_dface_assessment(const std::string &model_path)
Definition: symbol.h:91
void destory_dface_compare(dface::DfaceCompare *p)
Definition: symbol.h:275
void destory_dface_recognize(dface::DfaceRecognize *p)
Definition: symbol.h:224
DfaceDetect * CreateDetect(const std::string &model_path, int precision)
Definition: dface_detect.h:71
FacePose API.
Definition: dface_pose.h:18
void free_dface()
Definition: symbol.h:564
FaceDetect API.
Definition: dface_detect.h:17
FaceCompare API.
Definition: dface_compare.h:16