2017-04-03 77 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爲比賽和關鍵點畫出。

讓我知道它是否有幫助!