Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understood you're question correctly, I assume that you want the keypoint matches in <code>std::vector&lt;cv::DMatch&gt;</code> for the purpose of drawing them with the OpenCV <code>cv::drawMatches</code> or usage with some similar OpenCV function. Since I was also doing matching "by hand" recently, here's my code that draws up arbitrary matches contained originally in a <code>std::vector&lt;std::pair &lt;int, int&gt; &gt; aMatches</code> and displays them in a window:</p> <pre><code>const cv::Mat&amp; pic1 = img_1_var; const cv::Mat&amp; pic2 = img_2_var; const std::vector &lt;cv::KeyPoint&gt; &amp;feats1 = img_1_feats; const std::vector &lt;cv::KeyPoint&gt; &amp;feats2 = img_2_feats; // you of course can work directly with original objects // but for drawing you only need const references to // images &amp; their corresponding extracted feats std::vector &lt;std::pair &lt;int, int&gt; &gt; aMatches; // fill aMatches manually - one entry is a pair consisting of // (index_in_img_1_feats, index_in_img_2_feats) // the next code draws the matches: std::vector &lt;cv::DMatch&gt; matches; matches.reserve((int)aMatches.size()); for (int i=0; i &lt; (int)aMatches.size(); ++i) matches.push_back(cv::DMatch(aMatches[i].first, aMatches[i].second, std::numeric_limits&lt;float&gt;::max())); cv::Mat output; cv::drawMatches(pic1, feats1, pic2, feats2, matches, output); cv::namedWindow("Match", 0); cv::setWindowProperty("Match", CV_WINDOW_FULLSCREEN, 1); cv::imshow("Match", output); cv::waitKey(); cv::destroyWindow("Match"); </code></pre> <p>Alternatively, if you need fuller information about the matches for purposes more complicated than drawing then you might also want to set the distance between matches to a proper value. E.g. if you want to calculate distances using <em>L2</em> distance, you should replace the following line:</p> <pre><code>for (int i=0; i &lt; (int)aMatches.size(); ++i) matches.push_back(cv::DMatch(aMatches[i].first, aMatches[i].second, std::numeric_limits&lt;float&gt;::max())); </code></pre> <p>with this (note, for this a reference to feature descriptor vectors is also needed):</p> <pre><code>cv::L2&lt;float&gt; cmp; const std::vector &lt;std::vector &lt;float&gt; &gt; &amp;desc1 = img_1_feats_descriptors; const std::vector &lt;std::vector &lt;float&gt; &gt; &amp;desc2 = img_2_feats_descriptors; for (int i=0; i &lt; (int)aMatches.size(); ++i){ float *firstFeat = &amp;desc1[aMatches[i].first]; float *secondFeat = &amp;desc2[aMatches[i].second]; float distance = cmp(firstFeat, secondFeat, firstFeat-&gt;size()); matches.push_back(cv::DMatch(aMatches[i].first, aMatches[i].second, distance)); } </code></pre> <p>Note that in the last snippet, <code>descX[i]</code> is a descriptor for <code>featsX[i]</code>, each element of the inner vector being one component of the descriptor vector. Also, note that all descriptor vectors should have the same dimensionality.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload