多脸检测 [英] Multiple Face Detection

查看:134
本文介绍了多脸检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OpenCV(C ++)中有一个代码,该代码使用"haarcascade_mcs_upperbody.xml"来检测上身. 它检测单个上身.如何使它检测多个上半身. 我认为CV_HAAR_FIND_BIGGEST_OBJECT仅检测最大的对象.但是我不知道如何解决这个问题

I have a code in OpenCV (in C++) which uses "haarcascade_mcs_upperbody.xml" to detect upper body. It detects single upper body. How can I make it detect multiple upper bodies. I think CV_HAAR_FIND_BIGGEST_OBJECT is detecting only the biggest object. But I am not knowing how to solve this issue

代码如下:

int main(int argc, const char** argv)
{
CascadeClassifier body_cascade;
body_cascade.load("haarcascade_mcs_upperbody.xml");

VideoCapture captureDevice;
captureDevice.open(0);

Mat captureFrame;
Mat grayscaleFrame;

namedWindow("outputCapture", 1);

//create a loop to capture and find faces
while(true)
{
    //capture a new image frame
    captureDevice>>captureFrame;

    //convert captured image to gray scale and equalize
    cvtColor(captureFrame, grayscaleFrame, CV_BGR2GRAY);
    equalizeHist(grayscaleFrame, grayscaleFrame);

    //create a vector array to store the face found
    std::vector<Rect> bodies;

    //find faces and store them in the vector array
    body_cascade.detectMultiScale(grayscaleFrame, faces, 1.1, 3,                                                                                                                                     
    CV_HAAR_FIND_BIGGEST_OBJECT|CV_HAAR_SCALE_IMAGE, Size(30,30));    
    //draw a rectangle for all found faces in the vector array on the original image
    for(int i = 0; i < faces.size(); i++)
    {
        Point pt1(bodies[i].x + bodies[i].width, bodies[i].y + bodies[i].height);
        Point pt2(bodies[i].x, bodies[i].y);

        rectangle(captureFrame, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);
    }

    //print the output
    imshow("outputCapture", captureFrame);

    //pause for 33ms
    waitKey(33);
}

return 0;
}

推荐答案

您的代码似乎存在一些不一致之处,因为face_cascade并未在任何地方定义,但我认为其类型为CascadeClassifier.
detectMultiScale将所有检测到的对象存储在faces向量中.您确定它仅包含一个对象吗?
尝试删除CV_HAAR_FIND_BIGGEST_OBJECT标志,因为您希望检测所有对象,而不仅仅是最大的对象.
另外,请确保正确设置minSizemaxSize参数(请参见

It seems there is some inconsistency in your code, since face_cascade is not defined anywhere, but I assume its type is CascadeClassifier.
detectMultiScale stores all detected objects in the faces vector. Are you sure it contains only one object?
Try removing the CV_HAAR_FIND_BIGGEST_OBJECT flag, because you want all objects to be detected, and not only the biggest one.
Also, make sure you set the minSize and maxSize parameters correctly (see documentation), since those parameters determine the minimal and maximal detectable object sizes.

这篇关于多脸检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆