0

I've imported opencv and opencv_contrib frameworks in an Xcode project, and in my Objective-C++ file, I load a face classifier and then a Fisher face recognizer:

// set up classifier, recognizer, and webcam
-(void) setupAnalyzer:(NSString *)faceCascadeName :(NSString *)fisherDatasetName
{
    // load face classifier
    cout << "loading face classifier..." << endl;
    String faceCascadeNameString = string([faceCascadeName UTF8String]);
    faceCascade.load(faceCascadeNameString);

    // load face recognizer
    cout << "loading face recognizer..." << endl;
    fishface = createFisherFaceRecognizer();
    String fisherDatasetNameString = string([fisherDatasetName UTF8String]);
    fishface->load(fisherDatasetNameString);
}

When I call this function from Swift, it seems the face classifier loads just fine with an xml file I have in my project. But when I try to load the Fisher face recognizer using another xml file in my project, Xcode shows this error:

OpenCV Error: Unspecified error (File can’t be opened for reading!) in load, file ~/opencv/modules/face/src/facerec.cpp, line 61

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: ~/opencv/modules/face/src/facerec.cpp:61: error: (-2) File can’t be opened for reading! in function load

I've tried rebuilding the OpenCV frameworks in different ways and I keep getting the same error!

First of all, I'm confused why the program is looking to source code that isn't contained in the project (it's looking for facerec.cpp in another directory on my computer). Also, why does the cascade classifier load just fine? This makes me think it's an issue with the way I built the opencv_contrib modules, because the face classifier comes from opencv_contrib. But I tried rebuilding opencv_contrib, and I still get this OpenCV error.

Any help would be greatly appreciated!

[UPDATE] It is not an issue with building the contrib module. I manually included the module in Xcode, so it's now looking within the project for the facerec.cpp, but it still can't open the xml file for reading.

Community
  • 1
  • 1
Berthy
  • 11
  • 2

2 Answers2

0

First of all, I'm confused why the program is looking to source code that isn't contained in the project (it's looking for facerec.cpp in another directory on my computer).

It doesn't search for file. It shows you where error was happen. Since your library was build on your machine and has debug information it can point you source file and line number where error happen.

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: ~/opencv/modules/face/src/facerec.cpp:61: error: (-2) File can’t be opened for reading! in function load

This message means that exception was generated at line 61 in file facerec.cpp. You need to check if your data is available for reading.

John Tracid
  • 3,836
  • 3
  • 22
  • 33
0

Figured it out! This answer helped me realize that I needed to get the app bundle's path to the xml files: OpenCV Cascade Classifier load error iOS

Berthy
  • 11
  • 2