From 2b13fa2f78172594a2675847941c03df84f01cde Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期一, 21 十月 2019 09:30:28 +0800 Subject: [PATCH] lower memory and cpu --- csdk.cpp | 78 +++++++++++++++++++++++--------------- 1 files changed, 47 insertions(+), 31 deletions(-) diff --git a/csdk.cpp b/csdk.cpp index 1810569..bda8823 100644 --- a/csdk.cpp +++ b/csdk.cpp @@ -12,88 +12,104 @@ using namespace csdk_wrap; -static VecFunc dtors_; +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){ - return init_face_detector(tm, gi, minFaces, rollAngle, dtors_); + if (!face) face = new sdkface(); + return face->init_face_detector(tm, gi, minFaces, rollAngle); } int c_api_face_property_init(const int tm){ - return init_face_property(tm, dtors_); + if (!face) face = new sdkface(); + return face->init_face_property(tm); } int c_api_face_extractor_init(const int tm, const int gi){ - return init_face_extractor(tm, gi, dtors_); + 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){ - - return init_face_tracker(tm, gi, wid, hei, maxFaces, detinterval, sampleSize, dtors_); + 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); } YoloHandle c_api_yolo_init( const char *fcfg, const char *fweights, const char *fname, const int gpu_index){ - - return init_yolo_detector(fcfg, fweights, fname, gpu_index, dtors_); + + if (!yolo) yolo = new sdkyolo; + return yolo->init_yolo(fcfg, fweights, fname, gpu_index); } void c_api_release(){ - for(auto &i : dtors_){ - i(); - } - dtors_.clear(); + 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}; - return face_detect(faceCount, &img, channel); + 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_property(*pos, &img, channel); + 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}; - return face_extract_feature(featLen, *pos, &img, channel); + 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){ - return face_compare(feat1, feat2); -} - -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); -} - -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); + 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}; - return face_track(fCount, &img, channel); + + 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}; - return yolo_detect(handle, objCount, &img, thrsh, use_means); + 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){ - return yolo_obj_name_by_type(typ); + if (!yolo) return NULL; + + return yolo->yolo_obj_name_by_type(typ); } \ No newline at end of file -- Gitblit v1.8.0