OpenCV: knnMatch function does not work correctly

I am writing an android program to find an object. I am using ORB descriptors. But I need to use the knnMatch function. It doesn't seem to work correctly in my opinion, and I don't know why.

Here's an example of my code:

 .
 .
 Mat frameDescriptors = new Mat();
    FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
    DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);  
    List<List<DMatch>> knnMatches=new ArrayList<List<DMatch>>();
.
.
.
detector.detect(mRgba, frameKeypoints);
extractor.compute(mRgba, frameKeypoints, frameDescriptors);  
.
.
.
matcher.knnMatch(imageDescriptors,frameDescriptors, knnMatches, 5);
for(int q=0;q<knnMatches.size();q++){
                Log.d("PPP","Writing for q=" +q);
                for(int w=0;w<knnMatches.get(q).size();w++){
                    Log.d("PPP","Distance for: "+ q + "-" + w + " qIdx: " + knnMatches.get(q).get(w).queryIdx +" tIdx: " +knnMatches.get(q).get(w).trainIdx + " " + knnMatches.get(q).get(w).distance);
                }
}

      

And here is a sample log result:

Writing for q = 0
Distance for: 0-0 qIdx: 206 tIdx: 30 7.0
Distance for: 0-1 qIdx: 206 tIdx: 45 8.0
Distance for: 0-2 qIdx: 206 tIdx: 55 9.0
Distance for: 0-3 qIdx: 206 tIdx: 5 10.0
Distance for: 0-4 qIdx: 206 tIdx: 15 10.0
Writing for q = 1
Distance for: 1-0 qIdx: 206 tIdx: 30 7.0
Distance for: 1-1 qIdx: 206 tIdx: 45 8.0
Distance for: 1-2 qIdx: 206 tIdx: 55 9.0
Distance for: 1-3 qIdx: 206 tIdx: 5 10.0
Distance for: 1-4 qIdx: 206 tIdx: 15 10.0
Writing for q = 2
Distance for: 2-0 qIdx: 206 tIdx: 30 7.0
Distance for: 2-1 qIdx: 206 tIdx: 45 8.0
Distance for: 2-2 qIdx: 206 tIdx: 55 9.0
Distance for: 2-3 qIdx: 206 tIdx: 5 10.0
Distance for: 2-4 qIdx: 206 tIdx: 15 10.0

You can see that everyone is exactly the same trainIdx and every time I get the same distance. I don't know where I am going wrong. Can you help me?

+3
java android image-processing opencv


source to share


No one has answered this question yet

Check out similar questions:

2248
Is a finally block always executable in Java?
1722
Why is this code using random lines to print "hello world"?
1492
Does Java support default parameter values?
1338
Why does Java have transient fields?
1253
What does "Could not find or load main class" mean?
1249
How does the Java loop for each loop work?
938
What does "synchronized" mean?
6
OpenCV: running FLANN on a cluster
1
SIFT / SURF / ORB to detect and target a simple template
0
How to get the distance between pixels from two matched functions



All Articles
Loading...
X
Show
Funny
Dev
Pics