2017-04-19 86 views
1

我想從VisualStudio項目中工作正常的教程中讀取「classifications.xml」和「images.xml」。我現在如何將Swift XCode項目中的C++庫指向文件?將它們拖放到項目中不起作用。OpenCV在Swift IOS項目中讀取文件

這是原始代碼。我如何將cv :: Filestorage類指向我的項目中的文件?現在它返回一個錯誤

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 

回答

1

當你把它們拖放到你的項目中時,它們結束了應用程序包。

這些文件的文件名可以與該銀行代碼中找到:

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

我不知道你的代碼,它加載它,但如果你只是用「classifications.xml」,它會默認爲當前文件夾,該文件夾不是iOS資源上允許的路徑。

如果你想與C++進行互操作,使用Objective-C可能會更容易。

有點像;

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

,然後讀此:How to call an Objective-C Method from a C Method?

+0

謝謝你,我沒有找到包中的文件。現在正在尋找一種方式將他們送入圖書館 – Alexander

+0

@亞歷山大更新了更多信息 –