【发布时间】:2013-10-21 10:35:31
【问题描述】:
我正在开发一个 android 应用程序,可以从任何捕获的图像中提取词袋 我将按照tutorial
使用 opencv 库现在我有一个 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方法中传递这个参数
我希望我的问题对你来说很清楚 谢谢
【问题讨论】:
-
我希望这会有所帮助stackoverflow.com/questions/502430/…
-
我是 C++ 新手,但在谷歌上搜索后这个参数
const path& basepath是一个常量引用,所以我不知道如何转换它,java 不使用引用 -
@nawara Java 仅对所有内容使用引用(原始类型除外)。但这不是重点,使用 JNI,您只能传递 JNI Types,因此您需要在 JNI 函数中使用一个 jstring,在该 JNI 函数的 c 实现中构造一个
path对象(无论是什么)。然后使用该对象从 JNI 函数中调用现有的 c 函数。
标签: java android c++ opencv android-ndk