简体   繁体   中英

opencv\modules\core\src\persistence.cpp:2697: error: (-27) NULL or empty buffer in function cvOpenFileStorage

I am trying to run a facedetection application and I get the following error:

Unexpected Standard exception from MEX file.
What() is:..\..\..\..\opencv\modules\core\src\persistence.cpp:2697: error: (-27)
NULL or empty buffer in function cvOpenFileStorage

If you're using haarcascade_frontalface_default.xml, check the xml file content.

The first 3 lines should be:

<?xml version="1.0"?>
<!--
    Stump-based 24x24 discrete(?) adaboost frontal face detector.

I inadvertently downloaded the html that linked to the haarcascade_frontalface_default.xml file instead of the xml itself and got the same error you did.

You should provide some code and information.Nevertheless the error indicates that it can not access the haarcascade file. I suggest you make sure you have the "xml" in the same folder as your code (eg "ViewController.mm") and check permissions. additionally Assuming you are using Objective-c or swift:

1-check the file is in your Xcode project; and, if it is,

2-check it's included in the 'Copy Bundle Resources' phase underneath your selected Target (in the project tree view on the left in the normal Xcode window layout) and, if it is,

3-look inside the generated application bundle (find your product, right click, select 'Reveal in Finder', from Finder right click on the app and select 'Show Package Contents', then look for your file in there) to make sure that it's there.

I've got the same problem, and then I figure out what's the problem

First

Add file haarcascade_frontalface_default.xml to xcode project

make sure when you add the xml file with option below:

  1. Destination: Copy items if need [check]
  2. Added Folder: Create Folder References [check]
  3. Add to targets: Your Project target [check]

Second

in you Wrapper.mm file add this code to your obj-c function:

const NSString* cascadePath = [[NSBundle mainBundle]pathForResource:@"haarcascade_frontalface_default" ofType:@"xml"];

or in case you wanna load the xml file, use this code:

cv::CascadeClassifier classifier;
const NSString* cascadePath = [[NSBundle mainBundle]pathForResource:@"haarcascade_frontalface_default" ofType:@"xml"];
classifier.load([cascadePath UTF8String]);

this actually fixes my problem, anywaythis question has been questioned for a long time but I hope someone face this problem can come to this answer and help them solve their problem like mine, cheer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM