Loading SVM results in crash FileStorage

asked 2016-12-02 16:03:07 -0500

tomgekeerd gravatar image

Hello everyone,

I am currently developing an iOS application that uses the OpenCV framework for image processing. To process this image I want to make a prediction based on a trained SVM xml file we trained earlier with images.

To load this xml file (in the iOS Application) we are using the normal method to do this is in a sandboxed application in Objective-C. After we got the right path we want to load this using the SVM->load method in Objective-C++:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"model" ofType:@"xml"];
    const char* cPath = [path cStringUsingEncoding:NSMacOSRomanStringEncoding];

    FileStorage fs([path UTF8String], FileStorage::READ);
    cv::FileStorage read(cPath,
                         cv::FileStorage::READ);
    auto my_svm = cv::ml::SVM::create();

    // Crash is because of this line down below

    my_svm->load(read.root());

Unfortunately, this result in the following crash:

    error: (-27) NULL or empty buffer in function cvOpenFileStorage

I looked up this error on various fora, which states that this is because FileStorage cannot find the path sent in the argument of the load method.

After debugging this for hours, I lost my faith and really want to resolve this issue. Does anyone here knows what is going on here, or probably, what is going wrong here?

Thanks in advance

edit retag flag offensive close merge delete

Comments

Are you actually sure that this crash is generated due to the root and not due to the fact that your FileStorage is not initialized correctly? Can you output the value is contained into cPath?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-12-05 03:01:54 -0500 )edit

Hmm, the output of cPath is the sandboxed path where the model.xml is saved (which is correct when I print it). What do you mean by 'not initialized correctly' actually? Since I have no C++ experience besides this I can make mistakes very fast. How would you initialize FileStorage? Thanks!

tomgekeerd gravatar imagetomgekeerd ( 2016-12-05 11:45:47 -0500 )edit

Hmm, just edited some code and it now gives a total different error which is (I think) some format issue in model.xml. Since the script that generated this xml file runs version 2.4 of OpenCV and I am currently loading it using 3.1.0, could this lead to some error because the xml is parsed differently? Btw, the error is:

'The node is neither a map nor an empty collection in function cvGetFileNodeByName'

tomgekeerd gravatar imagetomgekeerd ( 2016-12-05 11:53:41 -0500 )edit

@tomgekeerd Did you get to resolve this?

ginister gravatar imageginister ( 2017-02-27 18:53:07 -0500 )edit