detectMultiScale return illogical result [closed]

asked 2016-03-25 01:47:49 -0600

aligoglos gravatar image

i want use cascade classifier for face detection but illogical result occurred this is my code :

#include "stdafx.h" #include "FaceDetection.h"
using namespace cv;
FaceDetection::FaceDetection(void)
{
    face_cascade = CascadeClassifier();
    face_Cascade_Path = "D:\book\ComputerLessons\haarcascade_frontalface_alt.xml";
    face_cascade.load(face_Cascade_Path);
}

Mat FaceDetection::detect(Mat input){ Mat face = Mat(input); faceExist = false; if (!face_cascade.empty()) { std::vector<Rect> faces; Mat grayInput; cvtColor( input, grayInput, COLOR_BGR2GRAY ); equalizeHist( grayInput, grayInput ); face_cascade.detectMultiScale( grayInput, faces, 1.1, 2, CASCADE_SCALE_IMAGE, Size(100, 100)); float maxArea = 0; int total = faces.size(); if (total>0) { for (size_t i = 0; i < faces.size(); i++) { Rect r = faces[i]; if (r.area() > maxArea) { faceExist = true; faceBound = r; maxArea = r.area(); } } face = input(faceBound); } } return face; } Rect FaceDetection::getBound(){ if (faceExist) { return faceBound; } else { return Rect(); } }

but when i click faces to expand result this error occured : image description

and when expand unclear result like this: image description image description

and In the following this exception occurred : AccessViolationException

please help me thanks. my opencv version is 3.1;

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-13 14:07:30.412425

Comments

1

please double-check your linker settings. are you accidentally using opencv debug libs in release build (or vice versa) ? are you sure you picked the right ones for your vs version / configuration (x86/x64) ?

berak gravatar imageberak ( 2016-03-25 01:51:43 -0600 )edit

i add both of : opencv_world310.lib , opencv_world310d.lib into AdditionalDependencies and my My PC is an x64 architecture.

aligoglos gravatar imagealigoglos ( 2016-03-25 02:01:49 -0600 )edit

and add both of opencv_world310.dll , opencv_world310d.dll in debug directory

aligoglos gravatar imagealigoglos ( 2016-03-25 02:03:27 -0600 )edit
2

so, that's probably the reason. use only opencv_world310d.lib for debug, and only opencv_world310.dll for release

berak gravatar imageberak ( 2016-03-25 02:18:11 -0600 )edit

Also a small remark, your extra check int total = faces.size(); if (total>0){ is totally unneccesary, since the for loop will just not run if the size is 0.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-03-29 06:14:33 -0600 )edit

i install visual studio 2015 (vs 14) and reconfiguration linker to vs 14 and copy new vs14 dll into my debug folder but didn't different this exception occurred. i thing is bug in opencv library. my new information : window 10 X64 , opencv 3.1 , visual studio 2015 update 1

aligoglos gravatar imagealigoglos ( 2016-03-30 04:00:53 -0600 )edit