【更新】完成人脸检测和特征提取模块
This commit is contained in:
66
app/main.cpp
66
app/main.cpp
@@ -2,26 +2,72 @@
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "util/TimeCount.h"
|
||||
#include "CenterFaceMnn.h"
|
||||
#include "MobileFaceFeatureMnn.h"
|
||||
|
||||
int32_t main(int32_t argc, char** argv) {
|
||||
CenterFaceMnn::GetInstance();
|
||||
void test_face_detect(std::string img_path) {
|
||||
cv::Mat img = cv::imread(img_path);
|
||||
std::vector<FaceInfo> faces;
|
||||
cv::Mat img = cv::imread("F:/33.jpg");
|
||||
int32_t count = 0;
|
||||
re_test:
|
||||
count++;
|
||||
{
|
||||
USE_TIME t(USE_TIME_US, "face_detect: ");
|
||||
CenterFaceMnn::GetInstance()->Detect(img, faces, 1);
|
||||
}
|
||||
if (count < 10) {
|
||||
goto re_test;
|
||||
}
|
||||
|
||||
for(auto& face : faces) {
|
||||
cv::rectangle(img, cv::Rect(face.x1, face.y1, face.x2 - face.x1, face.y2 - face.y1), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(img, cv::Rect(face.x1, face.y1, FACE_BOX_WIDTH(face), FACE_BOX_HEIGHT(face)), cv::Scalar(0, 0, 255), 2);
|
||||
}
|
||||
cv::imshow("test", img);
|
||||
cv::waitKey(0);
|
||||
}
|
||||
|
||||
void test_face_compare(std::string img1, std::string img2) {
|
||||
cv::Mat img1_ = cv::imread(img1);
|
||||
cv::Mat img2_ = cv::imread(img2);
|
||||
std::vector<FaceInfo> faces1;
|
||||
std::vector<FaceInfo> faces2;
|
||||
CenterFaceMnn::GetInstance()->Detect(img1_, faces1, 1);
|
||||
CenterFaceMnn::GetInstance()->Detect(img2_, faces2, 1);
|
||||
|
||||
if (faces1.size() == 0 || faces2.size() == 0) {
|
||||
std::cout << faces1.size() << " == " << faces2.size() << std::endl;
|
||||
return;
|
||||
}
|
||||
float feature1[512];
|
||||
float feature2[512];
|
||||
float score = 0.f;
|
||||
{
|
||||
USE_TIME t(USE_TIME_US, "GetFaceFeature img1 time: ");
|
||||
MobileFaceFeatureMnn::GetInstance()->GetFaceFeature(img1_, faces1[0].landmarks, feature1);
|
||||
}
|
||||
|
||||
{
|
||||
USE_TIME t(USE_TIME_US, "GetFaceFeature img2 time: ");
|
||||
MobileFaceFeatureMnn::GetInstance()->GetFaceFeature(img2_, faces2[0].landmarks, feature2);
|
||||
}
|
||||
|
||||
{
|
||||
USE_TIME t(USE_TIME_US, "DeepCamFaceFeatureCompare time: ");
|
||||
MobileFaceFeatureMnn::GetInstance()->MobileFaceFeatureCompare(feature1, feature2, score);
|
||||
}
|
||||
|
||||
std::cout << "score: " << score << std::endl;
|
||||
|
||||
for(auto& face : faces2) {
|
||||
cv::rectangle(img2_, cv::Rect(face.x1, face.y1, FACE_BOX_WIDTH(face), FACE_BOX_HEIGHT(face)), cv::Scalar(0, 0, 255), 2);
|
||||
}
|
||||
for(auto& face : faces1) {
|
||||
cv::rectangle(img1_, cv::Rect(face.x1, face.y1, FACE_BOX_WIDTH(face), FACE_BOX_HEIGHT(face)), cv::Scalar(0, 0, 255), 2);
|
||||
}
|
||||
|
||||
cv::imshow("img1", img1_);
|
||||
cv::imshow("img2", img2_);
|
||||
cv::waitKey(0);
|
||||
}
|
||||
int32_t main(int32_t argc, char** argv) {
|
||||
CenterFaceMnn::GetInstance();
|
||||
MobileFaceFeatureMnn::GetInstance();
|
||||
// test_face_detect("E:/dd.jpg");
|
||||
|
||||
test_face_compare("F:/1.jpg", "E:\\6.jpg");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user