OpenCV使用级联分类器实现猫脸检测

一、概述

  ps:步骤同上一篇https://www.cnblogs.com/tony-yang-flutter/p/16121237.html

二、代码示例

 String catFile = "/usr/local/share/opencv4/haarcascades/haarcascade_frontalcatface.xml";
    CascadeClassifier cat_face;
    if(!cat_face.load(catFile)){
        qDebug()<<"猫脸特征数据加载失败";
        return;
    }

    Mat src = imread(filePath);
    if(src.empty()){
        qDebug()<<"输入图片为空";
        return;
    }
    Mat gray;
    vector<Rect> faces;
    cvtColor(src,gray,COLOR_BGR2GRAY);
    equalizeHist(gray,gray);

    cat_face.detectMultiScale(gray,faces,1.1,3,0,Size(100,100));
    for(size_t i=0;i<faces.size();i++){
        rectangle(src,faces[i],Scalar(0,0,255),3,LINE_8);
    }
    imshow("src",src);

 

三、演示图片

 

posted on 2022-04-09 11:40  飘杨......  阅读(13)  评论(0编辑  收藏  举报