opencv结合dlib进行人脸特征点的检测

#include   
#include   
#include   
#include   
#include   
#include   
  
using namespace dlib;  
using namespace std;  
  
int main()  
{  
    try  
    {  

        printf("加载人脸检测和姿态估计模型");
        frontal_face_detector detector = get_frontal_face_detector();  
        shape_predictor pose_model;  
		printf("读取人脸特征点的训练资料");
        deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;  
            cv::Mat temp;   
			temp=cv::imread("1.jpg"); 
            cv_image cimg(temp);  
            // 检测人脸   
			printf("\n检测人脸");
            std::vector faces = detector(cimg);  
            // 找出每张脸的状态。 
            std::vector shapes; 
			printf("\n存储人脸点");
            for (unsigned long i = 0; i < faces.size(); ++i)  
                shapes.push_back(pose_model(cimg, faces[i]));  
      
            if (!shapes.empty()) {  
				printf("\n画点");
                for (int i = 0; i < 68; i++) {  
                    circle(temp, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 3, cv::Scalar(0, 0, 255), -1);  
                    //  shapes[0].part(i).x();//68个  
                }  
            }  
			printf("\n展示特征点");
            imshow("Dlib特征点", temp);  
  
			cvWaitKey(6000);
    }  
    catch (serialization_error& e)  
    {  
        cout << "You need dlib's default face landmarking model file to run this example." << endl;  
        cout << "You can get it from the following URL: " << endl;  
        cout << "   http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;  
        cout << endl << e.what() << endl;  
    }  
    catch (exception& e)  
    {  
        cout << e.what() << endl;  
    }  
}  

速度太慢了,需要GPU加速才行

还有一种方法,详细请见链接

毫秒级人脸识别


你可能感兴趣的:(opencv)