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;