OpenCV(CvHaarClassifierCascade *)cvLoad无法加载,无法加载xml文件 [英] OpenCV (CvHaarClassifierCascade*) cvLoad doesn't load, unable to load xml file

查看:222
本文介绍了OpenCV(CvHaarClassifierCascade *)cvLoad无法加载,无法加载xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenCv 2.3进行面部检测。我试图加载 haarcascade_frontalface_alt_tree.xml;在我的项目中,我一直无法加载xml文件。

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.3\opencv\data\haarcascades\haarcascade_frontalface_alt_tree.xml" ; 
pCascade = (CvHaarClassifierCascade*) cvLoad(file , NULL, NULL, NULL);
    if (!pCascade)   { 
        exit(-1);    // unable to load xml 
    }

我认为我遇到了与此问题

I尝试在cvLoad命令之前加载图像,但没有帮助。

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

我使用的是OpenCV 2.3,就像在教程

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

我正在使用这些库(

    #include <stdio.h>
#include "opencv2\opencv.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")


推荐答案

在致电之前缩小问题范围cvLoad ,您应该检查文件是否存在。这是一种方法:

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);
}

您需要 #include< sys /stat.h>

在我的系统上(OS X 10.6.8 / OpenCV 2.3 ),当我尝试加载 haarcascade_frontalface_alt_tree.xml haarcascade_frontalface_alt.xml 时,出现异常:

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






我认为您使用的是过时的OpenCV 1教程,该教程不适用于当前版本的 haarcascade_frontalface_alt_tree.xml 。请尝试使用此OpenCV 2教程。该教程中的代码对我有用:


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;

这篇关于OpenCV(CvHaarClassifierCascade *)cvLoad无法加载,无法加载xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆