detectMultiScale return illogical result [closed]
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 :
and when expand unclear result like this:
and In the following this exception occurred : AccessViolationException
please help me thanks. my opencv version is 3.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) ?
i add both of : opencv_world310.lib , opencv_world310d.lib into AdditionalDependencies and my My PC is an x64 architecture.
and add both of opencv_world310.dll , opencv_world310d.dll in debug directory
so, that's probably the reason. use only opencv_world310d.lib for debug, and only opencv_world310.dll for release
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.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