Ask Your Question
1

Access violation when using Cascade Classifier

asked 2013-05-15 09:04:26 -0600

AJW gravatar image

Hi there. I am currently trying to write some code to do Face Detection with the Cascade Classifier. I tried running the example code from the site (http://docs.opencv.org/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html). After getting an error, I tried stripping out some code to try to isolate the problem, but ultimately it seems that even creating a CascadeClassifier object causes a problem. The code is as follows:

/**
 * @file objectDetection2.cpp
 * @author A. Huaman ( based in the classic facedetect.cpp in samples/c )
 * @brief A simplified version of facedetect.cpp, show how to load a cascade classifier and how to find objects (Face + eyes) in a video stream - Using LBP here
 */
#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(){

    CascadeClassifier face_cascade("haarcascade_frontalface_alt.xml");

    return 0;
}

When the main method finishes, I get an error message (see: C:\fakepath\Error.PNG). I don't see how it could possibly be a problem with the constructor for CascadeClassifier, but I'm totally bewildered as to what's going on. The file given as an argument is in the same directory as the c++ file. Anyone have any ideas? Apologies if the answer is obvious, my C++ is a bit shaky.

Cheers

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-05-15 13:19:47 -0600

clarkis117 gravatar image

updated 2013-05-15 13:21:47 -0600

You need to use the file's full path, if it is in a separate directory from the program's .exe in windows.

Example

CascadeClassifier face_cascade("C:\\opencv\\data\\haarcascades\\haarcascade_frontalface_alt.xml");

This is a C string or a null terminated string, they are used to access files in opencv. In C strings \\ equates to "\" one literal backslash.

edit flag offensive delete link more

Comments

Thanks for replying so quickly. I tried giving the full path, and also tried putting the file in the same directory as the .exe, but it hasn't helped. I don't know if this is helpful, but the error seems to occur at the very end of the main function. If I step through just the initialisation line, I don't get the error; it only seems to occur when main finishes. So I presume it's finding the input file, but beyond that I'm not sure.

AJW gravatar imageAJW ( 2013-05-15 20:42:15 -0600 )edit

Question Tools

Stats

Asked: 2013-05-15 09:04:26 -0600

Seen: 726 times

Last updated: May 15 '13