首页 > 解决方案 > 通过 dlib 进行人脸识别太慢

问题描述

我正在使用这个 OpenCV 示例进行人脸检测。然后我使用这个 dlib 示例进行人脸识别。第一步是使用 OpenCV 检测人脸并将检测到的矩形保存在 jpg 中。我也对第二张图片做同样的事情。之后,我将这些面孔加载到 dlib 模型中,并尝试识别是否存在同一个人。一切正常,甚至是正确的,但在我的 i7 8550U 和 16gb 内存上识别人脸大约需要 1 分 30 秒。所以在我看来,我做错了。有一些代码我如何尝试比较面孔:

anet_type dlibNet;
deserialize("dlib_face_recognition_resnet_model_v1.dat") >> dlibNet;
...
cv::Mat img1 = cv::imread("img1.jpg");
cv::Mat img2 = cv::imread("img2.jpg");
cv::resize(img1, img1, cv::Size(150, 150));
cv::resize(img2, img2, cv::Size(150, 150));

cv_image<bgr_pixel> image1(img1);
matrix<rgb_pixel> matr1;
assign_image(matr1, image1);

cv_image<bgr_pixel> image2(img2);
matrix<rgb_pixel> matr2;
assign_image(matr2, image2);

std::vector<matrix<rgb_pixel>> faces;
faces.push_back(matr1);
faces.push_back(matr2);
std::vector<matrix<float, 0, 1>> face_descriptors = dlibNet(faces);
if (length(face_descriptors[0] - face_descriptors[1]) < 0.6)
        cout << "Same person" << endl;
else
        cout << "Fail. Different people" << endl; 

标签: c++opencvdlib

解决方案


推荐阅读