I am creating an object classifier using OpenCV and to avoid having to train the classifiers every time the app is launched I would like to somehow store them in a file. The most convenient way available seems to be using OpenCVs FileStorage class.
I gave this a shot but it didn't seem to work. The saved file did not show up anywhere though I did not receive an error. I suppose iOS doesn't just let you save any file. An alternative way would be to retrieve the YAML as a string, convert it to an NSString and save it in a property list, but I am not sure how this can be done or whether it is even possible.
Any help would be greatly appreciated.
I managed to get the FileStorage class working with iOS. The problem was that I needed to make sure the file was being created in iOSs designated Documents Directory. Here is some 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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With