Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying face detection using OpenCv 2.3. My trying to load "haarcascade_frontalface_alt_tree.xml" on my project, I'm constantly unable to load the xml file.

    CvHaarClassifierCascade * pCascade = 0;  // the face detector   
const char* file ="C:OpenCV2.3opencvdatahaarcascadeshaarcascade_frontalface_alt_tree.xml" ; 
pCascade = (CvHaarClassifierCascade*) cvLoad(file , NULL, NULL, NULL);
    if (!pCascade)   { 
        exit(-1);    // unable to load xml 
    }

I believe that I'm experiencing the same problem as this problem.

I have tried to load an image before the cvLoad command, but it didn't help.

I'm using OpenCV 2.3, made my configuration just like in this tutorial.

I'm using those libraries (I presume my configurations are correct, the file exist and can be open using Notepad++).

    #include <stdio.h>
#include "opencv2opencv.hpp"
#include "cv.h"
#include "highgui.h"
//#include "cvaux.h"

using namespace cv;


#pragma comment(lib, "opencv_core230d.lib")
#pragma comment(lib, "opencv_highgui230d.lib")
//#pragma comment(lib, "opencv_contrib230d.lib")
//#pragma comment(lib, "opencv_calib3d230d.lib")
//#pragma comment(lib, "opencv_features2d230d.lib")
//#pragma comment(lib, "opencv_flann230d.lib")
//#pragma comment(lib, "opencv_gpu230d.lib")
#pragma comment(lib, "opencv_haartraining_engined.lib")
#pragma comment(lib, "opencv_imgproc230d.lib")
//#pragma comment(lib, "opencv_legacy230d.lib")
//#pragma comment(lib, "opencv_ml230d.lib")
//#pragma comment(lib, "opencv_objdetect230d.lib")
//#pragma comment(lib, "opencv_video230d.lib")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
399 views
Welcome To Ask or Share your Answers For Others

1 Answer

To narrow down the issue, before calling cvLoad you should check to see if the file exists. Here's one way:

struct stat buf;
int statResult = stat(file,&buf);
if (statResult || buf.st_ino < 0) {
    cout << "File not found: " << file << endl;
    exit(-2);
}

You'll need to #include <sys/stat.h>


On my system (OS X 10.6.8/OpenCV 2.3), when I attempt to load haarcascade_frontalface_alt_tree.xml or haarcascade_frontalface_alt.xml I get an exception:

OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /Users/steve/Development/opencv2/opencv/modules/core/src/persistence.cpp, line 4857

I think you are using an outdated OpenCV 1 tutorial that doesn't work with the current version of haarcascade_frontalface_alt_tree.xml. Try this OpenCV 2 tutorial instead. This code from that tutorial works for me:

CascadeClassifier face_cascade;
if (!face_cascade.load( file) ) { 
    cout << "Couldn't load face_cascade" << endl;
    exit(-1); 
}

cout << "Loaded face_cascade" << endl;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...