| | |
| | | return face_compare(feat1, feat2); |
| | | } |
| | | |
| | | // quality |
| | | int c_api_face_quality_init(const int tm){ |
| | | return init_face_quality(tm, dtors_); |
| | | } |
| | | |
| | | void c_api_set_quality_params(const int min, const int max){ |
| | | return set_quality_params(min, max); |
| | | } |
| | | |
| | | cThfqResult* c_api_face_check_quality(const cFacePos *pos, uchar*data, const int w, const int h, const int channel){ |
| | | const cIMAGE img{data, w, h, 3}; |
| | | return face_check_quality(channel, &img, *pos); |
| | | } |
| | | |
| | | int c_api_face_check_quality_brightness(const cFacePos *pos, uchar*data, const int w, const int h, const int channel, int *nBrightness){ |
| | | const cIMAGE img{data, w, h, 3}; |
| | | return face_check_quality_brightness(channel, &img, *pos, nBrightness); |
| | | } |
| | | |
| | | int c_api_face_check_quality_occlusion(const cFacePos *pos, uchar*data, const int w, const int h, const int channel, int *nOcclusion){ |
| | | const cIMAGE img{data, w, h, 3}; |
| | | return face_check_quality_occlusion(channel, &img, *pos, nOcclusion); |
| | | } |
| | | |
| | | int c_api_face_check_quality_hat(const cFacePos *pos, uchar*data, const int w, const int h, const int channel, int *nHat){ |
| | | const cIMAGE img{data, w, h, 3}; |
| | | return face_check_quality_hat(channel, &img, *pos, nHat); |
| | | } |
| | | |
| | | int c_api_face_check_quality_blur_glass(const cFacePos *pos, uchar*data, const int w, const int h, |
| | | const int channel, int* nBlur,int* nGlasses){ |
| | | const cIMAGE img{data, w, h, 3}; |
| | | return face_check_quality_blur_glass(channel, &img, *pos, nBlur, nGlasses); |
| | | } |
| | | |
| | | 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}; |
| | | |
| | |
| | | cFaceInfo* c_api_face_track_detect(int *fCount, uchar *data, const int wid, const int hei, const int channel); |
| | | cFaceInfo* c_api_face_track(int *fCount, uchar *data, const int wid, const int hei, const int channel); |
| | | |
| | | // quality |
| | | int c_api_face_quality_init(const int tm); |
| | | void c_api_set_quality_params(const int min, const int max); |
| | | cThfqResult* c_api_face_check_quality(const cFacePos *pos, uchar*data, const int w, const int h, const int channel); |
| | | int c_api_face_check_quality_brightness(const cFacePos *pos, uchar*data, const int w, const int h, |
| | | const int channel, int *nBrightness); |
| | | int c_api_face_check_quality_occlusion(const cFacePos *pos, uchar*data, const int w, const int h, |
| | | const int channel, int *nOcclusion); |
| | | int c_api_face_check_quality_hat(const cFacePos *pos, uchar*data, const int w, const int h, |
| | | const int channel, int *nHat); |
| | | int c_api_face_check_quality_blur_glass(const cFacePos *pos, uchar*data, const int w, const int h, |
| | | const int channel, int* nBlur,int* nGlasses); |
| | | |
| | | /// 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); |
| | | const char* c_api_yolo_obj_name(const int typ); |
| | |
| | | long nFaceID;//face tracking id |
| | | } cFaceInfo; |
| | | |
| | | typedef struct _cThfqParam{ |
| | | int brightness_min;//0-100,太暗阈值,建议25.越小越可能把过暗的人脸当作正常人脸,此参数会影响THFQ_Result::brightness |
| | | int brightness_max;//0-100,太亮阈值,建议75.越大越可能把的过亮人脸当作正常人脸,此参数会影响THFQ_Result::brightness |
| | | }cThfqParam; |
| | | |
| | | typedef struct _cThfqResult{ |
| | | int brightness;//人脸亮度,只有3种可能的值:[-1->太暗,0->正常,1->太亮],亮度结果会受亮度阈值参数brightness_min和brightness_max影响 |
| | | int occlusion;//人脸遮挡度,范围值为0-100,越大表示人脸遮挡程度越高 |
| | | int hat;//带帽子,范围为0-100,越大表示越可能有佩戴帽子,建议判别阈值为50 |
| | | int blur;//人脸模糊度,范围值为0-100,越大表示图像越模糊,建议人脸模糊度判别阈值为70 |
| | | int glasses;//带眼镜,范围为0-100,越大表示越可能有戴眼镜,建议判别阈值为70 |
| | | }cThfqResult; |
| | | |
| | | |
| | | typedef struct _cObjInfo |
| | | { |
| | | cRECT rcObj; |
| | |
| | | #include "buz/face/extractor.cpp" |
| | | #include "buz/face/property.cpp" |
| | | #include "buz/face/tracker.cpp" |
| | | #include "buz/face/quality.cpp" |
| | | |
| | | #include "buz/yolo/detector.cpp" |
| | | |
New file |
| | |
| | | #include "quality.h" |
| | | |
| | | #include "THFaceQuality_i.h" |
| | | #include "csdk_struct.h" |
| | | |
| | | namespace csdk_wrap{ |
| | | int init_face_quality(const int tm, VecFunc &vec){ |
| | | auto ret = THFQ_Create(tm); |
| | | if(ret != tm){ |
| | | printf("create face quality error\n"); |
| | | }else{ |
| | | vec.emplace_back([]{THFQ_Release();}); |
| | | } |
| | | return ret; |
| | | } |
| | | |
| | | void set_quality_params(const int min, const int max){ |
| | | int _min = (min<=10)?10:((min>=40)?40:min); |
| | | int _max = (max>=90)?90:((max<=60)?60:max); |
| | | const cThfqParam params{_min, _max}; |
| | | printf("set_quality_params : %d, %d\n", _min, _max); |
| | | |
| | | THFQ_SetParam((THFQ_Param*)¶ms); |
| | | } |
| | | |
| | | cThfqResult* face_check_quality(const int chan, const cIMAGE *img, const cFacePos &pos){ |
| | | if(chan < 0 || !img){ |
| | | printf("face check quality error, image or pos null\n"); |
| | | return NULL; |
| | | } |
| | | |
| | | cThfqResult *pResult = (cThfqResult*)malloc(sizeof(cThfqResult)); |
| | | auto ret = THFQ_Check(chan, (BYTE*)(img->data), 3, img->width, img->height, (THFI_FacePos*)(&pos), (THFQ_Result*)pResult); |
| | | return pResult; |
| | | } |
| | | |
| | | int face_check_quality_brightness(const int chan, const cIMAGE *img, const cFacePos &pos, int *nBrightness){ |
| | | if(!img){ |
| | | printf("face check quality error, image or pos null\n"); |
| | | return -1; |
| | | } |
| | | |
| | | auto ret = THFQ_Check_Brightness(chan, (BYTE*)(img->data), 3, img->width, img->height, (THFI_FacePos*)(&pos), (int*)nBrightness); |
| | | return ret; |
| | | } |
| | | |
| | | int face_check_quality_occlusion(const int chan, const cIMAGE *img, const cFacePos &pos, int *nOcclusion){ |
| | | if(!img){ |
| | | printf("face check quality error, image or pos null\n"); |
| | | return -1; |
| | | } |
| | | |
| | | auto ret = THFQ_Check_Occlusion(chan, (BYTE*)(img->data), 3, img->width, img->height, (THFI_FacePos*)(&pos), (int*)nOcclusion); |
| | | return ret; |
| | | } |
| | | int face_check_quality_hat(const int chan, const cIMAGE *img, const cFacePos &pos, int *nHat){ |
| | | if(!img){ |
| | | printf("face check quality error, image or pos null\n"); |
| | | return -1; |
| | | } |
| | | |
| | | auto ret = THFQ_Check_Hat(chan, (BYTE*)(img->data), 3, img->width, img->height, (THFI_FacePos*)(&pos), (int*)nHat); |
| | | return ret; |
| | | } |
| | | |
| | | int face_check_quality_blur_glass(const int chan, const cIMAGE *img, const cFacePos &pos, int* nBlur,int* nGlasses){ |
| | | if(!img){ |
| | | printf("face check quality error, image or pos null\n"); |
| | | return -1; |
| | | } |
| | | |
| | | auto ret = THFQ_Check_BlurGlasses(chan, (BYTE*)(img->data), 3, img->width, img->height, (THFI_FacePos*)(&pos), (int*)nBlur, (int*)nGlasses); |
| | | return ret; |
| | | } |
| | | } |
New file |
| | |
| | | #ifndef _c_wrapper_face_quality_h_ |
| | | #define _c_wrapper_face_quality_h_ |
| | | |
| | | #include "../base.hpp" |
| | | |
| | | struct _cFacePos; |
| | | struct _cIMAGE; |
| | | struct _cThfqParam; |
| | | struct _cThfqResult; |
| | | |
| | | namespace csdk_wrap{ |
| | | int init_face_quality(const int tm); |
| | | void set_quality_params(const _cThfqParam* params); |
| | | int face_check_quality(const int chan, const cIMAGE *img, const cFacePos &pos, _cThfqResult *pResult); |
| | | int face_check_quality_brightness(const int chan, const cIMAGE *img, const cFacePos &pos, int *nBrightness); |
| | | int face_check_quality_occlusion(const int chan, const cIMAGE *img, const cFacePos &pos, int *nOcclusion); |
| | | int face_check_quality_hat(const int chan, const cIMAGE *img, const cFacePos &pos, int *nHat); |
| | | int face_check_quality_blur_glass(const int chan, const cIMAGE *img, const cFacePos &pos, int* nBlur,int* nGlasses); |
| | | } |
| | | #endif |
| | |
| | | PFacialData [8192]uint8 |
| | | NFaceID int64 |
| | | } |
| | | type CThfqParam struct { |
| | | Brightness_min int32 //0-100,太暗阈值,建议25.越小越可能把过暗的人脸当作正常人脸,此参数会影响THFQ_Result::brightness |
| | | Brightness_max int32 //0-100,太亮阈值,建议75.越大越可能把的过亮人脸当作正常人脸,此参数会影响THFQ_Result::brightness |
| | | } |
| | | type CThfqResult struct { |
| | | Brightness int32 //人脸亮度,只有3种可能的值:[-1->太暗,0->正常,1->太亮],亮度结果会受亮度阈值参数brightness_min和brightness_max影响 |
| | | Occlusion int32 //人脸遮挡度,范围值为0-100,越大表示人脸遮挡程度越高 |
| | | Hat int32 //带帽子,范围为0-100,越大表示越可能有佩戴帽子,建议判别阈值为50 |
| | | Blur int32 //人脸模糊度,范围值为0-100,越大表示图像越模糊,建议人脸模糊度判别阈值为70 |
| | | Glasses int32 //带眼镜,范围为0-100,越大表示越可能有戴眼镜,建议判别阈值为70 |
| | | } |
| | | |
| | | type CObjInfo struct { |
| | | RcObj CRECT |
| | | Typ int32 |
| | | Prob float32 |
| | | } |
| | | |
| | | //track yolo objs info |
| | | type CObjTrackInfo struct { |
| | | ObjInfo CObjInfo |
| | |
| | | #cgo LDFLAGS: -L/usr/local/cuda/lib64 -L${SRCDIR}/sdk/face/lib/gpu -L${SRCDIR}/sdk/darknet/lib |
| | | #cgo LDFLAGS: -L${SRCDIR}/sdk/plate/eparking/lib -L${SRCDIR}/sdk/plate/cloud/lib -L${SRCDIR}/sdk/plate/vehicle/lib |
| | | #cgo LDFLAGS: -Wl,-rpath,${SRCDIR}/sdk/face/lib/gpu:${SRCDIR}/sdk/darknet/lib:${SRCDIR}/sdk/plate/cloud/lib:${SRCDIR}/sdk/plate/vehicle/lib |
| | | #cgo LDFLAGS: -ldarknet -lTHFaceImage -lTHFeature -lTHFaceProperty -lTHFaceTracking -lcudart -lcublas -lcurand -lrt -ldl -lpthread -lthplateid -lLPRecognition |
| | | #cgo LDFLAGS: -ldarknet -lTHFaceImage -lTHFaceQuality -lTHFeature -lTHFaceProperty -lTHFaceTracking -lcudart -lcublas -lcurand -lrt -ldl -lpthread -lthplateid -lLPRecognition |
| | | #cgo LDFLAGS: -lVehicleTypeRecognition -lFeatureExtraction |
| | | #include <stdlib.h> |
| | | #include "csdk.h" |
| | |
| | | C.c_api_face_tracker_init(C.int(tm), C.int(gi), C.int(w), C.int(h), C.int(maxFaces), C.int(interval), C.int(sample)) |
| | | } |
| | | |
| | | // InitFaceQuality init face quality |
| | | func InitFaceQuality(tm int) { |
| | | |
| | | C.c_api_face_quality_init(C.int(tm)) |
| | | } |
| | | |
| | | // SetFaceQualityParams set face quality params |
| | | func SetFaceQualityParams(min, max int) { |
| | | |
| | | C.c_api_set_quality_params(C.int(min), C.int(max)) |
| | | } |
| | | |
| | | // ResizeFaceTracker init face tracker |
| | | func ResizeFaceTracker(ch, w, h int) int { |
| | | |
| | |
| | | return b |
| | | } |
| | | |
| | | |
| | | // FaceQuality face check quality |
| | | func FaceQuality(fpos CFacePos, img SDKImage, ch int) CThfqResult { |
| | | |
| | | data := img.Data |
| | | w := img.Width |
| | | h := img.Height |
| | | |
| | | pos := (*C.cFacePos)(unsafe.Pointer(&fpos)) |
| | | result := C.c_api_face_check_quality(pos, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h), C.int(ch)) |
| | | |
| | | return *((*CThfqResult)(unsafe.Pointer(&result))) |
| | | } |
| | | |
| | | // FaceQuality face check quality |
| | | func FaceQualityBrightness(fpos CFacePos, img SDKImage, ch int) int { |
| | | |
| | | data := img.Data |
| | | w := img.Width |
| | | h := img.Height |
| | | |
| | | var brightness, ret C.int |
| | | pos := (*C.cFacePos)(unsafe.Pointer(&fpos)) |
| | | |
| | | ret = C.c_api_face_check_quality_brightness(pos, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h), C.int(ch), &brightness) |
| | | if ret == -1 { |
| | | return -1 |
| | | } |
| | | |
| | | return int(brightness) |
| | | } |
| | | |
| | | // FaceQuality face check quality |
| | | func FaceQualityOcclusion(fpos CFacePos, img SDKImage, ch int) int { |
| | | |
| | | data := img.Data |
| | | w := img.Width |
| | | h := img.Height |
| | | |
| | | var occlusion, ret C.int |
| | | pos := (*C.cFacePos)(unsafe.Pointer(&fpos)) |
| | | |
| | | ret = C.c_api_face_check_quality_occlusion(pos, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h), C.int(ch), &occlusion) |
| | | if ret == -1 { |
| | | return -1 |
| | | } |
| | | |
| | | return int(occlusion) |
| | | } |
| | | |
| | | // FaceQuality face check quality |
| | | func FaceQualityHat(fpos CFacePos, img SDKImage, ch int) int { |
| | | |
| | | data := img.Data |
| | | w := img.Width |
| | | h := img.Height |
| | | |
| | | var hat, ret C.int |
| | | pos := (*C.cFacePos)(unsafe.Pointer(&fpos)) |
| | | |
| | | ret = C.c_api_face_check_quality_hat(pos, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h), C.int(ch), &hat) |
| | | if ret == -1 { |
| | | return -1 |
| | | } |
| | | |
| | | return int(hat) |
| | | } |
| | | |
| | | // FaceQuality face check quality |
| | | func FaceQualityBlurGlass(fpos CFacePos, img SDKImage, ch int) (int, int) { |
| | | |
| | | data := img.Data |
| | | w := img.Width |
| | | h := img.Height |
| | | |
| | | var blur, glass, ret C.int |
| | | pos := (*C.cFacePos)(unsafe.Pointer(&fpos)) |
| | | |
| | | ret = C.c_api_face_check_quality_blur_glass(pos, (*C.uchar)(unsafe.Pointer(&data[0])), C.int(w), C.int(h), C.int(ch), &blur, &glass) |
| | | if ret == -1 { |
| | | return -1, -1 |
| | | } |
| | | |
| | | return int(blur), int(glass) |
| | | } |
| | | |
| | | // FaceCompare face compare |
| | | func FaceCompare(feat1 []byte, feat2 []byte) float32 { |
| | | res := C.c_api_face_compare((*C.uchar)(unsafe.Pointer(&feat1[0])), (*C.uchar)(unsafe.Pointer(&feat2[0]))) |