DescriptorExtractor.compute() is not removing keypoints
According to this documentation: http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_extractors.html#descriptorextractor-compute "Keypoints for which a descriptor cannot be computed are removed." but in this code:
Mat c1 = Highgui.imread("kf1.png");
Mat c2 = Highgui.imread("kf2.png");
Mat f1 = new Mat();
Mat f2 = new Mat();
Imgproc.cvtColor(c1, f1, Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(c2, f2, Imgproc.COLOR_BGR2GRAY);
FeatureDetector detector = FeatureDetector.create(FeatureDetector.PYRAMID_FAST);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
MatOfKeyPoint mkpf1 = new MatOfKeyPoint();
MatOfKeyPoint mkpf2 = new MatOfKeyPoint();
Mat df1 = new Mat();
Mat df2 = new Mat();
detector.detect(f1, mkpf1);
detector.detect(f2, mkpf2);
System.out.println("Keypoints detected for f2: " + mkpf2.total());
System.out.println("Keypoints detected for f1: " + mkpf1.total());
extractor.compute(f1, mkpf1, df1);
extractor.compute(f2, mkpf2, df2);
System.out.println("Keypoints after extractor for f2: " + mkpf2.rows());
System.out.println("Keypoints after extractor for f1: " + mkpf1.rows());
Keypoints are never removed causing wrong behavior. Can anybody tell me why o how to solve this? Thanks!
Under what circumstances are you expecting that a descriptor can't be computed? compute() only removes a Keypoint if it can't compute a descriptor for it, which is a rather rare occurance.
For whatever pair of stereo images you'll see that the number of computed descriptors (df1 and df2) is less than the number of keypoints after extractor.compute() is called. The problem is that you'll not know what descriptors belongs to what keypoints because the relation keypoint i to descriptor i doesn't hold and "uncomputed" keypoints are never removed no matter what. I've tested the exact same code on c++ and it works perfectly. Keypoints are removed just after the extractor.compute() call but unfortunately fails in Java.