DMatch.queryIdx giving out of bounds error against keypoints?!?

469 views
Skip to first unread message

Richard

unread,
Apr 25, 2012, 2:50:05 PM4/25/12
to android...@googlegroups.com
So I have a block of code to detect an instance of an image in List refImages in a screencapture.

I extract each reference images keypoints into a List<List<KeyPoint>> refImagesKey like so

for(int i=0; i<refImages.size(); i++){
   
List<KeyPoint> imgKeyPoints = new ArrayList<KeyPoint>();
   featureDetector
.detect(refImages.get(i), imgKeyPoints);
   refImagesKey
.add(imgKeyPoints);
   obj_descriptor_mats
.add(new Mat());
}
descriptorExtractor
.compute(refImages, refImagesKey, obj_descriptor_mats);
descriptorMatcher
.add(obj_descriptor_mats);

Then I test screen cap against images like so

descriptorMatcher.match(sceneDescriptors, matches);

I filter out good matches...

          double max_dist = 0;
         
double min_dist = 100;
           
int rowCount = matches.size();
           
for(int i=0; i<rowCount; i++){
             
double dist = matches.get(i).distance;
             
if(dist < min_dist) min_dist=dist;
             
if(dist > max_dist) max_dist=dist;
           
}
           
           
List<DMatch> good_matches = new ArrayList<DMatch>();
             
double good_dist = 3*min_dist;
             
for(int i=0; i<rowCount; i++){
               
if(matches.get(i).distance < good_dist){
                  good_matches
.add(matches.get(i));
               
}
             
}

All that works, although I'm starting to question if it does correctly because when I go to get the points associated with each DMatch like so

List<Point> obj = new ArrayList<Point>();
List<Point> scene = new ArrayList<Point>();
int good_matches_size = good_matches.size();
           
for(int i=0; i<good_matches_size; i++){
 
DMatch imatch = good_matches.get(i);
  obj
.add(refImagesKey.get(imatch.imgIdx).get(imatch.queryIdx).pt);
  scene
.add(sceneKeyPoints.get(imatch.trainIdx).pt);
}

I get a Index out of bounds error for the queryIdx.
I cant help but feel I'm just using these properties incorrectly but there seems to be very little documentation on them.
Any advice would be greatly appreciated.

Thanks,

Richard

unread,
Apr 25, 2012, 3:29:25 PM4/25/12
to android...@googlegroups.com
DMatch.imgIdx is always part of the train descriptors. so I had to swap queryIdx and trainIdx.

Rui Marques

unread,
Apr 25, 2012, 6:00:54 PM4/25/12
to android...@googlegroups.com
Yes that is it, it is a common mistake i guess.
Reply all
Reply to author
Forward
0 new messages