Ask Your Question
0

NullpointerException when using a descriptor

asked 2013-04-23 05:20:43 -0600

MysticBE gravatar image

updated 2013-04-23 08:11:17 -0600

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?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-04-23 09:10:56 -0600

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.

edit flag offensive delete link more

Comments

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

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-23 09:25:23 -0600 )edit
0

answered 2013-04-23 08:00:18 -0600

Nyenna gravatar image

updated 2013-04-23 08:01:27 -0600

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);
edit flag offensive delete link more

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 ( 2013-04-23 08:23:24 -0600 )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 ( 2013-04-23 09:14:08 -0600 )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 ( 2013-04-23 09:22:40 -0600 )edit

Question Tools

Stats

Asked: 2013-04-23 05:20:43 -0600

Seen: 756 times

Last updated: Apr 23 '13