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,