Ask Your Question
1

Detectmultiscale for face detection in opencv 3.1 C++ doesn't work properly

asked 2015-12-28 10:58:04 -0600

GVannu gravatar image

Dear all, I recently develop an app for face detection using C++, Visual Studio 2015 and lbp cascades filter. Initially, my app, was developed with OpenCV 3.0 and face detection was very very good. The code is similar to others hundreds of Code on hundreds and hundreds of blogs:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/objdetect/objdetect.hpp"
#include <opencv2/imgproc.hpp>
#include "main.h"

using namespace cv;
using namespace std;
Mat cameraFrame;
CascadeClassifier face_cascade;
int main()
{
    VideoCapture stream1(0);
    Mat mGray;
    Mat eye;
    vector<Rect> faces;
face_cascade.load("C:\\MyFile\\Lavoro\\EyeTracking\\OpenCVwindows\\opencv\\build\\etc\\lbpcascades\\lbpcascade_frontalface.xml");
while (true) {
        stream1.read(cameraFrame);
        cvtColor(cameraFrame, mGray, CV_RGB2GRAY);
        equalizeHist(mGray, mGray);
        face_cascade.detectMultiScale(mGray, faces, 1.1, 2, CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_SCALE_IMAGE, Size(30, 30));
}
}
// ...other not usefull code for this questions

So, basically, I load an lbp filter and I apply this filter on GRAY image for detect faces. In OpenCV 3.0 all run very well, in opencv3.1 the results is that vector faces has a size of about 1.5 Millions. Watching this results I noticed that x and y coordinates are, in some case, wrong! For example into an image of 640x480 I have x and y of about 3000-4000.

Is this a bug of OpenCV 3.1? How can I resolve it?

edit retag flag offensive close merge delete

Comments

did you build OpenCV 3.1 libraries from source?

sturkmen gravatar imagesturkmen ( 2015-12-28 13:29:54 -0600 )edit

Hi sturkmen. No, I download the self-extract file from opencv website, I set environment variable and path. And finally set my visual studio project properties ( like linker input and additional include directories). I follow the tutorial provide from opencv. This worked for 3.0. I do the same procedure for 3.1 and I succesfully build and run my code. I have problem just with face detection

GVannu gravatar imageGVannu ( 2015-12-28 14:17:23 -0600 )edit

AFAIK Visual Studio 2015 compatibility is only by building libraries yourself. could you try both of OpenCV tutorials and tell us the results.

sturkmen gravatar imagesturkmen ( 2015-12-28 14:41:03 -0600 )edit

Yes!! I will try and I will tell you the results. Thank you

GVannu gravatar imageGVannu ( 2015-12-28 14:43:20 -0600 )edit

Hi! I have some problem on Visual Studio 2015 Community, C++, Windows 10, OpenCV 3.1, x64, tried both Debug and Releas. Source code like above. 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)

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

using gravatar imageusing ( 2016-04-17 13:14:58 -0600 )edit

@using again i ask, did you build OpenCV 3.1 libraries from source?

sturkmen gravatar imagesturkmen ( 2016-04-17 16:01:44 -0600 )edit

@sturkmen No, I did not build the library. I used ready-made from opencv3.1.0\opencv\build\x64\vc14\lib

using gravatar imageusing ( 2016-04-18 13:48:53 -0600 )edit

@sturkmen i tried your code above in 3.0.0 and it don work properly. There is access violation error at size < 462. (At size >462 faces.size=0). And also, you are using LBP cascade and CV_HAAR_SCALE_IMAGE key. Is it correct?

using gravatar imageusing ( 2016-04-18 15:16:52 -0600 )edit

where is the whole source ? i think you have a problem about configuration of Visual Studio. did you try to run some of other examples

sturkmen gravatar imagesturkmen ( 2016-04-18 15:43:38 -0600 )edit

i advise you to try rebuilding library from source

sturkmen gravatar imagesturkmen ( 2016-04-18 16:18:51 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-04-18 16:16:06 -0600

using gravatar image

May be problem is in precomiled libs. Here is describe step by step: http://dogfeatherdesign.com/opencv-3-.... Sorry offtop, this about 3.0.0

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2015-12-28 10:58:04 -0600

Seen: 2,994 times

Last updated: Dec 28 '15