2017-04-19 10 views
1

VisualStudioプロジェクトでうまくいきましたチュートリアルから "classesifications.xml"と "images.xml"を読み込もうとしています。 Swift XCodeプロジェクトのC++ライブラリでファイルを指定するにはどうすればよいですか?プロジェクトにドラッグアンドドロップしても機能しませんでした。Swift IOSプロジェクトのOpenCVファイルを読み込みます

ここに元のコードです。プロジェクトのファイルに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

あなたのプロジェクトにドラッグアンドドロップすると、それらはアプリケーションバンドルになります。 、あなただけ「のClassifications.xml」使用している場合、それはなり

Bundle.main.path(forResource: "classifications", ofType: "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

@Alexander詳細を更新 –

関連する問題