2017-04-03 6 views
1

私は2枚の画像の記述子の二つのベクトルマッチしています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); 

をしかし、今私は、2枚の画像から見つかったマッチを描きたいです。

これは動作しません:

drawMatches(gmlimg, keylines, walls, keylines1, matches, outImg, cv::Scalar::all(-1), cv::Scalar::all(-1), mask, DrawLinesMatchesFlags::DEFAULT); 

そして、これはどちらも:

あなたが BinaryDescriptorMatcherを使用するときに使用するものです std::vector< std::vector<cv::DMatch> >、としてマッチを取得しているので
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から1までマッチしていますが、逆の方法で描画しています(しかし、 'gmlimg'がイメージ1か2であるかどうかわかりません) –

+0

drawLineMatchesは動作しません。マッチはstd: :ベクトルが、私はstd :: vector >です。なぜなら、radiusMatchはそれを必要とするからです。 drawMatchesにはキーポイントが必要であり、キーポイントが必要です。 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<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);` 

outmgは、マッチと描画されたキーポイントを表示します。

助けてくれたら教えてください!

関連する問題