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

查看:1646
本文介绍了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 
    }



我相信我会遇到同样的问题作为此问题

我试图在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

我使用这些库(我认为我的配置是正确的,文件存在,可以使用Notepad ++打开)

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

    #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天全站免登陆