简体   繁体   English

为什么detectMultiScale仅在人脸靠近框架中心时才检测人脸?

[英]Why does detectMultiScale detect faces only when they are close to the centre of the frame?

I am trying a very simple program to detect faces in a webcam feed. 我正在尝试一个非常简单的程序来检测网络摄像头中的人脸。 I am noticing that the faces are detected well when my face is in the centre of the frame. 我注意到当我的脸位于画面中央时,可以很好地检测到这些脸。 Whenver I move a bit to the sides, the face detector either completely misses my face or gives no detection. 每当我向侧面移动一点时,面部检测器要么会完全错过我的面部,要么不会提供任何检测。 Is this bias because of the way I am using the function (code appended) or is it an inherent bias in the HAAR Classifiers? 这是我使用函数(附加代码)的方式造成的偏见,还是HAAR分类器中的固有偏见? Note that in either case (my face being in the approximate centre of the frame or my face being somewhere near the boundaries), my face is completely visible, ie so side profiles/or cutting of the face. 请注意,在任何一种情况下(我的脸位于框架的大致中心或脸在边界附近的某处),我的脸都是完全可见的,即侧面轮廓/或脸部的切割。

//A live face detector Program. Takes feed from the camera and detects face in the given frame

#include<opencv2/opencv.hpp>
#include<iostream>
#include<vector>
#include"opencv2/video/video.hpp"
using namespace cv;
using namespace std;



 int main(){
     cv::Mat frame;
     cv::VideoCapture cap(0);
     cv::namedWindow("Frame");
 do{
        cap >> frame;

        Rect r1,r2;
        vector<Rect> faces1,faces2;
        CascadeClassifier cascade1;
        CascadeClassifier cascade2;
        //cascade1.load("C:/opencv2.4.9/sources/data/lbpcascades/lbpcascade_frontalface.xml");
        cascade1.load("C:/opencv2.4.9/sources/data/haarcascades/haarcascade_frontalface_alt2.xml");
        cascade2.load("C:/opencv2.4.9/sources/data/lbpcascades/lbpcascade_profileface.xml");
        cascade1.detectMultiScale(frame, faces1,1.05, 6, CV_HAAR_FIND_BIGGEST_OBJECT, Size(0, 0));
        cascade2.detectMultiScale(frame, faces2,1.05, 6, CV_HAAR_FIND_BIGGEST_OBJECT, Size(0, 0));
        if (faces1.size()!=0){
            cout << "face1 found";
            r1 = faces1[0];
        }

        if (faces2.size()!=0){
            cout << "face2 found";
            r2 = faces2[0];
        }

            rectangle(frame, Point(r1.y,r1.x), Point(r1.y+r1.height,r1.x+r1.width), Scalar(0,255,0),2, 8);
            rectangle(frame, Point(r2.y,r2.x), Point(r2.y+r2.height,r2.x+r2.width), Scalar(255,0,0),2, 8);
            imshow("Frame",frame);
        }while(waitKey(30) < 0);

 cap.release();
 return 0;
 } 

your haar classifier code is working well.in your code change this 您的haar分类器代码运行良好。在您的代码中更改此

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

to

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

it will work. 它会工作。 you have changed the x,y values. 您已经更改了x,y值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM