detectMultiScale detects insane amount of faces [closed]

asked 2015-06-07 13:04:44 -0500

Precious Roy gravatar image

Hi,

This is my first attempt to detect faces with OpenCV but i am getting strange results. I am using the newest OpenCV files. but something is not right and i am getting detectMultiScale to fill the faces vector with 265290877 unusable entries. where most of them look like this [0] = {x=0 y=0 width=-1414812757 height = -1414812757}. so does any one know what i am doing wrong?

#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

int main(int argc, const char** argv)
{
//create the cascade classifier object used for the face detection
CascadeClassifier face_cascade;
//use the haarcascade_frontalface_alt.xml library
if (!face_cascade.load("haarcascade_frontalface_alt.xml"))
{
    printf("Unable to load classifier XML");
    return 0;
}

//setup video capture device and link it to the first capture device
//VideoCapture captureDevice;
//captureDevice.open(0);

//setup image files used in the capture process
Mat captureFrame;
Mat grayscaleFrame;

captureFrame = imread("Test.png", IMREAD_COLOR);

if (captureFrame.empty()) // Check for invalid input
{
    cout << "Could not open or find the image" << std::endl;
    return 0;
}

//create a window to present the results
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> faces;

    //find faces and store them in the vector array
    face_cascade.detectMultiScale(grayscaleFrame, faces, 1.1, 3, 0 | 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(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
    //  Point pt2(faces[i].x, faces[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;
}
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-12-08 08:01:35.115570

Comments

Can you post your image as we can also do the test ?

Eduardo gravatar imageEduardo ( 2015-06-07 16:38:34 -0500 )edit

yes good idea

here is the image i am using = http://www.r-junk.com/Data/OpenCV/Tes...

here is the VS debug view = http://www.r-junk.com/Data/OpenCV/out...

when using my webcam i was getting the same results

Precious Roy gravatar imagePrecious Roy ( 2015-06-07 17:18:11 -0500 )edit

I tried your code with OpenCV 2.4.9 and everything is fine on my computer. With the following minimal code:

cv::CascadeClassifier face_cascade("haarcascade_frontalface_alt.xml");
  cv::VideoCapture captureDevice("http://www.r-junk.com/Data/OpenCV/TestImage.png");

  cv::Mat captureFrame;
  captureDevice >> captureFrame;
  std::cout << "captureFrame=" << captureFrame.cols << "x" << captureFrame.rows << " ; type=" << captureFrame.type() << std::endl;

  std::vector<cv::Rect> faces;
  face_cascade.detectMultiScale(captureFrame, faces, 1.1, 3, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));
  std::cout << "faces.size()=" << faces.size() << std::endl;

I have the output:

captureFrame=800x618 ; type=16
faces.size()=1
Eduardo gravatar imageEduardo ( 2015-06-08 11:21:37 -0500 )edit

Well i just managed to rebuild 3.0 my self in visual studio changed the lib location and everything worked fine. so i am stumped why the pre-built libs doe not work with visual studio 2013. but i guess my problem is solved. i don't know if this is a but or not and don't really know if i need to report it.

Precious Roy gravatar imagePrecious Roy ( 2015-06-08 11:53:16 -0500 )edit

Are you sure you used the correct directory (vc10 is for VS2010, vc11 is for VS2012 and vc12 is for VS2013) ? Did you try with the latest version: OpenCV 3.0 gold (2015/06/04) ?

Eduardo gravatar imageEduardo ( 2015-06-08 12:59:49 -0500 )edit

Yea i was using the vc12\lib folder. it compiled just fine

Precious Roy gravatar imagePrecious Roy ( 2015-06-08 17:37:13 -0500 )edit

I have the same problem - innumerable number of faces in face_cascade.detectMultiScale.

Visual Studio 2015 Community, C++, Windows 10, OpenCV 3.1, x64, tried both Debug and Releas. Source code like above.

using gravatar imageusing ( 2016-04-17 11:27:42 -0500 )edit

I tried various combinations of the debug configurations: MT, MD, MDd I tried all of classifiers for faces: haarcascade_frontalcatface.xml, haarcascade_frontalface_alt.xml, haarcascade_frontalface_default.xml from opencv\build\etc\haarcascades

When I tried source line face_cascade.detectMultiScale(frame_gray, faces, 1.1, 3, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30)); the error access violation record appears (record or writing i do not shure because have a Russian interface)

using gravatar imageusing ( 2016-04-17 11:27:58 -0500 )edit

Next I tried change Size(500,500), and when line pass but faces keeps billlllions of faces.

using gravatar imageusing ( 2016-04-17 11:28:42 -0500 )edit

I rebuild 3.1.0 library and again has got a lot of faces on both my books (with Intel HD 4000 one and NVIDIA GeForce GT 425M another) captureFrame=640x480 ; type=16 faces.size()=18446743934142353947 after

capture >> frame; std::cout << "captureFrame=" << frame.cols << "x" << frame.rows << " ; type=" << frame.type() << std::endl;

    std::vector<cv::Rect> faces;
    face_cascade.detectMultiScale(frame, faces, 1.1, 3, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));
    std::cout << "faces.size()=" << faces.size() << std::endl;

What are we all doing wrong?

using gravatar imageusing ( 2016-04-28 12:26:40 -0500 )edit