Bahramdun Adil Bahramdun Adil - 1 year ago 559
Java Question

SURF and SIFT algorithms doesn't work in 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);

Answer Source

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)
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "features2d_converters.hpp"

...(line 121)
    case SIFT:
    fd = xfeatures2d::SIFT::create();
    case SURF:
    fd = xfeatures2d::SURF::create();

...(line 353)
    case SIFT:
        de = xfeatures2d::SIFT::create();
    case SURF:
        de = xfeatures2d::SURF::create();

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download