New file |
| | |
| | | #ifdef __cplusplus |
| | | extern "C"{ |
| | | #endif |
| | | |
| | | #include "cface.h" |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | #endif |
| | | |
| | | #include "csrc/face.h" |
| | | |
| | | #include "csrc/struct.h" |
| | | |
| | | #include "csrc/face.cpp" |
| | | |
| | | using namespace cppface; |
| | | |
| | | void *create_sdkface(){ |
| | | return new sdkface(); |
| | | } |
| | | |
| | | void release(void *handle){ |
| | | if (handle){ |
| | | sdkface *s = (sdkface*)handle; |
| | | delete s; |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | int init_extractor(void *handle, const int threads_max, const int gpu){ |
| | | sdkface *s = (sdkface*)handle; |
| | | return s->extractor(threads_max, gpu); |
| | | } |
| | | |
| | | int init_propertizer(void *handle, const int threads_max){ |
| | | sdkface *s = (sdkface*)handle; |
| | | return s->propertizer(threads_max); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | 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 resize(void *handle, const int w, const int h, const int chan){ |
| | | sdkface *s = (sdkface*)handle; |
| | | return s->resize(w, h, chan); |
| | | } |
New file |
| | |
| | | #ifndef _c_face_h_ |
| | | #define _c_face_h_ |
| | | |
| | | #ifdef __cplusplus |
| | | extern "C"{ |
| | | #endif |
| | | |
| | | #include "csrc/struct.h" |
| | | |
| | | void *create_sdkface(); |
| | | void release(void *handle); |
| | | |
| | | int init_detector(void *handle, const int min_faces, const int roll_angles, |
| | | const int threads_max, const int gpu); |
| | | |
| | | int init_extractor(void *handle, const int threads_max, const int gpu); |
| | | int init_propertizer(void *handle, const int threads_max); |
| | | |
| | | 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); |
| | | |
| | | int detect(void *handle, const void *data, const int w, const int h, const int c, const int chan, void **fpos, int *fcnt); |
| | | 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); |
| | | float compare(void *handle, unsigned char *feat1, unsigned char *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); |
| | | |
| | | int track(void *handle, const void *data, const int w, const int h, const int c, const int chan, void **fInfo, int *fcnt); |
| | | int resize(void *handle, const int w, const int h, const int chan); |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | #endif |
| | | |
| | | #endif |
New file |
| | |
| | | #include "face.h" |
| | | |
| | | #include <memory.h> |
| | | |
| | | #include "THFaceImage_i.h" |
| | | #include "THFeature_i.h" |
| | | #include "THFaceProperty_i.h" |
| | | #include "THFaceTracking_i.h" |
| | | |
| | | namespace cppface |
| | | { |
| | | sdkface::sdkface() |
| | | :fpos_(NULL) |
| | | ,feature_size_(0) |
| | | ,feature_(NULL) |
| | | ,finfos_(NULL) |
| | | {} |
| | | |
| | | sdkface::~sdkface() |
| | | { |
| | | for (auto i : dtors_){ |
| | | i(); |
| | | } |
| | | if (fpos_) free(fpos_); |
| | | if (feature_) free(feature_); |
| | | if (finfos_) free(finfos_); |
| | | } |
| | | |
| | | int sdkface::detector(const int min_faces, const int roll_angles, |
| | | const int threads_max, const int gpu){ |
| | | int ret = 0; |
| | | if (gpu < 0) { |
| | | THFI_Param *param = new THFI_Param[threads_max]; |
| | | ret = THFI_Create(threads_max, param); |
| | | delete[] param; |
| | | } else { |
| | | THFI_Param_Ex *param = new THFI_Param_Ex[threads_max]; |
| | | THFI_Param detParam; |
| | | detParam.nMinFaceSize = min_faces; |
| | | detParam.nRollAngle = roll_angles; |
| | | for (int i = 0; i < threads_max; i++) { |
| | | param[i].tp = detParam; |
| | | param[i].nDeviceID = gpu; |
| | | } |
| | | ret = THFI_Create_Ex(threads_max, param); |
| | | delete[] param; |
| | | } |
| | | if(ret != threads_max){ |
| | | printf("create face detector failed!\n"); |
| | | }else{ |
| | | dtors_.emplace_back([]{THFI_Release();}); |
| | | } |
| | | |
| | | return ret; |
| | | } |
| | | |
| | | int sdkface::extractor(const int threads_max, const int gpu){ |
| | | int ret = 0; |
| | | if (gpu < 0) { |
| | | ret = EF_Init(threads_max); |
| | | } else { |
| | | EF_Param *param = new EF_Param[threads_max]; |
| | | for (int i = 0; i < threads_max; i++) { |
| | | param[i].nDeviceID = gpu; |
| | | } |
| | | ret = EF_Init_Ex(threads_max, param); |
| | | delete[] param; |
| | | } |
| | | if(ret != threads_max){ |
| | | printf("create face extractor failed!\n");; |
| | | }else{ |
| | | dtors_.emplace_back([]{EF_Release();}); |
| | | } |
| | | return ret; |
| | | |
| | | } |
| | | |
| | | int sdkface::propertizer(const int threads_max){ |
| | | auto ret = THFP_Create(threads_max); |
| | | if(ret != threads_max){ |
| | | printf("create face property error\n"); |
| | | }else{ |
| | | dtors_.emplace_back([]{THFP_Release();}); |
| | | } |
| | | return ret; |
| | | } |
| | | |
| | | static const int maxFacePos = 30; |
| | | int sdkface::detect(const cIMAGE *img, const int chan, void **fpos, int *fcnt){ |
| | | if(chan < 0 || !img || !img->data || img->width <= 0 || img->height <= 0){ |
| | | return -1; |
| | | } |
| | | |
| | | if (fpos_ == NULL){ |
| | | fpos_ = (cFacePos*)malloc(maxFacePos * sizeof(cFacePos)); |
| | | } |
| | | |
| | | // ::THFI_FacePos facesPos[maxFacePos]; |
| | | int faceNum = THFI_DetectFace(chan, (BYTE*)(img->data), 24, img->width, img->height, |
| | | (::THFI_FacePos*)fpos_, maxFacePos); |
| | | |
| | | if (faceNum > 0) { |
| | | // memcpy(fpos_, facesPos, sizeof(THFI_FacePos) * faceNum); |
| | | *fcnt = faceNum; |
| | | *fpos = fpos_; |
| | | } |
| | | return faceNum; |
| | | } |
| | | |
| | | int sdkface::extract(const cFacePos &pos, const cIMAGE *img, const int chan, void **feat, int *featLen){ |
| | | if(chan < 0 || !img || !img->data || img->width <= 0 || img->height <= 0){ |
| | | printf("face extract error, image or pos null\n"); |
| | | return -1; |
| | | } |
| | | |
| | | *featLen = EF_Size(); |
| | | if (feature_size_ < *featLen){ |
| | | free(feature_); |
| | | feature_ = (unsigned char*)malloc(*featLen); |
| | | feature_size_ = *featLen; |
| | | } |
| | | |
| | | auto ret = EF_Extract(chan, (BYTE*)(img->data), img->width, img->height, 3, |
| | | (THFI_FacePos*)(&pos), feature_); |
| | | |
| | | if(ret != 1){ |
| | | printf("face extract error %d\n", ret); |
| | | return ret; |
| | | } |
| | | |
| | | *feat = feature_; |
| | | |
| | | return *featLen; |
| | | } |
| | | |
| | | float sdkface::compare(unsigned char *feat1, unsigned char *feat2){ |
| | | if (!feat1 || !feat2){ |
| | | return 0.0f; |
| | | } |
| | | |
| | | return EF_Compare(feat1, feat2); |
| | | } |
| | | |
| | | int sdkface::propertize(const cFacePos &pos, const cIMAGE *img, const int chan, void **res){ |
| | | if(chan < 0 || !img || !img->data || img->width <= 0 || img->height <= 0){ |
| | | printf("face propertize error, image or pos null\n"); |
| | | return -1; |
| | | } |
| | | |
| | | cThftResult *thft = (cThftResult*)malloc(sizeof(cThftResult)); |
| | | |
| | | *res = NULL; |
| | | auto ret = THFP_Execute_V2(chan, (BYTE*)(img->data), img->width, img->height, |
| | | (THFI_FacePos*)(&pos), (THFP_Result_V2*)thft); |
| | | if(ret == 0){ |
| | | *res = thft; |
| | | // printf("property face gender %s, age %d, race %s, beauty level %d, smile_level %d\n", |
| | | // res.gender ?"male":"female", |
| | | // res.age, |
| | | // res.race==2?"yello":"other", |
| | | // res.beauty_level, res.smile_level); |
| | | } |
| | | return ret; |
| | | } |
| | | |
| | | static THFT_Param param; |
| | | int sdkface::tracker(const int width, const int height, |
| | | const int max_faces, const int interval, const int sample_size, |
| | | const int threads_max, const int gpu){ |
| | | |
| | | param.nDeviceID = gpu; |
| | | param.nImageWidth = width; |
| | | param.nImageHeight = height; |
| | | param.nMaxFaceNum = max_faces; |
| | | param.nSampleSize = sample_size > 0 ? sample_size : width/2; |
| | | param.nDetectionIntervalFrame = interval; |
| | | |
| | | printf("start threads: %d gi: %d size: %dx%d maxface: %d, sample: %d, interval: %d\n", |
| | | threads_max, gpu, width, height, max_faces, sample_size, interval); |
| | | |
| | | auto nNum = THFT_Create(threads_max, ¶m); |
| | | if(nNum != threads_max){ |
| | | printf("create face detector failed!\n"); |
| | | }else{ |
| | | dtors_.emplace_back([]{THFT_Release();}); |
| | | } |
| | | |
| | | printf("end threads: %d gi: %d size: %dx%d maxface: %d, sample: %d, interval: %d\n", |
| | | threads_max, gpu, width, height, max_faces, sample_size, interval); |
| | | |
| | | return nNum; |
| | | } |
| | | |
| | | int sdkface::track(const cIMAGE *img, const int chan, void **fInfo, int *fcnt){ |
| | | if (!finfos_){ |
| | | finfos_ = (cFaceInfo*)malloc(param.nMaxFaceNum * sizeof(cFaceInfo)); |
| | | } |
| | | |
| | | *fcnt = 0; |
| | | |
| | | auto nNum = THFT_FaceTracking(chan, img->data, (THFT_FaceInfo*)finfos_); |
| | | if (nNum > 0){ |
| | | *fcnt = nNum; |
| | | *fInfo = finfos_; |
| | | }else{ |
| | | *fInfo = NULL; |
| | | } |
| | | return nNum; |
| | | } |
| | | |
| | | int sdkface::resize(const int w, const int h, const int chan){ |
| | | THFT_Param tmpParam; |
| | | tmpParam.nDeviceID = param.nDeviceID; |
| | | tmpParam.nImageWidth = w; |
| | | tmpParam.nImageHeight = h; |
| | | tmpParam.nMaxFaceNum = param.nMaxFaceNum; |
| | | tmpParam.nSampleSize = param.nSampleSize; |
| | | tmpParam.nDetectionIntervalFrame = param.nDetectionIntervalFrame; |
| | | |
| | | printf("chan %d size: %dx%d", chan, w, h); |
| | | |
| | | auto flag = THFT_Reset(chan, &tmpParam); |
| | | |
| | | return flag; |
| | | } |
| | | |
| | | } // namespace cppface |
New file |
| | |
| | | #ifndef _cpp_face_hpp_ |
| | | #define _cpp_face_hpp_ |
| | | |
| | | #include <vector> |
| | | #include <functional> |
| | | |
| | | using VecFunc = std::vector<std::function<void()> >; |
| | | |
| | | #include "struct.h" |
| | | |
| | | namespace cppface |
| | | { |
| | | class sdkface{ |
| | | public: |
| | | sdkface(); |
| | | ~sdkface(); |
| | | |
| | | public: |
| | | int detector(const int min_faces, const int roll_angles, |
| | | const int threads_max, const int gpu); |
| | | int extractor(const int threads_max, const int gpu); |
| | | int propertizer(const int threads_max); |
| | | |
| | | int tracker(const int width, const int height, |
| | | const int max_faces, const int interval, const int sample_size, |
| | | const int threads_max, const int gpu); |
| | | |
| | | public: |
| | | int detect(const cIMAGE *img, const int chan, void **fpos, int *fcnt); |
| | | int extract(const cFacePos &pos, const cIMAGE *img, const int chan, void **feat, int *featLen); |
| | | float compare(unsigned char *feat1, unsigned char *feat2); |
| | | |
| | | int propertize(const cFacePos &pos, const cIMAGE *img, const int chan, void **res); |
| | | |
| | | int track(const cIMAGE *img, const int chan, void **fInfo, int *fcnt); |
| | | int resize(const int w, const int h, const int chan); |
| | | private: |
| | | VecFunc dtors_; |
| | | |
| | | cFacePos *fpos_; |
| | | |
| | | int feature_size_; |
| | | unsigned char *feature_; |
| | | |
| | | cFaceInfo *finfos_; |
| | | |
| | | }; |
| | | } // namespace cppface |
| | | |
| | | |
| | | #endif |
New file |
| | |
| | | #ifndef _face_struct_h_ |
| | | #define _face_struct_h_ |
| | | |
| | | typedef struct _cPOINT { |
| | | int x; |
| | | int y; |
| | | } cPOINT; |
| | | |
| | | typedef struct _cRECT { |
| | | int left; |
| | | int top; |
| | | int right; |
| | | int bottom; |
| | | } cRECT; |
| | | |
| | | typedef struct _cIMAGE{ |
| | | unsigned char *data; |
| | | int width; |
| | | int height; |
| | | int channel; |
| | | } cIMAGE; |
| | | |
| | | typedef struct _cFaceAngle { |
| | | int yaw; |
| | | int pitch; |
| | | int roll; |
| | | float confidence; |
| | | } cFaceAngle; |
| | | |
| | | typedef struct _cThftResult { |
| | | int gender;//1-male,0-female |
| | | int age;//range[0-100] |
| | | int race; //[1-white,2-yellow,3-black] |
| | | int beauty_level;//range[0-100] |
| | | int smile_level;//range[0-100] |
| | | } cThftResult; |
| | | |
| | | typedef struct _cFacePos { |
| | | cRECT rcFace; |
| | | cPOINT ptLeftEye; |
| | | cPOINT ptRightEye; |
| | | cPOINT ptMouth; |
| | | cPOINT ptNose; |
| | | cFaceAngle fAngle; |
| | | int nQuality; |
| | | |
| | | unsigned char pFacialData[512]; |
| | | } cFacePos; |
| | | |
| | | typedef struct _cFaceInfo{ |
| | | cRECT rcFace; |
| | | cPOINT ptLeftEye; |
| | | cPOINT ptRightEye; |
| | | cPOINT ptMouth; |
| | | cPOINT ptNose; |
| | | cFaceAngle fAngle; |
| | | int nQuality; |
| | | |
| | | unsigned char pFacialData[8*1024]; |
| | | long nFaceID;//face tracking id |
| | | } cFaceInfo; |
| | | |
| | | #endif |
New file |
| | |
| | | module face |
| | | |
| | | go 1.12 |
| | | |
| | | require basic.com/libgowrapper/sdkstruct.git v0.0.0-20191211011351-89daaec8738e |
New file |
| | |
| | | basic.com/libgowrapper/sdkstruct.git v0.0.0-20191211011351-89daaec8738e h1:FIUozkg3tMk0K6cQMOt/DvlpK/A66AMDdCKpE4qlUzc= |
| | | basic.com/libgowrapper/sdkstruct.git v0.0.0-20191211011351-89daaec8738e/go.mod h1:bNdkzVVGY+oQEcaYN9VlyIK/03WB3NQNQApjiPJjIag= |
New file |
| | |
| | | package main |
| | | |
| | | /* |
| | | #cgo CFLAGS: -I${SRCDIR}/sdk/include -w -g |
| | | #cgo CXXFLAGS: -I${SRCDIR}/sdk/include -w -g -std=c++11 |
| | | #cgo LDFLAGS: -L/usr/local/cuda-8.0/lib64 -L${SRCDIR}/sdk/lib |
| | | #cgo LDFLAGS: -Wl,-rpath,${SRCDIR}/sdk/lib |
| | | #cgo LDFLAGS: -lTHFaceImage -lTHFeature -lTHFaceProperty -lTHFaceTracking |
| | | #cgo LDFLAGS: -lcudart -lcublas -lcurand -lrt -ldl -lpthread |
| | | #include <stdlib.h> |
| | | #include "cface.h" |
| | | */ |
| | | import "C" |
| | | import ( |
| | | "unsafe" |
| | | |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | | ) |
| | | |
| | | // SDKFace sdk |
| | | type SDKFace struct { |
| | | handle unsafe.Pointer |
| | | detector bool |
| | | extractor bool |
| | | propertizer bool |
| | | tracker bool |
| | | } |
| | | |
| | | // NewSDK sdk |
| | | func NewSDK() interface{} { |
| | | h := C.create_sdkface() |
| | | if h == nil { |
| | | return nil |
| | | } |
| | | |
| | | return &SDKFace{ |
| | | handle: h, |
| | | detector: false, |
| | | extractor: false, |
| | | propertizer: false, |
| | | tracker: false, |
| | | } |
| | | } |
| | | |
| | | // Free free |
| | | func Free(i interface{}) { |
| | | s := i.(*SDKFace) |
| | | if s != nil && s.handle != nil { |
| | | C.release(s.handle) |
| | | } |
| | | } |
| | | |
| | | // Detector detector |
| | | func Detector(i interface{}, minFaces, rollAngles, threadMax, gpu int) bool { |
| | | s := i.(*SDKFace) |
| | | if s.detector { |
| | | return true |
| | | } |
| | | ret := C.init_detector(s.handle, C.int(minFaces), C.int(rollAngles), C.int(threadMax), C.int(gpu)) |
| | | if ret <= 0 { |
| | | return false |
| | | } |
| | | s.detector = true |
| | | return true |
| | | } |
| | | |
| | | // Extractor ext |
| | | func Extractor(i interface{}, threadMax, gpu int) bool { |
| | | s := i.(*SDKFace) |
| | | if s.extractor { |
| | | return true |
| | | } |
| | | ret := C.init_extractor(s.handle, C.int(threadMax), C.int(gpu)) |
| | | if ret <= 0 { |
| | | return false |
| | | } |
| | | s.extractor = true |
| | | return true |
| | | } |
| | | |
| | | // Propertizer prop |
| | | func Propertizer(i interface{}, threadMax int) bool { |
| | | s := i.(*SDKFace) |
| | | if s.propertizer { |
| | | return true |
| | | } |
| | | ret := C.init_propertizer(s.handle, C.int(threadMax)) |
| | | if ret <= 0 { |
| | | return false |
| | | } |
| | | s.propertizer = true |
| | | return true |
| | | } |
| | | |
| | | // Tracker track |
| | | func Tracker(i interface{}, w, h, maxFaces, interval, sampleSize, threadMax, gpu int) bool { |
| | | s := i.(*SDKFace) |
| | | if s.tracker { |
| | | return s.tracker |
| | | } |
| | | ret := C.init_tracker(s.handle, C.int(w), C.int(h), C.int(maxFaces), C.int(interval), C.int(sampleSize), C.int(threadMax), C.int(gpu)) |
| | | |
| | | if ret <= 0 { |
| | | return false |
| | | } |
| | | s.tracker = true |
| | | return true |
| | | } |
| | | |
| | | // CFacePosArrayToGoArray convert cFacePos array to go |
| | | func CFacePosArrayToGoArray(cArray unsafe.Pointer, count int) (goArray []sdkstruct.CFacePos) { |
| | | p := uintptr(cArray) |
| | | |
| | | for i := 0; i < count; i++ { |
| | | j := *(*sdkstruct.CFacePos)(unsafe.Pointer(p)) |
| | | |
| | | goArray = append(goArray, j) |
| | | |
| | | p += unsafe.Sizeof(j) |
| | | } |
| | | return |
| | | } |
| | | |
| | | // Detect det |
| | | func Detect(s *SDKFace, data []byte, w, h, c int, ch int) []sdkstruct.CFacePos { |
| | | if !s.detector { |
| | | return nil |
| | | } |
| | | |
| | | var cfpos unsafe.Pointer |
| | | var count C.int |
| | | ret := C.detect(s.handle, unsafe.Pointer(&data[0]), C.int(w), C.int(h), C.int(c), C.int(ch), &cfpos, &count) |
| | | if ret > 0 { |
| | | return CFacePosArrayToGoArray(cfpos, int(count)) |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | // Extract extract |
| | | func Extract(s *SDKFace, fpos sdkstruct.CFacePos, data []byte, w, h, c int, ch int) []byte { |
| | | |
| | | pos := (*C.cFacePos)(unsafe.Pointer(&fpos)) |
| | | |
| | | //(void *handle, const cFacePos *pos, const void*data, const int w, const int h, const int c, const int chan, void **feat, int *featLen); |
| | | var feat unsafe.Pointer |
| | | var featLen C.int |
| | | p := C.extract(s.handle, pos, unsafe.Pointer(&data[0]), C.int(w), C.int(h), C.int(c), C.int(ch), &feat, &featLen) |
| | | if p > 0 { |
| | | return C.GoBytes(feat, featLen) |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | // Compare face compare |
| | | func Compare(i interface{}, feat1 []byte, feat2 []byte) float32 { |
| | | s := i.(*SDKFace) |
| | | if s.extractor { |
| | | return 0 |
| | | } |
| | | |
| | | res := C.compare(s.handle, (*C.uchar)(unsafe.Pointer(&feat1[0])), (*C.uchar)(unsafe.Pointer(&feat2[0]))) |
| | | return float32(res) |
| | | } |
| | | |
| | | // Propertize prop |
| | | func Propertize(s *SDKFace, fpos sdkstruct.CFacePos, data []byte, w, h, c int, ch int) *sdkstruct.CThftResult { |
| | | if !s.propertizer { |
| | | return nil |
| | | } |
| | | |
| | | pos := (*C.cFacePos)(unsafe.Pointer(&fpos)) |
| | | |
| | | var thft unsafe.Pointer |
| | | ret := C.propertize(s.handle, pos, unsafe.Pointer(&data[0]), C.int(w), C.int(h), C.int(c), C.int(ch), &thft) |
| | | if ret == 0 { |
| | | gothft := *(*sdkstruct.CThftResult)(thft) |
| | | C.free(thft) |
| | | return &gothft |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | // CFaceInfoArrayToGoArray convert cFaceInfo array to go |
| | | func CFaceInfoArrayToGoArray(cArray unsafe.Pointer, count int) (goArray []sdkstruct.CFaceInfo) { |
| | | p := uintptr(cArray) |
| | | |
| | | for i := 0; i < count; i++ { |
| | | j := *(*sdkstruct.CFaceInfo)(unsafe.Pointer(p)) |
| | | goArray = append(goArray, j) |
| | | p += unsafe.Sizeof(j) |
| | | } |
| | | return |
| | | } |
| | | |
| | | // Track track |
| | | func Track(s *SDKFace, data []byte, w, h, c int, ch int) []sdkstruct.CFaceInfo { |
| | | if !s.tracker { |
| | | return nil |
| | | } |
| | | |
| | | //img, const int chan, void **fInfo, int *fcnt); |
| | | |
| | | var fCount C.int |
| | | var finfos unsafe.Pointer |
| | | ret := C.track(s.handle, unsafe.Pointer(&data[0]), C.int(w), C.int(h), C.int(c), C.int(ch), &finfos, &fCount) |
| | | |
| | | if ret > 0 { |
| | | faces := CFaceInfoArrayToGoArray(finfos, int(fCount)) |
| | | //if len(faces) > 0{ |
| | | // fmt.Println("faces detected:", len(faces)) |
| | | //} |
| | | |
| | | return faces |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | // FaceInfo2FacePos info -> pos |
| | | func FaceInfo2FacePos(face sdkstruct.CFaceInfo) (fPos sdkstruct.CFacePos) { |
| | | fPos.RcFace = face.RcFace |
| | | fPos.PtLeftEye = face.PtLeftEye |
| | | fPos.PtRightEye = face.PtRightEye |
| | | fPos.PtNose = face.PtNose |
| | | fPos.PtMouth = face.PtMouth |
| | | fPos.FAngle.Yaw = face.FAngle.Yaw |
| | | fPos.FAngle.Pitch = face.FAngle.Pitch |
| | | fPos.FAngle.Roll = face.FAngle.Roll |
| | | fPos.FAngle.Confidence = face.FAngle.Confidence |
| | | |
| | | copy(fPos.PFacialData[:], face.PFacialData[:512]) |
| | | |
| | | return fPos |
| | | } |
| | | |
| | | // TrackerResize init face tracker |
| | | func TrackerResize(i interface{}, w, h, ch int) bool { |
| | | s := i.(*SDKFace) |
| | | |
| | | if !s.tracker { |
| | | return false |
| | | } |
| | | ret := C.resize(s.handle, C.int(w), C.int(h), C.int(ch)) |
| | | if ret >= 0 { |
| | | return true |
| | | } |
| | | return false |
| | | } |
| | | |
| | | // Run run |
| | | func Run(i interface{}, data []byte, w, h, c, dchan int) []sdkstruct.CFaceResult { |
| | | if data == nil || w <= 0 || h <= 0 { |
| | | return nil |
| | | } |
| | | |
| | | s := i.(*SDKFace) |
| | | |
| | | if !s.tracker || !s.extractor || !s.propertizer { |
| | | return nil |
| | | } |
| | | |
| | | channel := c |
| | | if channel == 0 { |
| | | channel = 3 |
| | | } |
| | | |
| | | var fInfo []sdkstruct.CFaceInfo |
| | | |
| | | if s.tracker { |
| | | fInfo = Track(s, data, w, h, c, dchan) |
| | | } |
| | | |
| | | var faces []sdkstruct.CFaceResult |
| | | //将sdk返回值转换成protomsg类型 |
| | | for _, d := range fInfo { |
| | | |
| | | //运行sd |
| | | dec := FaceInfo2FacePos(d) |
| | | prop := Propertize(s, dec, data, w, h, c, dchan) |
| | | feat := Extract(s, dec, data, w, h, c, dchan) |
| | | |
| | | result := sdkstruct.CFaceResult{ |
| | | Info: d, |
| | | Prop: *prop, |
| | | Feat: feat, |
| | | } |
| | | faces = append(faces, result) |
| | | |
| | | } |
| | | |
| | | return faces |
| | | } |
New file |
| | |
| | | #ifndef _FI_STD_DEF_EX_H_ |
| | | #define _FI_STD_DEF_EX_H_ |
| | | |
| | | #ifndef WIN32 |
| | | |
| | | typedef struct tagPOINT |
| | | { |
| | | int x, y; |
| | | }POINT; |
| | | |
| | | typedef struct tagSIZE |
| | | { |
| | | int cx, cy; |
| | | }SIZE; |
| | | |
| | | typedef struct tagRECT |
| | | { |
| | | int left, top, right, bottom; |
| | | }RECT; |
| | | |
| | | typedef unsigned char BYTE; |
| | | typedef unsigned short WORD; |
| | | typedef unsigned int DWORD; |
| | | |
| | | #endif |
| | | |
| | | /* |
| | | typedef struct tagPointF { |
| | | float x; |
| | | float y; |
| | | } TPointF; |
| | | */ |
| | | #endif // _FI_STD_DEF_EX_H_ |
New file |
| | |
| | | #ifndef THFACEIMAGE_I_H |
| | | #define THFACEIMAGE_I_H |
| | | |
| | | #include "FiStdDefEx.h" |
| | | |
| | | /* |
| | | * ============================================================================ |
| | | * Name : THFaceImage_i.h |
| | | * Part of : Face Recognition (THFaceImage) SDK |
| | | * Created : 9.1.2016 by XXX |
| | | * Description: |
| | | * THFaceImage_i.h - Face Recognition (THFaceImage) SDK header file |
| | | * Version : 4.0.0 |
| | | * Copyright: All Rights Reserved by XXXX |
| | | * Revision: |
| | | * ============================================================================ |
| | | */ |
| | | |
| | | #define THFACEIMAGE_API extern "C" |
| | | |
| | | //////Struct define////// |
| | | |
| | | struct FaceAngle |
| | | { |
| | | int yaw;//angle of yaw,from -90 to +90,left is negative,right is postive |
| | | int pitch;//angle of pitch,from -90 to +90,up is negative,down is postive |
| | | int roll;//angle of roll,from -90 to +90,left is negative,right is postive |
| | | float confidence;//confidence of face pose(from 0 to 1,0.6 is suggested threshold) |
| | | }; |
| | | |
| | | struct THFI_FacePos |
| | | { |
| | | RECT rcFace;//coordinate of face |
| | | POINT ptLeftEye;//coordinate of left eye |
| | | POINT ptRightEye;//coordinate of right eye |
| | | POINT ptMouth;//coordinate of mouth |
| | | POINT ptNose;//coordinate of nose |
| | | FaceAngle fAngle;//value of face angle |
| | | int nQuality;//quality of face(from 0 to 100) |
| | | BYTE pFacialData[512];//facial data |
| | | THFI_FacePos() |
| | | { |
| | | memset(&rcFace,0,sizeof(RECT)); |
| | | memset(&ptLeftEye,0,sizeof(POINT)); |
| | | memset(&ptRightEye,0,sizeof(POINT)); |
| | | memset(&ptMouth,0,sizeof(POINT)); |
| | | memset(&ptNose,0,sizeof(POINT)); |
| | | memset(&fAngle,0,sizeof(FaceAngle)); |
| | | nQuality=0; |
| | | memset(pFacialData, 0, 512); |
| | | } |
| | | }; |
| | | |
| | | typedef long long DWORD_PTR; |
| | | struct THFI_Param |
| | | { |
| | | int nMinFaceSize;//min face width size can be detected,default is 50 pixels |
| | | int nRollAngle;//max face roll angle,default is 30(degree) |
| | | bool bOnlyDetect;//ingored |
| | | DWORD_PTR dwReserved;//reserved value,must be NULL |
| | | THFI_Param() |
| | | { |
| | | nMinFaceSize=50; |
| | | nRollAngle=30; |
| | | bOnlyDetect=false; |
| | | dwReserved=NULL; |
| | | } |
| | | }; |
| | | |
| | | struct THFI_Param_Ex |
| | | { |
| | | THFI_Param tp; |
| | | int nDeviceID;//device id for GPU device.eg:0,1,2,3..... |
| | | THFI_Param_Ex() |
| | | { |
| | | nDeviceID = 0; |
| | | } |
| | | }; |
| | | |
| | | //////API define////// |
| | | |
| | | THFACEIMAGE_API int THFI_Create(short nChannelNum,THFI_Param* pParam); |
| | | /* |
| | | The THFI_Create function will initialize the algorithm engine module |
| | | |
| | | Parameters: |
| | | nChannelNum[intput],algorithm channel num,for multi-thread mode,one thread uses one channel |
| | | pParam[input],algorithm engine parameter. |
| | | Return Values: |
| | | If the function succeeds, the return value is valid channel number. |
| | | If the function fails, the return value is zero or negative; |
| | | error code: |
| | | -99,invalid license. |
| | | Remarks: |
| | | This function only can be called one time at program initialization. |
| | | */ |
| | | |
| | | THFACEIMAGE_API int THFI_DetectFace(short nChannelID, BYTE* pImage, int bpp, int nWidth, int nHeight, THFI_FacePos* pfps, int nMaxFaceNums, int nSampleSize=640); |
| | | /* |
| | | The THFI_DetectFace function execute face detection only. |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pImage[input],image data buffer,RGB24 format. |
| | | bpp[input],bits per pixel(24-RGB24 image),must be 24 |
| | | nWidth[input],image width. |
| | | nHeight[input],image height. |
| | | pfps[output],the facial position information. |
| | | nMaxFaceNums[input],max face nums that you want |
| | | nSampleSize[input],down sample size(image down sample) for detect image,if it is 0,will detect by original image. |
| | | Return Values: |
| | | If the function succeeds, the return value is face number. |
| | | If the function fails, the return value is negative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,nChannelID is invalid or SDK is not initialized |
| | | -2,image data is invalid,please check function parameter:pImage,bpp,nWidth,nHeight |
| | | -3,pfps or nMaxFaceNums is invalid. |
| | | Remarks: |
| | | 1.image data buffer(pImage) size must be nWidth*(bpp/8)*nHeight. |
| | | 2.pfps must be allocated by caller,the memory size is nMaxFaceNums*sizeof(THFI_FacePos). |
| | | 3.if image has face(s),face number less than or equal to nMaxFaceNums |
| | | */ |
| | | |
| | | THFACEIMAGE_API int THFI_DetectFaceByEye(short nChannelID, BYTE* pImage, int nWidth, int nHeight, POINT ptLeft, POINT ptRight, THFI_FacePos* pfps); |
| | | /* |
| | | The THFI_DetectFaceByEye function detect facial data by eye position |
| | | |
| | | Parameters: |
| | | pImage[input],image data buffer,rgb24 format,pImage data size must be nWidth*nHeight*3 bytes |
| | | nWidth[input],image width. |
| | | nHeight[input],image height. |
| | | ptLeft[input],left eye position |
| | | ptRight[input],right eye position |
| | | pfps[output],the facial position information. |
| | | Return Values: |
| | | If the function succeeds, the return value is 1. |
| | | If the function fails, the return value is negative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,nChannelID is invalid or SDK is not initialize |
| | | -2,image data is invalid,please check function parameter:pImage,bpp,nWidth,nHeight |
| | | -3,pfps or nMaxFaceNums is invalid. |
| | | */ |
| | | |
| | | THFACEIMAGE_API void THFI_Release(); |
| | | /* |
| | | The THFI_Release function will release the algorithm engine module |
| | | |
| | | Parameters: |
| | | No parameter. |
| | | Return Values: |
| | | No return value. |
| | | Remarks: |
| | | This function only can be called one time at program exit. |
| | | */ |
| | | |
| | | THFACEIMAGE_API int THFI_Create_Ex(short nChannelNum, THFI_Param_Ex* pParam); |
| | | /* |
| | | The THFI_Create_Ex function will initialize the algorithm engine module,,only for GPU version |
| | | |
| | | Parameters: |
| | | nChannelNum[intput],algorithm channel num,for multi-thread mode,one thread uses one channel |
| | | pParam[input],algorithm engine parameter. |
| | | Return Values: |
| | | If the function succeeds, the return value is valid channel number. |
| | | If the function fails, the return value is zero or negative; |
| | | error code: |
| | | -99,invalid license. |
| | | Remarks: |
| | | This function only can be called one time at program initialization. |
| | | */ |
| | | |
| | | #endif |
New file |
| | |
| | | #ifndef THFACELIVE_I_H |
| | | #define THFACELIVE_I_H |
| | | |
| | | /* |
| | | * ============================================================================ |
| | | * Name : THFaceLive_i.h |
| | | * Part of : Face Liveness Detect (THFaceLive) SDK |
| | | * Created : 9.1.2017 by XXX |
| | | * Description: |
| | | * THFaceLive_i.h - Face Liveness Detect (THFaceLive) SDK header file |
| | | * Version : 2.0.0 |
| | | * Copyright: All Rights Reserved by XXXX |
| | | * Revision: |
| | | * ============================================================================ |
| | | */ |
| | | #include "THFaceImage_i.h" |
| | | |
| | | #define THFACELIVE_API extern "C" |
| | | |
| | | THFACELIVE_API int THFL_Create(); |
| | | /* |
| | | The THFL_Create function will initialize the algorithm engine module |
| | | |
| | | Parameters: |
| | | No parameter. |
| | | Return Values: |
| | | If the function succeeds, the return value is 1. |
| | | If the function fails, the return value is negative; |
| | | Remarks: |
| | | This function only can be called one time at program initialization. |
| | | */ |
| | | |
| | | THFACELIVE_API int THFL_Detect(unsigned char* pBuf_color, unsigned char* pBuf_bw, int nWidth, int nHeight, THFI_FacePos* ptfp_color, THFI_FacePos* ptfp_bw, int nThreshold=30); |
| | | /* |
| | | The THFL_Detect function execute face liveness detection |
| | | |
| | | Parameters: |
| | | pBuf_color[input],color camera image data buffer,bgr format. |
| | | pBuf_bw[input],black-white camera image data buffer,bgr format. |
| | | nWidth[input],image width. |
| | | nHeight[input],image height. |
| | | ptfp_color[input],face data of color camera image.(THFI_FacePos format,return by THFI_DetectFace of THFaceImage SDK) |
| | | ptfp_bw[input],face data of black-white camera image.(THFI_FacePos format,return by THFI_DetectFace of THFaceImage SDK) |
| | | nThreshold[input],score threshold(sugguest value is 30) |
| | | Return Values: |
| | | If the function succeeds, the return value is 0 or 1.(0->fake face,1->live face) |
| | | If the function fails, the return value is negative. |
| | | Remarks: |
| | | */ |
| | | THFACELIVE_API void THFL_Release(); |
| | | /* |
| | | The THFL_Release function will release the algorithm engine module |
| | | |
| | | Parameters: |
| | | No parameter. |
| | | Return Values: |
| | | No return value. |
| | | Remarks: |
| | | This function only can be called one time at program exit. |
| | | */ |
| | | |
| | | #endif |
New file |
| | |
| | | #ifndef THFACEPROP_I_H |
| | | #define THFACEPROP_I_H |
| | | |
| | | #include "THFaceImage_i.h" |
| | | |
| | | /* |
| | | * ============================================================================ |
| | | * Name : THFaceProperty_i.h |
| | | * Part of : Face Property (THFaceProperty) SDK |
| | | * Created : 7.8.2016 by XXX |
| | | * Description: |
| | | * THFaceProp_i.h - Face Property (THFaceProperty) SDK header file |
| | | * Version : 1.0.0 |
| | | * Copyright: All Rights Reserved by XXXX |
| | | * Revision: |
| | | * ============================================================================ |
| | | */ |
| | | |
| | | struct THFP_Result_V1 |
| | | { |
| | | int gender;//1-male,0-female |
| | | int age;//range[0-100] |
| | | int beauty_level;//range[0-100] |
| | | int smile_level;//range[0-100] |
| | | }; |
| | | |
| | | struct THFP_Result_V2 |
| | | { |
| | | int gender;//1-male,0-female |
| | | int age;//range[0-100] |
| | | int race; //[1-white,2-yellow,3-black] |
| | | int beauty_level;//range[0-100] |
| | | int smile_level;//range[0-100] |
| | | }; |
| | | |
| | | #define THFACEPROP_API extern "C" |
| | | |
| | | THFACEPROP_API int THFP_Create(short nChannelNum); |
| | | /* |
| | | The THFP_Create function will initialize the algorithm engine module |
| | | |
| | | Parameters: |
| | | nChannelNum[intput],algorithm channel num,for multi-thread mode,one thread uses one channel |
| | | Return Values: |
| | | If the function succeeds, the return value is valid channel number. |
| | | If the function fails, the return value is zero or negative; |
| | | error code: |
| | | -99,invalid license. |
| | | Remarks: |
| | | This function only can be called one time at program initialization. |
| | | */ |
| | | |
| | | THFACEPROP_API void THFP_Release(); |
| | | /* |
| | | The THFP_Release function will release the algorithm engine module |
| | | |
| | | Parameters: |
| | | No parameter. |
| | | Return Values: |
| | | No return value. |
| | | Remarks: |
| | | This function only can be called one time at program exit. |
| | | */ |
| | | |
| | | THFACEPROP_API int THFP_Execute_V1(short nChannelID, BYTE* pBGR, int nWidth, int nHeight, THFI_FacePos* ptfp, THFP_Result_V1* pResult); |
| | | /* |
| | | The THFP_Execute_V1 function execute face property analysis. |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pBGR[input],point to an image buffer,BGR format. |
| | | nWidth[input],the image width. |
| | | nHeight[input],the image height. |
| | | ptfp[input],the facial data of a face. |
| | | pResult[output],the face property result |
| | | Return Values: |
| | | If the function succeeds, the return value is 0. |
| | | If the function fails, the return value is nagative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,pBuf,ptfp,pFeature is NULL |
| | | -2,nChannelID is invalid or SDK is not initialized |
| | | Remarks: |
| | | No remark. |
| | | */ |
| | | THFACEPROP_API int THFP_Execute_1N_V1(short nChannelID, BYTE* pBGR, int nWidth, int nHeight, THFI_FacePos* ptfps, THFP_Result_V1* pResults,int nFaceCount); |
| | | /* |
| | | The THFP_Execute_1N_V1 function execute face property analysis. |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pBGR[input],point to an image buffer,BGR format. |
| | | nWidth[input],the image width. |
| | | nHeight[input],the image height. |
| | | ptfps[input],the facial data of muti-faces |
| | | pResults[output],the face property results of muti-faces |
| | | nFaceCount[input],the face number |
| | | Return Values: |
| | | If the function succeeds, the return value is 0. |
| | | If the function fails, the return value is nagative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,pBGR,ptfps,pResults is NULL,OR nFaceCount is less than 1 |
| | | -2,nChannelID is invalid or SDK is not initialized |
| | | Remarks: |
| | | No remark. |
| | | */ |
| | | THFACEPROP_API int THFP_Execute_V2(short nChannelID, BYTE* pBGR, int nWidth, int nHeight, THFI_FacePos* ptfp, THFP_Result_V2* pResult); |
| | | /* |
| | | The THFP_Execute_V2 function execute face property analysis. |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pBGR[input],point to an image buffer,BGR format. |
| | | nWidth[input],the image width. |
| | | nHeight[input],the image height. |
| | | ptfp[input],the facial data of a face. |
| | | pResult[output],the face property result |
| | | Return Values: |
| | | If the function succeeds, the return value is 0. |
| | | If the function fails, the return value is nagative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,pBGR,ptfp,pResult is NULL |
| | | -2,nChannelID is invalid or SDK is not initialized |
| | | Remarks: |
| | | No remark. |
| | | */ |
| | | |
| | | THFACEPROP_API int THFP_Execute_1N_V2(short nChannelID, BYTE* pBGR, int nWidth, int nHeight, THFI_FacePos* ptfps, THFP_Result_V2* pResults, int nFaceCount); |
| | | /* |
| | | The THFP_Execute_1N_V2 function execute face property analysis. |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pBGR[input],point to an image buffer,BGR format. |
| | | nWidth[input],the image width. |
| | | nHeight[input],the image height. |
| | | ptfps[input],the facial data of muti-faces |
| | | pResults[output],the face property results of muti-faces |
| | | nFaceCount[input],the face number |
| | | Return Values: |
| | | If the function succeeds, the return value is 0. |
| | | If the function fails, the return value is nagative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,pBGR,ptfps,pResults is NULL,OR nFaceCount is less than 1 |
| | | -2,nChannelID is invalid or SDK is not initialized |
| | | Remarks: |
| | | No remark. |
| | | */ |
| | | |
| | | #endif |
New file |
| | |
| | | #ifndef THFACETRACKING_I_H |
| | | #define THFACETRACKING_I_H |
| | | |
| | | #include "FiStdDefEx.h" |
| | | |
| | | /* |
| | | * ============================================================================ |
| | | * Name : THFaceTracking_i.h |
| | | * Part of : Face Tracking (THFaceTracking) SDK |
| | | * Created : 11.22.2017 by XXX |
| | | * Description: |
| | | * THFaceTracking_i.h - Face Tracking (THFaceTracking) SDK header file |
| | | * Version : 1.0.0 |
| | | * Copyright: All Rights Reserved by XXXX |
| | | * Revision: |
| | | * ============================================================================ |
| | | */ |
| | | |
| | | struct FacePose |
| | | { |
| | | int yaw;//angle of yaw,from -90 to +90,left is negative,right is postive |
| | | int pitch;//angle of pitch,from -90 to +90,up is negative,down is postive |
| | | int roll;//angle of roll,from -90 to +90,left is negative,right is postive |
| | | float confidence;//confidence of face pose(from 0 to 1,0.6 is suggested threshold) |
| | | }; |
| | | |
| | | struct THFT_FaceInfo |
| | | { |
| | | RECT rcFace;//coordinate of face |
| | | POINT ptLeftEye;//coordinate of left eye |
| | | POINT ptRightEye;//coordinate of right eye |
| | | POINT ptMouth;//coordinate of mouth |
| | | POINT ptNose;//coordinate of nose |
| | | FacePose fAngle;//value of face angle |
| | | int nQuality;//quality of face(from 0 to 100) |
| | | BYTE pFacialData[8*1024];//facial data |
| | | |
| | | long nFaceID;//face tracking id |
| | | |
| | | THFT_FaceInfo() |
| | | { |
| | | memset(&rcFace, 0, sizeof(RECT)); |
| | | memset(&ptLeftEye, 0, sizeof(POINT)); |
| | | memset(&ptRightEye, 0, sizeof(POINT)); |
| | | memset(&ptMouth, 0, sizeof(POINT)); |
| | | memset(&ptNose, 0, sizeof(POINT)); |
| | | memset(&fAngle, 0, sizeof(FacePose)); |
| | | nQuality = 0; |
| | | memset(pFacialData, 0, 8 * 1024); |
| | | |
| | | nFaceID = -1; |
| | | } |
| | | }; |
| | | |
| | | struct THFT_Param |
| | | { |
| | | int nDeviceID;//device id for GPU device.eg:0,1,2,3..... |
| | | |
| | | int nImageWidth;//image width of video |
| | | int nImageHeight;//image height of video |
| | | int nMaxFaceNum;//max face number for tracking |
| | | int nSampleSize;//down sample size for face detection |
| | | int nDetectionIntervalFrame;//interval frame number of face detection for face tracking |
| | | |
| | | THFT_Param() |
| | | { |
| | | nMaxFaceNum = 100; |
| | | nSampleSize = 640; |
| | | nDeviceID = 0; |
| | | nDetectionIntervalFrame = 5; |
| | | } |
| | | }; |
| | | |
| | | #define THFACETRACKING_API extern "C" |
| | | |
| | | |
| | | THFACETRACKING_API int THFT_Create(short nChannelNum,THFT_Param* pParam); |
| | | /* |
| | | The THFT_Create function will initialize the algorithm engine module |
| | | |
| | | Parameters: |
| | | nChannelNum[intput],algorithm channel num,for multi-thread mode,one thread uses one channel |
| | | pParam[input],algorithm engine parameter. |
| | | Return Values: |
| | | If the function succeeds, the return value is valid channel number. |
| | | If the function fails, the return value is zero or negative; |
| | | error code: |
| | | -99,invalid license. |
| | | Remarks: |
| | | This function only can be called one time at program initialization. |
| | | */ |
| | | |
| | | THFACETRACKING_API void THFT_Release(); |
| | | /* |
| | | The THFT_Release function will release the algorithm engine module |
| | | |
| | | Parameters: |
| | | No parameter. |
| | | Return Values: |
| | | No return value. |
| | | Remarks: |
| | | This function only can be called one time at program exit. |
| | | */ |
| | | |
| | | THFACETRACKING_API int THFT_FaceTracking(short nChannelID, unsigned char* pBGR,THFT_FaceInfo* pFaceInfos); |
| | | /* |
| | | The THFT_FaceTracking function execute face detection and face tracking |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pBGR[input],image data buffer,BGR format. |
| | | pFaceInfos[output],the facial position information. |
| | | Return Values: |
| | | If the function succeeds, the return value is face number. |
| | | If the function fails, the return value is negative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,nChannelID is invalid or SDK is not initialized |
| | | -2,image data is invalid,please check function parameter:pBGR |
| | | -3,pFaceInfos is invalid. |
| | | Remarks: |
| | | 1.image data buffer(pBGR) size must be (THFT_Param::nImageWidth * THFT_Param::nImageHeight * 3) |
| | | 2.pFaceInfos must be allocated by caller,the memory size is THFT_Param::nMaxFaceNum*sizeof(THFT_FaceInfo). |
| | | 3.if image has face(s),face number less than or equal to THFT_Param::nMaxFaceNums |
| | | */ |
| | | |
| | | THFACETRACKING_API int THFT_FaceDetect(short nChannelID, BYTE* pBGR, int nWidth, int nHeight, THFT_FaceInfo* pFaceInfos, int nMaxFaceNums, int nSampleSize); |
| | | /* |
| | | The THFT_FaceDetect function execute facial detection for an image |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pBGR[input],image data buffer,BGR format. |
| | | nWidth[input],image width. |
| | | nHeight[input],image height. |
| | | pFaceInfos[output],the facial position information. |
| | | nMaxFaceNums[input],max face nums that you want |
| | | nSampleSize[input],down sample size(image down sample) for detect image,if it is 0,will detect by original image. |
| | | Return Values: |
| | | If the function succeeds, the return value is face number. |
| | | If the function fails, the return value is negative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,nChannelID is invalid or SDK is not initialized |
| | | -2,image data is invalid,please check function parameter:pBGR,nWidth,nHeight |
| | | -3,pFaceInfos or nMaxFaceNums is invalid. |
| | | Remarks: |
| | | 1.image data buffer(pBGR) size must be nWidth*nHeight*3. |
| | | 2.pFaceInfos must be allocated by caller,the memory size is nMaxFaceNums*sizeof(THFT_FaceInfo). |
| | | 3.if image has face(s),face number less than or equal to nMaxFaceNums |
| | | */ |
| | | |
| | | THFACETRACKING_API int THFT_FaceOnly(short nChannelID, BYTE* pBGR, int nWidth, int nHeight, RECT* pFaces, int nMaxFaceNums, int nSampleSize); |
| | | /* |
| | | The THFT_FaceOnly function execute face rectangle detection only |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pBGR[input],image data buffer,BGR format. |
| | | nWidth[input],image width. |
| | | nHeight[input],image height. |
| | | pFaces[output],the face rectangle |
| | | nMaxFaceNums[input],max face nums that you want |
| | | nSampleSize[input],down sample size(image down sample) for detect image,if it is 0,will detect by original image. |
| | | Return Values: |
| | | If the function succeeds, the return value is face number. |
| | | If the function fails, the return value is negative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,nChannelID is invalid or SDK is not initialized |
| | | -2,image data is invalid,please check function parameter:pBGR,nWidth,nHeight |
| | | -3,pFaces or nMaxFaceNums is invalid. |
| | | Remarks: |
| | | 1.image data buffer(pBGR) size must be nWidth*nHeight*3. |
| | | 2.pFaces must be allocated by caller,the memory size is nMaxFaceNums*sizeof(RECT). |
| | | 3.if image has face(s),face number less than or equal to nMaxFaceNums |
| | | */ |
| | | |
| | | THFACETRACKING_API int THFT_Reset(short nChannelID, THFT_Param* pParam); |
| | | /* |
| | | The THFT_Reset function will reset parameters for an algorithm channel |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pParam[input],algorithm channel parameter. |
| | | Return Values: |
| | | If the function succeeds, the return value is 0. |
| | | If the function fails, the return value is negative; |
| | | error code: |
| | | -99,invalid license. |
| | | Remarks: |
| | | NULL |
| | | */ |
| | | |
| | | #endif |
New file |
| | |
| | | #ifndef THFEATURE_I_H |
| | | #define THFEATURE_I_H |
| | | |
| | | #include "THFaceImage_i.h" |
| | | |
| | | /* |
| | | * ============================================================================ |
| | | * Name : THFeature_i.h |
| | | * Part of : Face Feature (THFeature) SDK |
| | | * Created : 10.18.2016 by xxx |
| | | * Description: |
| | | * THFeature_i.h - Face Feature(THFeature) SDK header file |
| | | * Version : 5.0.0 |
| | | * Copyright: All Rights Reserved by XXX |
| | | * Revision: |
| | | * ============================================================================ |
| | | */ |
| | | |
| | | #define THFEATURE_API extern "C" |
| | | |
| | | struct TH_Image_Data |
| | | { |
| | | BYTE* bgr;//MUST BE bgr format buffer,the size is width*height*3 bytes |
| | | int width;//image width |
| | | int height;//image height |
| | | }; |
| | | |
| | | struct EF_Param |
| | | { |
| | | int nDeviceID;//device id for GPU device.eg:0,1,2,3..... |
| | | EF_Param() |
| | | { |
| | | nDeviceID = 0; |
| | | } |
| | | }; |
| | | //////API define////// |
| | | |
| | | THFEATURE_API short EF_Init(int nChannelNum); |
| | | /* |
| | | The EF_Init function will initialize the Face Feature(THFeature) algorithm module |
| | | |
| | | Parameters: |
| | | nChannelNum,the channel number,support for muti-thread,one channel stand for one thread.max value is 32. |
| | | Return Values: |
| | | If the function succeeds, the return value is valid channel number. |
| | | If the function fails, the return value is 0 or nagative; |
| | | error code: |
| | | -99,invalid license. |
| | | -1,open file "feadb.db*" error |
| | | -2,check file "feadb.db*" error |
| | | -3,read file "feadb.db*" error |
| | | Remarks: |
| | | This function can be called one time at program initialization. |
| | | */ |
| | | |
| | | THFEATURE_API int EF_Size(); |
| | | /* |
| | | The EF_Size function will return face feature size. |
| | | |
| | | Parameters: |
| | | No parameter. |
| | | Return Values: |
| | | If the function succeeds, the return value is face feature size. |
| | | If the function fails, the return value is 0 or nagative; |
| | | error code: |
| | | -99,invalid license. |
| | | Remarks: |
| | | No remark. |
| | | */ |
| | | |
| | | THFEATURE_API int EF_Extract(short nChannelID, BYTE* pBuf, int nWidth, int nHeight, int nChannel, THFI_FacePos* ptfp, BYTE* pFeature); |
| | | /* |
| | | The EF_Extract function execute face feature extraction from one photo |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pBuf[input],point to an image buffer,BGR format. |
| | | nWidth[input],the image width. |
| | | nHeight[input],the image height. |
| | | nChannel[input],image buffer channel,must be 3 |
| | | ptfp[input],the facial data of a face. |
| | | pFeature[output],the face feature buffer |
| | | Return Values: |
| | | If the function succeeds, the return value is 1. |
| | | If the function fails, the return value is nagative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,pBuf,ptfp,pFeature is NULL |
| | | -2,nChannelID is invalid or SDK is not initialized |
| | | Remarks: |
| | | No remark. |
| | | */ |
| | | |
| | | THFEATURE_API int EF_Extract_M(short nChannelID, BYTE* pBuf, int nWidth, int nHeight, int nChannel, THFI_FacePos* ptfps, BYTE* pFeatures, int nFaceNum); |
| | | /* |
| | | The EF_Extract_M function execute face feature extraction for muti-faces from one photo |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | pBuf[input],point to an image buffer,BGR format. |
| | | nWidth[input],the image width. |
| | | nHeight[input],the image height. |
| | | nChannel[input],image buffer channel,must be 3 |
| | | ptfps[input],the facial data of muti-faces |
| | | pFeatures[output],the face feature buffer for muti-faces |
| | | nFaceNum[input],the face number |
| | | Return Values: |
| | | If the function succeeds, the return value is 1. |
| | | If the function fails, the return value is 0 or nagative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,pBuf,ptfps,pFeatures is NULL |
| | | -2,nChannelID is invalid or SDK is not initialized |
| | | Remarks: |
| | | No remark. |
| | | */ |
| | | |
| | | THFEATURE_API int EF_Extracts(short nChannelID, TH_Image_Data* ptids, THFI_FacePos* ptfps, BYTE* pFeatures, int nNum); |
| | | /* |
| | | The EF_Extracts function execute face feature extraction for muti-faces from muti-photos |
| | | |
| | | Parameters: |
| | | nChannelID[input],channel ID(from 0 to nChannelNum-1) |
| | | ptids[input],the image data list of muti-photos |
| | | ptfps[input],the facial data list of muti-photos(one image data-one facial data) |
| | | pFeatures[output],the face feature buffer for muti-faces |
| | | nNum[input],the image data number |
| | | Return Values: |
| | | If the function succeeds, the return value is 1. |
| | | If the function fails, the return value is 0 or nagative. |
| | | error code: |
| | | -99,invalid license. |
| | | -1,ptids,ptfp,pFeature is NULL |
| | | -2,nChannelID is invalid or SDK is not initialized |
| | | Remarks: |
| | | No remark. |
| | | */ |
| | | |
| | | THFEATURE_API float EF_Compare(BYTE* pFeature1, BYTE* pFeature2); |
| | | /* |
| | | The EF_Compare function execute two face features compare. |
| | | |
| | | Parameters: |
| | | pFeature1[input],point to one face feature buffer. |
| | | pFeature2[input],point to another face feature buffer. |
| | | Return Values: |
| | | the return value is the two face features's similarity. |
| | | Remarks: |
| | | No remark. |
| | | */ |
| | | |
| | | THFEATURE_API void EF_Release(); |
| | | /* |
| | | The EF_Release function will release the Face Feature (THFeature) algorithm module |
| | | |
| | | Parameters: |
| | | No parameter. |
| | | Return Values: |
| | | No return value. |
| | | Remarks: |
| | | This function can be called one time at program Un-Initialization. |
| | | */ |
| | | |
| | | THFEATURE_API short EF_Init_Ex(int nChannelNum, EF_Param* pParam = NULL); |
| | | /* |
| | | The EF_Init_Ex function will initialize the Face Feature(THFeature) algorithm module,only for GPU version |
| | | |
| | | Parameters: |
| | | nChannelNum,the channel number,support for muti-thread,one channel stand for one thread.max value is 32. |
| | | pParam,initialize parameter |
| | | Return Values: |
| | | If the function succeeds, the return value is valid channel number. |
| | | If the function fails, the return value is 0 or nagative; |
| | | error code: |
| | | -99,invalid license. |
| | | -1,open file "feadb.db*" error |
| | | -2,check file "feadb.db*" error |
| | | -3,read file "feadb.db*" error |
| | | Remarks: |
| | | This function can be called one time at program initialization. |
| | | */ |
| | | |
| | | #endif |
New file |
| | |
| | | Face-SDK-CUDA-Linux64V7.0.3 和 FaceTracking-SDK-CUDA-Linux64 V1.0.0-timeout2018 的合并 |