2017-04-03 101 views
1

我已经匹配的两幅图像的描述符的两个向量:如何在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); 
+0

你怎么知道他们不工作?你期望哪场比赛的比赛?对我来说,你应该尝试'cv :: Scalar :: all(255,255,255)',你应该得到白线。另外,你从图像2中获得匹配,但是反过来绘制(但我不知道'gmlimg'是图像1还是2) –

+0

drawLineMatches不起作用,因为匹配必须是std: :vector ,但是我的std :: vector >,因为radiusMatch需要它。 并且drawMatch需要kepoints而不是keylines。 http://docs.opencv.org/3.0-beta/modules/line_descriptor/doc/drawing_functions.html http://docs.opencv.org/2.4.8/modules/features2d/doc/drawing_function_of_keypoints_and_matches .html – Philipp

+0

这与'drawMatches'不起作用的原因不一样吗? –

回答

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应该h为比赛和关键点画出。

让我知道它是否有帮助!