【OpenCV】Dlib人脸关键点检测顺序

承接图像分类、检测、分割、生成相关项目,私信。

dlib19.2 只可以使用VS2015update3进行cmake,不然会提示你c++11特性不能够支持,导致编译不通过。

  • 人脸关键点检测关键代码

最好参考一下这篇博客Opencv与dlib联合进行人脸关键点检测与识别

Mat ProcessFace::DrawDetectedFace(){
	
	Mat imgDrawFace = srcImage;//这个变量是指向待检测人脸的图片


	for (int i = 0; i < (detectedFaceData ? *detectedFaceData : 0); i++)
	{

		short * p = ((short*)(detectedFaceData + 1)) + 6 * i;
		Rect opencvRect(p[0], p[1], p[2], p[3]);
		int x = p[0];
		int y = p[1];
		int w = p[2];
		int h = p[3];
		int neighbors = p[4];

		printf("face_rect=[%d, %d, %d, %d], neighbors=%d\n", x, y, w, h, neighbors);
		Point left(x, y);
		Point right(x + w, y + h);
		cv::rectangle(imgDrawFace, left, right, Scalar(230, 255, 0), 4);
		dlib::rectangle dlibRect((long)opencvRect.tl().x, (long)opencvRect.tl().y, (long)opencvRect.br().x - 1, (long)opencvRect.br().y - 1);
		dlib::full_object_detection shape = sp(dlib::cv_image<uchar>(srcGrayImage), dlibRect);
		
		for (int i = 0; i<shape.num_parts(); i++)
		{
			shape.part(0).x();
			//point pt = shape.part(i);
			int x = shape.part(i).x();
			int y = shape.part(i).y();
			
			char str[3];
			itoa(i, str, 10);
			line(imgDrawFace, Point(shape.part(i).x(), shape.part(i).y()), Point(shape.part(i).x(), shape.part(i).y()), Scalar(0, i*3, 255), 2);
			putText(imgDrawFace, str, Point(shape.part(i).x(), shape.part(i).y()), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 255, 0), 2);
		}
		//std::vector shapes;
		//shapes.push_back(shape);//把点保存在了shape中
		//dlib::array>  face_chips;
		//extract_image_chips(dlib::cv_image(srcGrayImage), get_face_chip_details(shapes), face_chips);
		//imgDrawFace = dlib::toMat(face_chips[0]);
		//cvtColor(imgDrawFace, imgDrawFace, CV_BGR2GRAY);

	}
	return imgDrawFace;
}
  • 人脸68个关键点分布情况

【OpenCV】Dlib人脸关键点检测顺序_第1张图片

你可能感兴趣的:(图像识别,OpenCV)