From 2b27c2c88872084123c77eceb5eea34a21290403 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 15 一月 2020 11:10:42 +0800
Subject: [PATCH] zero copy face

---
 cface.cpp |  137 +++++++++++++++++++++++----------------------
 1 files changed, 69 insertions(+), 68 deletions(-)

diff --git a/cface.cpp b/cface.cpp
index fc20813..99ab41c 100644
--- a/cface.cpp
+++ b/cface.cpp
@@ -1,85 +1,86 @@
 #ifdef __cplusplus
 extern "C"{
 #endif
-
+ 
+#include <stdio.h>
 #include "cface.h"
-
+ 
 #ifdef __cplusplus
 }
 #endif
-
-#include "csrc/all.hpp"
-
-using namespace csdk_wrap;
-
-static VecFunc dtors_;
-
-int c_api_face_detector_init(const int tm, const int gi, const int minFaces, const int rollAngle){
-    return init_face_detector(tm, gi, minFaces, rollAngle, dtors_);
+ 
+#include "csrc/face.h"
+ 
+#include "csrc/struct.h"
+ 
+#include "csrc/face.cpp"
+ 
+using namespace cppface;
+ 
+void *create_sdkface(){
+    return new sdkface();
 }
-
-int c_api_face_property_init(const int tm){
-    return init_face_property(tm, dtors_);
-}
-
-int c_api_face_extractor_init(const int tm, const int gi){
-    return init_face_extractor(tm, gi, dtors_);
-}
-
-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){
-
-   return init_face_tracker(tm, gi, wid, hei, maxFaces, detinterval, sampleSize, dtors_);
-}
-
-int c_api_face_track_resize(const int chan, const int wid, const int hei){
-    return face_track_resize(chan, wid, hei);
-}
-
-void c_api_release(){
-    for(auto &i : dtors_){
-        i();
+ 
+void release(void *handle){
+    if (handle){
+        sdkface *s = (sdkface*)handle;
+        delete s;
     }
-    dtors_.clear();
 }
-
-////////////////////////////////////////////////
-
-cFacePos* c_api_face_detect(int *faceCount, uchar*data, const int w, const int h, const int channel){
-    const cIMAGE img{data, w, h, 3};
-    return face_detect(faceCount, &img, channel);
+ 
+int init_detector(void *handle, const int min_faces, const int roll_angles, 
+                    const int threads_max, const int gpu){
+    sdkface *s = (sdkface*)handle;
+    return s->detector(min_faces, roll_angles, threads_max, gpu);
 }
-
-cThftResult c_api_face_property(const cFacePos* pos, uchar*data, const int w, const int h, const int channel){
-
-    const cIMAGE img{data, w, h, 3};
-    return face_property(*pos, &img, channel);
+ 
+int init_extractor(void *handle, const int threads_max, const int gpu){
+    sdkface *s = (sdkface*)handle;
+    return s->extractor(threads_max, gpu);
 }
-
-uchar* c_api_face_extract(int *featLen, const cFacePos* pos, uchar*data, const int w, const int h, const int channel){
-
-    const cIMAGE img{data, w, h, 3};
-    return face_extract_feature(featLen, *pos, &img, channel);
+ 
+int init_propertizer(void *handle, const int threads_max){
+    sdkface *s = (sdkface*)handle;
+    return s->propertizer(threads_max);
 }
-
-float c_api_face_compare(uchar *feat1, uchar *feat2){
-    return face_compare(feat1, feat2);
+ 
+int init_tracker(void *handle, const int width, const int height,
+            const int max_faces, const int interval, const int sample_size,
+            const int threads_max, const int gpu){
+    sdkface *s = (sdkface*)handle;
+    return s->tracker(width, height, max_faces, interval, sample_size, threads_max, gpu);
 }
-
-cRECT* c_api_face_track_only(int *fCount, uchar *data, const int wid, const int hei, const int channel){
-    const cIMAGE img{data, wid, hei, 3};
-
-    return face_track_only(fCount, &img, channel);
+ 
+int detect(void *handle, const void *data, const int w, const int h, const int c, const int chan, void **fpos, int *fcnt){
+    sdkface *s = (sdkface*)handle;
+    cIMAGE img{(unsigned char*)data, w, h, c};
+    return s->detect(&img, chan, fpos, fcnt);
 }
-
-cFaceInfo* c_api_face_track_detect(int *fCount, uchar *data, const int wid, const int hei, const int channel){
-    const cIMAGE img{data, wid, hei, 3};
-
-    return face_track_detect(fCount, &img, channel);
+ 
+int extract(void *handle, const cFacePos *pos, const void*data, const int w, const int h, const int c, const int chan, void **feat, int *featLen){
+    sdkface *s = (sdkface*)handle;
+    cIMAGE img{(unsigned char*)data, w, h, c};
+    return s->extract(*pos, &img, chan, feat, featLen);
 }
-
-cFaceInfo* c_api_face_track(int *fCount, uchar *data, const int wid, const int hei, const int channel){
-    const cIMAGE img{data, wid, hei, 3};
-    return face_track(fCount, &img, channel);
+ 
+float compare(void *handle, unsigned char *feat1, unsigned char *feat2){
+    sdkface *s = (sdkface*)handle;
+    return s->compare(feat1, feat2);
 }
-
+ 
+int propertize(void *handle, const cFacePos *pos, const void *data, const int w, const int h, const int c, const int chan, void **res){
+    sdkface *s = (sdkface*)handle;
+    cIMAGE img{(unsigned char*)data, w, h, c};
+    return s->propertize(*pos, &img, chan, res);
+}
+ 
+int track(void *handle, const void *data, const int w, const int h, const int c, const int chan, void **fInfo, int *fcnt){
+    sdkface *s = (sdkface*)handle;
+    cIMAGE img{(unsigned char*)data, w, h, c};
+    return s->track(&img, chan, fInfo, fcnt);
+}
+ 
+int track_resize(void *handle, const int w, const int h, const int chan){
+    sdkface *s = (sdkface*)handle;
+    return s->track_resize(w, h, chan);
+}

--
Gitblit v1.8.0