【发布时间】:2013-04-10 00:20:53
【问题描述】:
我正在尝试在 Android 中使用面部识别。所有负载都正常,但是我不知道如何使用 JavaCV 加载它的 haarcascade_frontalface_alt2.xml 文件。 这是我的代码:
public static void detectFacialFeatures()
{
// The cascade definition to be used for detection.
// This will redirect the OpenCV errors to the Java console to give you
// feedback about any problems that may occur.
new JavaCvErrorCallback();
// Load the original image.
// We need a grayscale image in order to do the recognition, so we
// create a new image of the same size as the original one.
IplImage grayImage = IplImage.create(iplImage.width(),iplImage.height(), IPL_DEPTH_8U, 1);
// We convert the original image to grayscale.
cvCvtColor(iplImage, grayImage, CV_BGR2GRAY);
CvMemStorage storage = CvMemStorage.create();
// We instantiate a classifier cascade to be used for detection, using the cascade definition.
CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(cvLoad("./haarcascade_frontalface_alt2.xml"));
// We detect the faces.
CvSeq faces = cvHaarDetectObjects(grayImage, cascade, storage, 1.1, 1, 0);
Log.d("CARAS","Hay "+faces.total()+" caras ahora mismo");
}
问题来了
CvHaarClassifierCascade(cvLoad("./haarcascade_frontalface_alt2.xml"));
我尝试将 xml 文件放入 /assets 文件夹,但我不知道如何加载它。它总是给我下一个错误:
03-26 17:31:25.385: E/cv::error()(14787): OpenCV Error: Null pointer (Invalid classifier cascade) in CvSeq* cvHaarDetectObjectsForROC(const CvArr*, CvHaarClassifierCascade*, CvMemStorage*, std::vector<int>&, std::vector<double>&, double, int, int, CvSize, CvSize, bool), file /home/saudet/projects/cppjars/OpenCV-2.4.4/modules/objdetect/src/haar.cpp, line 1514
... 更接近它指向此代码行的错误:
CvSeq faces = cvHaarDetectObjects(grayImage, cascade, storage, 1.1, 1, 0);
这就是为什么我很确定问题来自 haarcascade_frontalface_alt2.xml 加载。
感谢您的帮助。
P.D:我想将级联包含在 apk 中,而不是 sdcard 中。
【问题讨论】: