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
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();
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 ^^;