Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roadmap: face detector yn face recognizer sf #1232

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
run: |
mkdir -p ${GITHUB_WORKSPACE}/testdata
curl -sL https://github.com/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ${GITHUB_WORKSPACE}/testdata/googlenet-9.onnx
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx > ${GITHUB_WORKSPACE}/testdata/face_recognition_sface_2021dec.onnx
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx > ${GITHUB_WORKSPACE}/testdata/face_detection_yunet_2023mar.onnx
- name: Run main tests
run: xvfb-run -a --error-file /var/log/xvfb_error.log --server-args="-screen 0 1024x768x24 +extension RANDR" go test -v -coverprofile=/tmp/coverage.out -count=1 -tags matprofile .
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ jobs:
run: |
mkdir -p ${GITHUB_WORKSPACE}/testdata
curl -sL https://github.com/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ${GITHUB_WORKSPACE}/testdata/googlenet-9.onnx
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx > ${GITHUB_WORKSPACE}/testdata/face_recognition_sface_2021dec.onnx
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx > ${GITHUB_WORKSPACE}/testdata/face_detection_yunet_2023mar.onnx
- name: Run main tests
run: go test -v -tags matprofile .
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ jobs:
- name: Install ONNX test model
run: |
curl -sL https://github.com/onnx/models/raw/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx > ./testdata/googlenet-9.onnx
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_recognition_sface/face_recognition_sface_2021dec.onnx > ./testdata/face_recognition_sface_2021dec.onnx
curl -sL https://github.com/opencv/opencv_zoo/raw/refs/heads/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx > ./testdata/face_detection_yunet_2023mar.onnx
- name: Install GOTURN test model
shell: bash
run: |
Expand Down
6 changes: 3 additions & 3 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ Your pull requests will be greatly appreciated!
- [ ] [detectBoard](https://docs.opencv.org/4.x/d9/df5/classcv_1_1aruco_1_1CharucoDetector.html#aacbea601612a3a0feaa45ebb7fb255fd)
- [ ] [detectDiamonds](https://docs.opencv.org/4.x/d9/df5/classcv_1_1aruco_1_1CharucoDetector.html#a50342803f68deb1e6b0b79f61d4b1a73)

- [ ] Face Detection
- [ ] [FaceDetectorYN](https://docs.opencv.org/4.x/df/d20/classcv_1_1FaceDetectorYN.html)
- [ ] [FaceRecognizerSF](https://docs.opencv.org/4.x/da/d09/classcv_1_1FaceRecognizerSF.html)
- [X] Face Detection
- [X] [FaceDetectorYN](https://docs.opencv.org/4.x/df/d20/classcv_1_1FaceDetectorYN.html)
- [X] [FaceRecognizerSF](https://docs.opencv.org/4.x/da/d09/classcv_1_1FaceRecognizerSF.html)

- [X] **dnn. Deep Neural Network module**
- [ ] ml. Machine Learning
Expand Down
136 changes: 136 additions & 0 deletions objdetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,140 @@ bool QRCodeDetector_DetectAndDecodeMulti(QRCodeDetector qr, Mat input, CStrings*
decoded->length = decodedCodes.size();
decoded->strs = strs;
return res;
}

FaceDetectorYN FaceDetectorYN_Create(const char* model, const char* config, Size size) {
cv::String smodel = cv::String(model);
cv::String sconfig = cv::String(config);
cv::Size ssize = cv::Size(size.width, size.height);

return new cv::Ptr<cv::FaceDetectorYN>(cv::FaceDetectorYN::create(smodel, sconfig, ssize));
}

FaceDetectorYN FaceDetectorYN_Create_WithParams(const char* model, const char* config, Size size, float score_threshold, float nms_threshold, int top_k, int backend_id, int target_id) {
cv::String smodel = cv::String(model);
cv::String sconfig = cv::String(config);
cv::Size ssize = cv::Size(size.width, size.height);

return new cv::Ptr<cv::FaceDetectorYN>(cv::FaceDetectorYN::create(smodel, sconfig, ssize, score_threshold, nms_threshold, top_k, backend_id, target_id));
}

FaceDetectorYN FaceDetectorYN_Create_FromBytes(const char* framework, void* bufferModel, int model_size, void* bufferConfig, int config_size, Size size) {
cv::String sframework = cv::String(framework);
cv::Size ssize = cv::Size(size.width, size.height);

std::vector<uchar> bufferModelV;
std::vector<uchar> bufferConfigV;

uchar* bmv = (uchar*)bufferModel;
uchar* bcv = (uchar*)bufferConfig;


for(int i = 0; i < model_size; i ++) {
bufferModelV.push_back(bmv[i]);
}
for(int i = 0; i < config_size; i ++) {
bufferConfigV.push_back(bcv[i]);
}

return new cv::Ptr<cv::FaceDetectorYN>(cv::FaceDetectorYN::create(sframework, bufferModelV, bufferConfigV, ssize));
}

FaceDetectorYN FaceDetectorYN_Create_FromBytes_WithParams(const char* framework, void* bufferModel, int model_size, void* bufferConfig, int config_size, Size size, float score_threshold, float nms_threshold, int top_k, int backend_id, int target_id) {
cv::String sframework = cv::String(framework);
cv::Size ssize = cv::Size(size.width, size.height);

std::vector<uchar> bufferModelV;
std::vector<uchar> bufferConfigV;

uchar* bmv = (uchar*)bufferModel;
uchar* bcv = (uchar*)bufferConfig;


for(int i = 0; i < model_size; i ++) {
bufferModelV.push_back(bmv[i]);
}
for(int i = 0; i < config_size; i ++) {
bufferConfigV.push_back(bcv[i]);
}

return new cv::Ptr<cv::FaceDetectorYN>(cv::FaceDetectorYN::create(sframework, bufferModelV, bufferConfigV, ssize, score_threshold, nms_threshold, top_k, backend_id, target_id));
}

void FaceDetectorYN_Close(FaceDetectorYN fd) {
delete fd;
}

int FaceDetectorYN_Detect(FaceDetectorYN fd, Mat image, Mat faces) {
return (*fd)->detect(*image, *faces);
}

Size FaceDetectorYN_GetInputSize(FaceDetectorYN fd) {
Size sz;

cv::Size cvsz = (*fd)->getInputSize();

sz.width = cvsz.width;
sz.height = cvsz.height;

return sz;
}

float FaceDetectorYN_GetNMSThreshold(FaceDetectorYN fd) {
return (*fd)->getNMSThreshold();
}

float FaceDetectorYN_GetScoreThreshold(FaceDetectorYN fd) {
return (*fd)->getScoreThreshold();
}

int FaceDetectorYN_GetTopK(FaceDetectorYN fd) {
return (*fd)->getTopK();
}

void FaceDetectorYN_SetInputSize(FaceDetectorYN fd, Size input_size){
cv::Size isz(input_size.width, input_size.height);
(*fd)->setInputSize(isz);
}

void FaceDetectorYN_SetNMSThreshold(FaceDetectorYN fd, float nms_threshold){
(*fd)->setNMSThreshold(nms_threshold);
}

void FaceDetectorYN_SetScoreThreshold(FaceDetectorYN fd, float score_threshold){
(*fd)->setScoreThreshold(score_threshold);
}

void FaceDetectorYN_SetTopK(FaceDetectorYN fd, int top_k){
(*fd)->setTopK(top_k);
}

FaceRecognizerSF FaceRecognizerSF_Create(const char* model, const char* config) {
return FaceRecognizerSF_Create_WithParams(model, config, 0, 0);
}

FaceRecognizerSF FaceRecognizerSF_Create_WithParams(const char* model, const char* config, int backend_id, int target_id) {
cv::Ptr<cv::FaceRecognizerSF>* p = new cv::Ptr<cv::FaceRecognizerSF>(cv::FaceRecognizerSF::create(model, config, backend_id, target_id));
return p;
}

void FaceRecognizerSF_Close(FaceRecognizerSF fr) {
delete fr;
}

void FaceRecognizerSF_AlignCrop(FaceRecognizerSF fr, Mat src_img, Mat face_box, Mat aligned_img) {
(*fr)->alignCrop(*src_img, *face_box, *aligned_img);
}

void FaceRecognizerSF_Feature(FaceRecognizerSF fr, Mat aligned_img, Mat face_feature) {
(*fr)->feature(*aligned_img, *face_feature);
}

float FaceRecognizerSF_Match(FaceRecognizerSF fr, Mat face_feature1, Mat face_feature2) {
return FaceRecognizerSF_Match_WithParams(fr, face_feature1, face_feature2, 0);
}

float FaceRecognizerSF_Match_WithParams(FaceRecognizerSF fr, Mat face_feature1, Mat face_feature2, int dis_type) {
double rv = (*fr)->match(*face_feature1, *face_feature2, dis_type);
return (float)rv;
}
Loading
Loading