存储关键点索引,使单个查询图像与多个图像列表匹配

问题描述 投票:0回答:1

我正在使用OpenCV 3.3。我想在Vector Dmatch类型的对象上使用OpenCV C ++匹配函数。目标是将来自单个查询图像的描述符与来自多个图像列表的描述符进行匹配。我知道当使用此函数将来自单个图像的描述符与来自另一个单个图像的描述符进行匹配时,对应于每个图像上的每个匹配描述符的两个关键点索引将从向量存储到每个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,这是一个不及match.size()的int,那么

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;
c++ opencv matcher descriptor
1个回答
0
投票

您可以在循环浏览图像时将所有列车图像的匹配索引值存储到列表中。然后,您可以选择适当的匹配点并随意使用它们。

© www.soinside.com 2019 - 2024. All rights reserved.