我開發一個Android應用程序中提取文字的袋子從任何拍攝的圖像 我將使用OpenCV庫爲目的folliwing這tutorial的Android NDK --converting C++方法的Java mthod
現在我有一個C++方法: void extractTrainingVocabulary(const path& basepath) {...}
,我需要在我的Android活動
void extractTrainingVocabulary(const path& basepath) {
for (directory_iterator iter = directory_iterator(basepath); iter
!= directory_iterator(); iter++) {
directory_entry entry = *iter;
if (is_directory(entry.path())) {
cout << "Processing directory " << entry.path().string() << endl;
extractTrainingVocabulary(entry.path());
} else {
path entryPath = entry.path();
if (entryPath.extension() == ".jpg") {
cout << "Processing file " << entryPath.string() << endl;
Mat img = imread(entryPath.string());
if (!img.empty()) {
vector<KeyPoint> keypoints;
detector->detect(img, keypoints);
if (keypoints.empty()) {
cerr << "Warning: Could not find key points in image: "
<< entryPath.string() << endl;
} else {
Mat features;
extractor->compute(img, keypoints, features);
bowTrainer.add(features);
}
} else {
cerr << "Warning: Could not read image: "
<< entryPath.string() << endl;
}
}
}
}
}
所以下面的教程android NDK
我 應該聲明此方法是這樣的:public native void extractTrainingVocabulary() ;
我的問題是如何處理C++參數const path& basepath
?如何通過這個參數在Java方法
我希望我的問題是明確爲你 感謝
我希望這將有助於 http://stackoverflow.com/questions/502430/passing-const-variable-to-method-in-java/502457#502457 – Rajj
我是新的C++,但經過谷歌搜索這個參數'const path&basepath'是一個const引用,所以我不知道如何轉換它,java不使用引用 – nawara
@nawara Java只對所有東西(除了原始類型)使用引用。但是,這並不重要,用JNI你只能傳遞[JNI Types](http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html),所以你需要以JNI函數中的jstring爲例,在該JNI函數的c實現中構造一個'path'對象(不管是什麼)。然後使用該對象從JNI函數中調用現有的c函數。 – PeterT