detectionMap函数的使用 用opencv下深度学习模块进行人脸识别

本文展示了如何利用OpenCV的dnn::Net接口读取Tensorflow模型,进行人脸检测。通过读取视频,将图像转换为Blob输入网络,获取预测结果,解析检测矩阵并根据置信度阈值绘制人脸矩形。代码中使用了opencv_face_detector_uint8.pb和opencv_face_detector.pbtxt文件。
摘要由CSDN通过智能技术生成

void QuickDemo::face_detection_demo() {
    std::string root_dir = "D:/opencv-4.4.0/opencv/sources/samples/dnn/face_detector/";

//读取模型+配置文件
    dnn::Net net = dnn::readNetFromTensorflow(root_dir+ "opencv_face_detector_uint8.pb", root_dir+"opencv_face_detector.pbtxt");
    VideoCapture capture("D:/images/video/example_dsh.mp4");
    Mat frame;
    while (true) {
        capture.read(frame);
        if (frame.empty()) {
            break;
        }
        Mat blob = dnn::blobFromImage(frame, 1.0, Size(300, 300), Scalar(104, 177, 123), false, false);
        net.setInput(blob);// NCHW
        Mat probs = net.forward(); // 
        Mat detectionMat(probs.size[2], probs.size[3], CV_32F, probs.ptr<float>());
        // 解析结果
        for (int i = 0; i < detectionMat.rows; i++) { <

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值