我正在使用OpenCV 3.3。 我想在 Vector Dmatch 类型的对象上使用 OpenCV C++ match 函数。 目标是将单个查询图像中的描述符与多个图像列表中的描述符进行匹配。 我知道,当这个函数用于将单个图像中的描述符与另一个图像中的描述符匹配时,对应于每个图像上每个匹配描述符的两个关键点索引将存储在向量中的每个 Dmatch 对象中。
例如,如果我这样做
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 );
那么,如果我想访问匹配的关键点,对于每个 i 来说,这是一个不如 matches.size(( 的整数,那么
int idx=matches[i].trainIdx;
int idy=matches[i].queryIdx;
point2f matched_point1=keypoints1[idx].pt;
point2f matched_point2=keypoints2[idy].pt;
但是,当我尝试将单个查询图像中的描述符与多个图像列表中的描述符匹配时会发生什么,因为每个 Dmatch 对象只能容纳两个索引,而我想匹配两个以上的图像。 即:
vector<Mat> descriptors1;
Mat descriptors2;
matcher.add( descriptors1 );
matcher.train();
matcher.match(descriptors2, matches );
这些指数意味着什么?
int idx=matches[i].trainIdx;
int idy=matches[i].queryIdx;
您可以在循环浏览图像时将所有训练图像的匹配索引值存储到列表中。然后,您可以选择适当的匹配点并根据需要使用它们。