// sdk_test_face_compare.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "Inc/DeepCamFaceApi.h" #include "Inc/TimeCount.h" #include #include namespace fs = std::filesystem; bool GetFaceFeature(cv::Mat& img, float* feature) { std::vector face_infos; { USE_TIME t("FaceDetect ==> "); DeepCamFaceDetect(img, face_infos); } if (face_infos.size() > 0) { USE_TIME t("Get Feature ==> "); DeepCamGetFaceFeature(img, face_infos[0].landmarks, feature); for (int i = 0; i < 5; i++) { cv::circle(img, cv::Point(face_infos[0].landmarks[i * 2], face_infos[0].landmarks[i * 2 + 1]), 1, cv::Scalar(0, 0, 255), 2); } cv::rectangle(img, cv::Rect(face_infos[0].x1, face_infos[0].y1, face_infos[0].GetWidth(), face_infos[0].GetHeight()), cv::Scalar(0, 255, 0), 2); cv::imshow("Face Compare", img); cv::waitKey(1); return true; } else {//未检测到人脸 return false; } } bool FindAllFilesInPath(std::string strPath, std::vector & fileList, std::vector & suffixFilters) { fs::path str(strPath); if (!exists(str)) //必须先检测目录是否存在才能使用文件入口. return false; std::regex stuff(".*\\.(exe|zip)");//包含字母z的所有jpg或png图片 for (auto&fe : fs::directory_iterator(str)) { auto fp = fe.path(); //std::wcout << fp.filename().wstring() << std::endl; auto temp = fp.filename(); if (std::regex_match(temp.string(), stuff)) { std::cout << temp << std::endl; } //replace_extension替换扩展名 //stem去掉扩展名 } return 0; } int main() { std::string path = R"(D:\Tools\)"; std::vector files; std::vector stuff; FindAllFilesInPath(path, files, stuff); float feature1[512] = { 0 }; GetFaceFeature(cv::imread("./1.jpg"), feature1); cv::VideoCapture camera1(1); if (!camera1.isOpened()) return 1; while (true) { cv::Mat img; camera1 >> img; if (!img.empty()) { float feature2[512] = { 0 }; float score = 0.f; if (GetFaceFeature(img, feature2)) { DeepCamFaceFeatureCompare(feature1, feature2, score); } std::cout << "cmp ==> " << score << std::endl; } } return 0; }