如何在Opencv中绘制匹配项
How to draw matches in Opencv?
我已经匹配了两个图像的两个描述符向量:
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);
由于您获得的匹配项为 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);`
出局应该有匹配和关键点。
让我知道它是否有帮助!
相关文章:
- 如何使用 opencv 绘制绿色矩形?
- Opencv,在图像中的对象周围绘制一个框
- OPENCV C .在for循环中在不同的图像像素上绘制一个圆圈(应在每个循环运行时将图像打开)
- OPENCV-快速 简介:如何使用drawmatchesflags :: draw_rich_keypoints绘制关键
- 如何在Opencv中绘制匹配项
- OpenCV c++ 断言失败调用绘制轮廓
- 在OpenCV中绘制带有梯度颜色的线
- 在框架上使用 OpenCV 绘制矩形
- 如何在OpenCV中绘制线路
- 绘制凸度缺陷C OPENCV
- 如何在opencv中使用matlab c ++库绘制点
- 使用OpenCV教程中的任何一个进行人脸检测是否有任何函数可以计算绘制在人脸上的矩形的大小
- 从图像中裁剪椭圆形状,而不是在OpenCV中在内部绘制
- 使用 OpenCV C++绘制最大轮廓的凸包
- 使用Opencv/c++在Stream中的两点之间绘制aline
- 绘制opencv中多个移动对象的轨迹
- 如何在OpenFrameworks/OpenCV中使用HSV颜色绘制正方形
- OpenCV - 仅在绘制单应性时打印对象名称
- 使用 OpenCV 和 C++ 在图像中绘制投资回报率
- OpenCV 3.1 绘制轮廓 '(-215) npoints > 0'