java opencv sift,SURF和SIFT算法在OpenCV 3.0 Java中不起作用

I am using OpenCV 3.0 (the latest version) in Java, but when I use SURF algorithm or SIFT algorithm it doesn't work and throws Exception which says: OpenCV Error: Bad argument (Specified feature detector type is not supported.) in cv::javaFeatureDetector::create

I have googled, but the answers which was given to this kind of questions did not solve my problem. If anyone knows about this problem please let me know.

Thanks in advance!

Update: The code below in third line throws exception.

Mat img_object = Imgcodecs.imread("data/img_object.jpg");

Mat img_scene = Imgcodecs.imread("data/img_scene.jpg");

FeatureDetector detector = FeatureDetector.create(FeatureDetector.SURF);

MatOfKeyPoint keypoints_object = new MatOfKeyPoint();

MatOfKeyPoint keypoints_scene = new MatOfKeyPoint();

detector.detect(img_object, keypoints_object);

detector.detect(img_scene, keypoints_scene);

解决方案

If you compile OpenCV from source, you can fix the missing bindings by editing opencv/modules/features2d/misc/java/src/cpp/features2d_manual.hpp yourself.

I fixed it by making the following changes:

(line 6)

#ifdef HAVE_OPENCV_FEATURES2D

#include "opencv2/features2d.hpp"

#include "opencv2/xfeatures2d.hpp"

#include "features2d_converters.hpp"

...(line 121)

case SIFT:

fd = xfeatures2d::SIFT::create();

break;

case SURF:

fd = xfeatures2d::SURF::create();

break;

...(line 353)

case SIFT:

de = xfeatures2d::SIFT::create();

break;

case SURF:

de = xfeatures2d::SURF::create();

break;

The only requirement is that you build opencv_contrib optional module along with your sources (you can download the git project from https://github.com/Itseez/opencv_contrib and just set its local path on opencv's ccmake settings.

Oh, and keep in mind that SIFT and SURF are non-free software ^^;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值