First time here? Check out the FAQ!

Ask Your Question
0

NullpointerException when using a descriptor

asked Apr 23 '13

MysticBE gravatar image

updated Apr 23 '13

I am currently trying to compare 2 images with OpenCV. One image is on the SD card, the other image is made when pressing a button, and that picture will then be compared to the one on the SD card. I am using FAST detection (which works fine, i get back a lot of keypoints), and then I want to use a FREAK descriptor, but this is where it all goes wrong.

 MatOfKeyPoint points1 = new MatOfKeyPoint();   
        private FeatureDetector detector;
        private DescriptorExtractor descriptor;

psuedo code for the fast detection, which works

            fast1.detect(mIntermediateMat,points1);         
            // descriptor
            descriptor2 = DescriptorExtractor.create(DescriptorExtractor.FREAK);        
            descriptor2.compute(mIntermediateMat, points1, descriptors);

I get the next error in the compute part of the descriptor line:

04-23 11:58:03.840: E/AndroidRuntime(18729): FATAL EXCEPTION: main 04-23 11:58:03.840: E/AndroidRuntime(18729): java.lang.NullPointerException 04-23 11:58:03.840: E/AndroidRuntime(18729): at org.opencv.features2d.DescriptorExtractor.compute(DescriptorExtractor.java:106) 04-23 11:58:03.840: E/AndroidRuntime(18729): at be.artesis.findmymovie.camera$2.onClick(camera.java:267)

When running the debug mode it looks like the descriptors field in descriptor2.compute is null. Am I wrong when thinking that is has to be null untill computed, since we use the FREAK algorithm to find the descriptors?

I have no idea what is wrong at the moment, does anyone know what needs to be done? Did I do some bad initialization?

Preview: (hide)

2 answers

Sort by » oldest newest most voted
0

answered Apr 23 '13

MysticBE gravatar image

As i thought already, the initialization wasn't how it's supposed to be. Needed to add Mat descriptors = new Mat(); just before the detector.

Preview: (hide)

Comments

Please accept your own solution as answer so people see that this topic is solved :)

StevenPuttemans gravatar imageStevenPuttemans (Apr 23 '13)edit
0

answered Apr 23 '13

Nyenna gravatar image

updated Apr 23 '13

What is "points" (in your last line of code)? Shouldn't it be "points1"?

And are you sure of your syntax? Maybe it is correct, but I use the following:

cv::FastFeatureDetector detector(50);
cv::FREAK extractor;

detector.detect(img, points);
extractor.compute(img, points, descriptors);
Preview: (hide)

Comments

yes it should, that points stood there because i did it for the 2 images, but just showed one here for the code. My syntax is Java based, you probably use the native code?

MysticBE gravatar imageMysticBE (Apr 23 '13)edit

Yes, I am. So you mean that it works for the first image but not for the second? Can you show the code for the first image?

Nyenna gravatar imageNyenna (Apr 23 '13)edit

they both work fine, i just copy pasted the wrong line of code ;) I fixed it by just adding Mat descriptors = new Mat(); and now it works. Thank you for all your help

MysticBE gravatar imageMysticBE (Apr 23 '13)edit

Question Tools

Stats

Asked: Apr 23 '13

Seen: 790 times

Last updated: Apr 23 '13