赞
踩
该案例的思路:
首先用老师提供的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; } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。