OpenCV:函数knnMatch无法正常工作

时间:2012-03-15 10:15:02

标签: java android image-processing opencv

我为Android编写程序来查找对象。我使用ORB描述符。但我需要使用函数knnMatch。在我看来,它不能正常工作,我不知道为什么。

以下是我的代码示例:

 .
 .
 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);
                }
}

以下是日志结果示例:

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

你可以看到所有都是完全相同的trainIdx,每次我得到相同的距离。我不知道我哪里弄错了。你可以帮我吗?

0 个答案:

没有答案