Reputation: 1347
I have big problems calculating ORB descriptors for keypoints found by SIFT detector. If I try to run a simple example program the whole system freezes and I can't figure out why. The sample code is as follows:
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImageM;
import com.googlecode.javacv.cpp.opencv_core.CvMat;
import com.googlecode.javacv.cpp.opencv_features2d.DescriptorExtractor;
import com.googlecode.javacv.cpp.opencv_features2d.FeatureDetector;
import com.googlecode.javacv.cpp.opencv_features2d.KeyPoint;
import com.googlecode.javacv.cpp.opencv_features2d.ORB;
import com.googlecode.javacv.cpp.opencv_nonfree.SIFT;
public class DescriptorTest {
public static void main(String[] args) {
SIFT sift = new SIFT(0, 3, 0.04, 10, 1.6);
FeatureDetector detector = sift.getFeatureDetector();
ORB orb_descriptor = new ORB(500, 1.2f, 8, 31, 0, 2, 0, 31);
DescriptorExtractor descriptor = orb_descriptor.getDescriptorExtractor();
CvMat image = cvLoadImageM("res/dvd_009_ref.jpg");
KeyPoint keypoints = new KeyPoint();
CvMat descriptors = new CvMat(null);
detector.detect(image, keypoints, null);
System.out.println("Keypoints found: "+ keypoints.capacity());
descriptor.compute(image, keypoints, descriptors);
System.out.println("Descriptors calculated: "+descriptors.rows());
}
}
Does anyone has an idea what the problem is? Would be great :)
Upvotes: 2
Views: 2671
Reputation:
I do not know whether this will be helpful for you or not you may want to check a workaround given here ( http://code.opencv.org/issues/2987 ) by Vladislav Vinogradov (http://code.opencv.org/users/340). Though this is a c++ code I am sure you will get the idea:
void unpackSIFTOctave(const KeyPoint& kpt, int& octave, int& layer, float& scale)
{
octave = kpt.octave & 255;
layer = (kpt.octave >> 8) & 255;
octave = octave < 128 ? octave : (-128 | octave);
scale = octave >= 0 ? 1.f/(1 << octave) : (float)(1 << -octave);
}
This is a known issue for a while and they do not seem to be planning to fix it.
(and yes you may want to keep keypoint's datum since description extraction procedures may use those to be scale/rotation invariant and octave info is usually related how "locally" descriptive a keypoint is and )
Hope this helps, (and does not need to be edited again :) )
V
Upvotes: 1
Reputation: 1347
Ok, so it seems to work if I set the octave of the keypoints to 0. I don't know yet if this is a good idea but i tend to say no. Since for some descriptors the information of the scale-space octave in which the feature has been found is vital.
for(int i = 0; i < keypoints.capacity(); i++) {
KeyPoint kp = keypoints.position(i);
kp.octave(0);
}
keypoints.position(0);
Upvotes: 1