如何在 Android NDK 中使用 OpenCV BOWImgDescriptorExtractor?

Posted

技术标签:

【中文标题】如何在 Android NDK 中使用 OpenCV BOWImgDescriptorExtractor?【英文标题】:How to use OpenCV BOWImgDescriptorExtractor in Android NDK? 【发布时间】:2015-02-10 22:48:09 【问题描述】:

我有一个带有原生部分的 android 应用。它将使用 svm,所以我需要 BOWImgDescriptorExtractor。我的问题是我不能在 PC 上使用bowDE.compute();。没有带有此参数的 Android 实现:bowDe.compute(Mat& img, vector<KeyPoint>& keypoints, Mat& descriptors);

我必须使用以下方法:

void compute(const cv::Mat &, std::vector<cv::KeyPoint,std::allocator<cv::KeyPoint>> &, cv::Mat &, std::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>> *, cv::Mat *)

我不知道怎么做。

当我将鼠标悬停在 BOWImgDescriptorExtracotr 上时,我可以看到该类。在那里我可以看到方法声明,如下:

 void compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& imgDescriptor,
                  vector<vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 );
    // compute() is not constant because DescriptorMatcher::match is not constant

如您所见,其他参数都有其默认值,但由于某种原因,我仍然收到无效参数的错误。虽然它应该是的方法与类中给出的方法不同..出于某种原因..

我的代码如下:

Mat features;
vector<KeyPoint> keypoints;

detector->detect(matGray, keypoints);
KeyPointsFilter::retainBest(keypoints, 1500);
bowDE.compute(matGray, keypoints, features);

这是尝试编译时的输出:

SVMDetector.cpp:45:45: error: no matching function for call to 'cv::BOWImgDescriptorExtractor::compute(cv::Mat&, std::vector<cv::KeyPoint>&, const cv::Mat&)'
SVMDetector.cpp:45:45: note: candidate is:
OpenCV-2.4.9-android-sdk/sdk/native/jni/include/opencv2/features2d/features2d.hpp:1592:10: note: void cv::BOWImgDescriptorExtractor::compute(const cv::Mat&, std::vector<cv::KeyPoint>&, cv::Mat&, std::vector<std::vector<int> >*, cv::Mat*)
OpenCV-2.4.9-android-sdk/sdk/native/jni/include/opencv2/features2d/features2d.hpp:1592:10: note:   no known conversion for argument 3 from 'const cv::Mat' to 'cv::Mat&'
make: *** [/<some path>/local/armeabi-v7a/objs/svm_detector/SVMDetector.o] Error 1

你能举个例子或解释一下吗?提前致谢!

【问题讨论】:

【参考方案1】:

我认为这可能是 IDE (Eclipse Luna) 的问题。今天打开电脑启动eclipse后,没有报错。

【讨论】:

以上是关于如何在 Android NDK 中使用 OpenCV BOWImgDescriptorExtractor?的主要内容,如果未能解决你的问题,请参考以下文章

如何定位Android NDK开发中遇到的错误

如何在 Android 中从 NDK 访问可绘制文件

如何使用Android SDK Manager安装NDK

如何使用cmake和Android NDK在C ++中加载线程支持

如何使用 Android Gradle 插件 0.7 配置 NDK

如何在 OSX for Android studio 中设置 NDK 构建路径