我已经匹配了两个图像描述符的两个向量:
cv::Ptr<BinaryDescriptorMatcher> bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher();
std::vector<std::vector<cv::DMatch> > matches;
float maxDist = 10.0;
bdm->radiusMatch(descr2, descr1, matches, maxDist);
// descr1 from image1, descr2 from image2
std::vector<char> mask(matches.size(), 1);
但现在我想从两张图片中找出找到的匹配。
这不起作用:
drawMatches(gmlimg, keylines, walls, keylines1, matches, outImg, cv::Scalar::all(-1), cv::Scalar::all(-1), mask, DrawLinesMatchesFlags::DEFAULT);
这两点都没有:
drawLineMatches(gmlimg, keylines, walls, keylines1, matches, outImg, cv::Scalar::all(-1), cv::Scalar::all(-1), mask, DrawLinesMatchesFlags::DEFAULT);
答案 0 :(得分:0)
由于您将匹配项设置为std::vector< std::vector<cv::DMatch> >
,这是您在使用BinaryDescriptorMatcher
时所使用的匹配项,因此您可以按如下方式绘制匹配项:
std::vector<DMatch> matches_to_draw;
std::vector< std::vector<DMatch> >matches_from_matcher;
std::vector< cv::Keypoint > keypoints_Object, keypoints_Scene; // Keypoints
// Iterate through the matches from descriptor
for(unsigned int i = 0; i < matches_from_matcher.size(); i++)
{
if (matches_from_matcher[i].size() >= 1)
{
cv::DMatch v = matches[i][0];
/*
May be you can add a filtering here for the matches
Skip it if you want to see all the matches
Something like this - avg is the average distance between all keypoint pairs
double difference_for_each_match = fabs(keypoints_Object[v.queryIdx].pt.y
- keypoints_Scene[v.trainIdx].pt.y);
if( (fabs (avg - difference_for_each_match)) <= 5))
{
matches_to_draw.push_back(v);
}
*/
// This is for all matches
matches_to_draw.push_back(v);
}
}
cv::drawMatches(image, keypoints_Object, walls, keypoints_Scene, matches_to_draw, outImg, cv::Scalar::all(-1), cv::Scalar::all(-1), mask, DrawLinesMatchesFlags::DEFAULT);`
outImg应该有匹配和绘制的关键点。
让我知道它是否有帮助!