人脸识别引擎SeetaFaceEngine中Alignment模块使用的测试代码
生活随笔
收集整理的這篇文章主要介紹了
人脸识别引擎SeetaFaceEngine中Alignment模块使用的测试代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
人臉識別引擎SeetaFaceEngine中Alignment模塊用于檢測人臉關鍵點,包括5個點,兩個眼的中心、鼻尖、兩個嘴角,以下是測試代碼:
int test_alignment()
{std::vector<std::string> images{ "1.jpg", "2.jpg", "3.jpg", "4.jpeg", "5.jpeg", "6.jpg", "7.jpg", "8.jpg", "9.jpg", "10.jpg","11.jpeg", "12.jpg", "13.jpeg", "14.jpg", "15.jpeg", "16.jpg", "17.jpg", "18.jpg", "19.jpg", "20.jpg" };std::vector<int> count_faces{ 1, 2, 6, 0, 1, 1, 1, 2, 1, 1,1, 1, 1, 1, 1, 1, 1, 0, 8, 2 };const std::string path_images{ "E:/GitCode/Face_Test/testdata/" };seeta::FaceDetection detector("E:/GitCode/Face_Test/src/SeetaFaceEngine/FaceDetection/model/seeta_fd_frontal_v1.0.bin");detector.SetMinFaceSize(20);detector.SetMaxFaceSize(200);detector.SetScoreThresh(2.f);detector.SetImagePyramidScaleFactor(0.8f);detector.SetWindowStep(4, 4);seeta::FaceAlignment point_detector("E:/GitCode/Face_Test/src/SeetaFaceEngine/FaceAlignment/model/seeta_fa_v1.1.bin");for (auto name : images) {fprintf(stderr, "start detect image: %s\n", name.c_str());cv::Mat src_ = cv::imread(path_images + name, 1);if (src_.empty()) {fprintf(stderr, "read image error: %s\n", name.c_str());continue;}cv::Mat src;cv::cvtColor(src_, src, CV_BGR2GRAY);seeta::ImageData img_data;img_data.data = src.data;img_data.width = src.cols;img_data.height = src.rows;img_data.num_channels = 1;std::vector<seeta::FaceInfo> faces = detector.Detect(img_data);for (auto face : faces) {// Detect 5 facial landmarks: two eye centers, nose tip and two mouth cornersseeta::FacialLandmark points[5];point_detector.PointDetectLandmarks(img_data, face, points);cv::rectangle(src_, cv::Rect(face.bbox.x, face.bbox.y,face.bbox.width, face.bbox.height), cv::Scalar(0, 255, 0), 2);for (auto point : points) {cv::circle(src_, cv::Point(point.x, point.y), 2, cv::Scalar(0, 0, 255), 2);}}std::string save_result = path_images + "_" + name;cv::imwrite(save_result, src_);}int width = 200;int height = 200;cv::Mat dst(height * 5, width * 4, CV_8UC3);for (int i = 0; i < images.size(); i++) {std::string input_image = path_images + "_" + images[i];cv::Mat src = cv::imread(input_image, 1);if (src.empty()) {fprintf(stderr, "read image error: %s\n", images[i].c_str());return -1;}cv::resize(src, src, cv::Size(width, height), 0, 0, 4);int x = (i * width) % (width * 4);int y = (i / 4) * height;cv::Mat part = dst(cv::Rect(x, y, width, height));src.copyTo(part);}std::string output_image = path_images + "result.png";cv::imwrite(output_image, dst);return 0;
}
從網上找了20張圖像,用于測試此模塊,測試結果如下:
GitHub:https://github.com/fengbingchun/Face_Test
總結
以上是生活随笔為你收集整理的人脸识别引擎SeetaFaceEngine中Alignment模块使用的测试代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使GDAL库支持中文路径或中文文件名的处
- 下一篇: 人脸识别引擎SeetaFaceEngin