Max Etienne
Max Etienne

Reputation: 1

Storing keypoints indexes from matching a single query image with a list of several images

I am using OpenCV 3.3. I want to use the OpenCV C++ match function on an object of type Vector Dmatch. The goal is to match descriptors from a single query image with the descriptors from a list of several images. I know that when this function is used to match descriptors from a single image to descriptors from another single image, the two keypoints indexes corresponding to each matching descriptors on each image are stored into each Dmatch object from the vector.

For example, if I do

Mat img_1=imread("path1...");
Mat img_2=imread("path2...");

vector<KeyPoint> keypoints_1, keypoints_2;
Mat descriptors_1, descriptors_2;

detector->detectAndCompute(img_1, Mat(), keypoints_1, descriptors_1 );
detector->detectAndCompute( img_2, Mat(), keypoints_2, descriptors_2 );

FlannBasedMatcher matcher;
vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );

then if I want to access the keypoints that were matched, for each i that is an int that is inferior to matches.size(), then

int idx=matches[i].trainIdx;
int idy=matches[i].queryIdx;

point2f matched_point1=keypoints1[idx].pt;
point2f matched_point2=keypoints2[idy].pt;

However what happens when I try to match descriptors from a single query image with the descriptors from a list of several images, since each Dmatch object can only hold two indexes, whilst I want to match more than two images. i.e:

vector<Mat> descriptors1;
Mat descriptors2;

matcher.add( descriptors1 );
matcher.train();

matcher.match(descriptors2, matches );

what will those indexes mean?

int idx=matches[i].trainIdx;
int idy=matches[i].queryIdx;

Upvotes: 0

Views: 434

Answers (1)

Sakthi Geek
Sakthi Geek

Reputation: 411

You can store the matched index values for all the train images to a list while looping through the images. You can then select the appropriate matched points and play with them however you want.

Upvotes: 0

Related Questions