Haar-Cascade分级机的精度调整

问题描述 投票:2回答:1

我正在使用Haar-Cascade分类器来检测面部。

我目前面临以下功能的一些问题:

void ImageManager::detectAndDisplay(Mat frame, CascadeClassifier face_cascade){


    string window_name = "Capture - Face detection";
    string filename;

    std::vector<Rect> faces;
    std::vector<Rect> eyes;
    Mat frame_gray;
    Mat crop;
    Mat res;
    Mat gray;
    string text;
    stringstream sstm;


    cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
    equalizeHist(frame_gray, frame_gray);

    // Detect faces
    face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30));

    // Set Region of Interest
    cv::Rect roi_b;
    cv::Rect roi_c;

    size_t ic = 0; // ic is index of current element


    for (ic = 0; ic < faces.size(); ic++) // Iterate through all current elements (detected faces)  
    {

        roi_c.x = faces[ic].x;
        roi_c.y = faces[ic].y;
        roi_c.width = (faces[ic].width);
        roi_c.height = (faces[ic].height);



        crop = frame_gray(roi_c);

        faces_img.push_back(crop);

        rectangle(frame, Point(roi_c.x, roi_c.y), Point(roi_c.x + roi_c.width, roi_c.y + roi_c.height), Scalar(0,0,255), 2);


    }

    imshow("test", frame);
    waitKey(0);

    cout << faces_img.size();


}

框架是我正在尝试扫描的照片。

face_cascade是分类器。

opencv face-detection haar-classifier
1个回答
8
投票

在内部,CascadeClassifier会执行多次检测,并对这些检测进行分组。

minNeighbours(在detectMultiScale调用中)是大约相同位置的检测数量,无法计入有效检测,因此从当前的2增加到大约5个左右,直到您开始错过正数。

© www.soinside.com 2019 - 2024. All rights reserved.