feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
103
3rdparty/opencv-4.5.4/samples/dnn/face_match.cpp
vendored
Normal file
103
3rdparty/opencv-4.5.4/samples/dnn/face_match.cpp
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "opencv2/dnn.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "opencv2/objdetect.hpp"
|
||||
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
if (argc != 5)
|
||||
{
|
||||
std::cerr << "Usage " << argv[0] << ": "
|
||||
<< "<det_onnx_path> "
|
||||
<< "<reg_onnx_path> "
|
||||
<< "<image1>"
|
||||
<< "<image2>\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
String det_onnx_path = argv[1];
|
||||
String reg_onnx_path = argv[2];
|
||||
String image1_path = argv[3];
|
||||
String image2_path = argv[4];
|
||||
std::cout<<image1_path<<" "<<image2_path<<std::endl;
|
||||
Mat image1 = imread(image1_path);
|
||||
Mat image2 = imread(image2_path);
|
||||
|
||||
float score_thresh = 0.9f;
|
||||
float nms_thresh = 0.3f;
|
||||
double cosine_similar_thresh = 0.363;
|
||||
double l2norm_similar_thresh = 1.128;
|
||||
int top_k = 5000;
|
||||
|
||||
// Initialize FaceDetector
|
||||
Ptr<FaceDetectorYN> faceDetector;
|
||||
|
||||
faceDetector = FaceDetectorYN::create(det_onnx_path, "", image1.size(), score_thresh, nms_thresh, top_k);
|
||||
Mat faces_1;
|
||||
faceDetector->detect(image1, faces_1);
|
||||
if (faces_1.rows < 1)
|
||||
{
|
||||
std::cerr << "Cannot find a face in " << image1_path << "\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
faceDetector = FaceDetectorYN::create(det_onnx_path, "", image2.size(), score_thresh, nms_thresh, top_k);
|
||||
Mat faces_2;
|
||||
faceDetector->detect(image2, faces_2);
|
||||
if (faces_2.rows < 1)
|
||||
{
|
||||
std::cerr << "Cannot find a face in " << image2_path << "\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize FaceRecognizerSF
|
||||
Ptr<FaceRecognizerSF> faceRecognizer = FaceRecognizerSF::create(reg_onnx_path, "");
|
||||
|
||||
|
||||
Mat aligned_face1, aligned_face2;
|
||||
faceRecognizer->alignCrop(image1, faces_1.row(0), aligned_face1);
|
||||
faceRecognizer->alignCrop(image2, faces_2.row(0), aligned_face2);
|
||||
|
||||
Mat feature1, feature2;
|
||||
faceRecognizer->feature(aligned_face1, feature1);
|
||||
feature1 = feature1.clone();
|
||||
faceRecognizer->feature(aligned_face2, feature2);
|
||||
feature2 = feature2.clone();
|
||||
|
||||
double cos_score = faceRecognizer->match(feature1, feature2, FaceRecognizerSF::DisType::FR_COSINE);
|
||||
double L2_score = faceRecognizer->match(feature1, feature2, FaceRecognizerSF::DisType::FR_NORM_L2);
|
||||
|
||||
if(cos_score >= cosine_similar_thresh)
|
||||
{
|
||||
std::cout << "They have the same identity;";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "They have different identities;";
|
||||
}
|
||||
std::cout << " Cosine Similarity: " << cos_score << ", threshold: " << cosine_similar_thresh << ". (higher value means higher similarity, max 1.0)\n";
|
||||
|
||||
if(L2_score <= l2norm_similar_thresh)
|
||||
{
|
||||
std::cout << "They have the same identity;";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "They have different identities.";
|
||||
}
|
||||
std::cout << " NormL2 Distance: " << L2_score << ", threshold: " << l2norm_similar_thresh << ". (lower value means higher similarity, min 0.0)\n";
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user