1

I am trying to read "classifications.xml" and "images.xml" from a tutorial which was working fine in a VisualStudio project. How do I point the C++ library in my Swift XCode project to the files now? Drag and dropping them into the project did not work.

Here is the original code. How do I point cv::Filestorage class to the files in my project? Right now it returns an error

cv::Mat matClassificationInts;      // we will read the classification numbers into this variable as though it is a vector

cv::FileStorage fsClassifications("classifications.xml", cv::FileStorage::READ);        // open the classifications file

if (fsClassifications.isOpened() == false) {                                                    // if the file was not opened successfully
    std::cout << "error, unable to open training classifications file, exiting program\n\n";    // show error message
    return(0);                                                                                  // and exit program
}

fsClassifications["classifications"] >> matClassificationInts;      // read classifications section into Mat classifications variable
fsClassifications.release();                                        // close the classifications file
Alexander
  • 155
  • 1
  • 8

1 Answers1

1

When you dragged and dropped them into your project, they ended up in the app bundle.

The filename for those files can be found with this Swift code:

Bundle.main.path(forResource: "classifications", ofType: "xml")

I don't know what your code does it load it, but if you just used "classifications.xml", it would default to the current folder which is not an allowed path on iOS for resources.

It might be easier to get this to work with Objective-C if you are trying to interop with C++.

Something like;

NSString *path = [[NSBundle main] pathForResource:@"classification" ofType:@"xml"];
char *pathCString = [path cStringUsingEncoding:NSUTF8StringEncoding];

And then read this: How to call an Objective-C Method from a C Method?

Community
  • 1
  • 1
Lou Franco
  • 87,846
  • 14
  • 132
  • 192