该案例的思路:
首先用老师提供的gitee仓库下载文件,因为有墙原本的脚本没办法用的。
下载->models->facedector
接着就是我们的demo演示了

void QuickDemo::face_dected_demo()
{
	VideoCapture capture("E:/data/vtest.avi");
	Mat frame;
	std::string root_dir = "D:/opencv/sources/samples/dnn/face_detector/";
	dnn::Net net=dnn::readNetFromTensorflow(root_dir+"opencv_face_detector_uint8.pb",root_dir+"opencv_face_detector.pbtxt");//读取模型,读取配置文件
	while (1)
	{
		capture.read(frame);
		if (frame.empty())
		{
			break;
		}
		Mat blob = dnn::blobFromImages(frame,1.0,Size(100,100),Scalar(104,177,123),false,false);
		net.setInput(blob);//NCHW
		Mat probs = net.forward();//多少张图形,image.index
		Mat dectionRes(probs.size[2], probs.size[3],CV_32F,probs.ptr<float>());
		//解析该结果
		for (int i = 0; i < dectionRes.rows; i++)
		{
			float confidence = dectionRes.at<float>(i, 2);
			if (confidence > 0.5)
			{
				int x1 = static_cast<int>(dectionRes.at<float>(i,3)*frame.cols);
				int y1= static_cast<int>(dectionRes.at<float>(i, 4) * frame.rows);
				int x2=static_cast<int>(dectionRes.at<float>(i, 5) * frame.cols);
				int y2=static_cast<int>(dectionRes.at<float>(i, 6) * frame.rows);
				Rect box(x1, y1, (x2 - x1), (y2 - y1));
				rectangle(frame, box, Scalar(0, 0, 255), 2, LINE_AA, 0);
			}
		}
		imshow("人脸检测显示", frame);
		char c = waitKey(10);
		if (c == 27)
		{
			break;
		}

	}
}
GitHub 加速计划 / opencv31 / opencv
77.38 K
55.71 K
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:2 个月前 )
c3747a68 Added Universal Windows Package build to CI. 5 天前
9b635da5 - 5 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐