18

This is OpenCV's drawMatches() function:

void drawMatches(Mat img1, vector<KeyPoint> keypoints1,
                 Mat img2, vector<KeyPoint> keypoints2,
                 vector<DMatch> matches, 
                 Mat outImg) //want keypoints1[i] = keypoints2[matches[i]]

Notice that matches is of type vector<DMatch>. Here is the DMatch constructor:

DMatch(int queryIdx, int trainIdx, float distance)

Presumably, queryIdx is an index into one set of keypoints, and trainIdx is an index into the other set of keypoints.

The question: Is it true that queryIdx indexes into keypoints1, and trainIdx indexes into keypoints2? Or, is it the other way around?

4

2 に答える 2

33

That depends on how you get matches.

If you call match function in the order:

match(descriptor_for_keypoints1, descriptor_for_keypoints2, matches)

then queryIdx refers to keypoints1 and trainIdx refers to keypoints2, or vice versa.

于 2012-11-10T07:06:12.263 に答える
10

the variable "matches" is a list of DMatch objects.

If we are iterating over this list of DMatch objects, then each item will have the following attributes:

  1. item.distance: This attribute gives us the distance between the descriptors. A lower distance indicates a better match.
  2. item.trainIdx: This attribute gives us the index of the descriptor in the list of train descriptors (in our case, it’s the list of descriptors in the img2).
  3. item.queryIdx: This attribute gives us the index of the descriptor in the list of query descriptors (in our case, it’s the list of descriptors in the img1).
  4. item.imgIdx: This attribute gives us the index of the train image.
于 2015-12-20T11:14:16.387 に答える