Using OpenCV FileStorage in iOS

I am creating an object classifier using OpenCV, and to avoid the need to train classifiers every time I run the application, I would like to somehow save them in a file. The most convenient way, apparently, is the FileStorage class OpenCVs .

I fired, but it didn't seem to work. The saved file did not appear anywhere, although I did not receive an error. I suppose iOS doesn't just let you save any file. An alternative way would be to get YAML as a string, convert it to NSString and save it in the property list, but I'm not sure how this can be done or even possible.

Any help would be greatly appreciated.

+6
source share
1 answer

I managed to get the FileStorage class working with iOS. The problem was that I needed to make sure that the file was created in iOSs, specified in the "Document Directory". Here is a sample code:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docs = [paths objectAtIndex:0]; NSString *vocabPath = [docs stringByAppendingPathComponent:@"vocabulary.xml"]; FileStorage fs([vocabPath UTF8String], FileStorage::WRITE); // vocab is a CvMat object representing the vocabulary in my bag of features model fs << "vocabulary" << vocab; fs.release(); // READING NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docs = [paths objectAtIndex:0]; NSString *vocabPath = [docs stringByAppendingPathComponent:@"vocabulary.xml"]; FileStorage fs([vocabPath UTF8String], FileStorage::READ); // vocab is a CvMat object representing the vocabulary in my bag of features model fs["vocabulary"] >> vocab; fs.release(); 
+13
source

Source: https://habr.com/ru/post/910485/


All Articles