Feature points matching using SIFT between two images
<p>I wonder why there is not good matching between two images using SIFT.
The matched images is shown below.
<a href="https://i.stack.imgur.com/un6dv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/un6dv.jpg" alt="enter image description here"></a>
Original images are </p>

<p><a href="https://i.stack.imgur.com/FF9Ca.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FF9Ca.jpg" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/Z6ZuA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z6ZuA.jpg" alt="enter image description here"></a></p>

<p>My program is as follow.</p>

<pre><code>int imagematching(Mat &amp;img1, Mat &amp; img2, std::vector&lt;Point2f&gt; &amp;first_keypoints, std::vector&lt;Point2f&gt; &amp;second_keypoints){
    int max_keypoints = 500;

    Ptr&lt;SIFT&gt; detector = SIFT::create();
    Ptr&lt;SIFT&gt; extractor = SIFT::create();

    //--Step 1: Key point detection
    std::vector&lt;KeyPoint&gt; keypoints1, keypoints2;
    //-- Step 2: Calculate descriptors (feature vectors)
    Mat descriptors1, descriptors2;

    detector-&gt;detect( img1, keypoints1 );
    detector-&gt;detect( img2, keypoints2 );   

    extractor-&gt;compute(img1, keypoints1, descriptors1);
    extractor-&gt;compute(img2, keypoints2, descriptors2);    

    FlannBasedMatcher matcher;


    vector&lt;DMatch&gt; matches;
    matcher.match(descriptors1, descriptors2, matches);   

    double max_dist = 0; double min_dist = 999999;

    //-- Quick calculation of max and min distances between keypoints
    for( int i = 0; i &lt; descriptors1.rows; i++ )
    { 
      double dist = matches[i].distance;
      if( dist &lt; min_dist ) min_dist = dist;
      if( dist &gt; max_dist ) max_dist = dist;
    }

    printf("-- Max dist : %f \n", max_dist );
    printf("-- Min dist : %f \n", min_dist );
    //-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
    std::vector&lt; DMatch &gt; good_matches;

    for( int i = 0; i &lt; descriptors1.rows; i++ )
    { 
      if( matches[i].distance &lt; 3*min_dist )
         { good_matches.push_back( matches[i]); }
    }
    matches.clear();

    Mat img_matches;
    drawMatches( img1, keypoints1, img2, keypoints2,
               good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
               vector&lt;char&gt;(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

    descriptors1.release();
    descriptors2.release();

    //-- Localize the object
    //std::vector&lt;Point2f&gt; first_keypoints;
    //std::vector&lt;Point2f&gt; second_keypoints;

    for( int i = 0; i &lt; good_matches.size(); i++ )
    {
       //cout &lt;&lt; i &lt;&lt; " :";
       //-- Get the keypoints from the good matches
       if( keypoints1[ good_matches[i].queryIdx ].pt.x &gt; 0 &amp;&amp; keypoints1[ good_matches[i].queryIdx ].pt.y &gt; 0 
               &amp;&amp; keypoints2[ good_matches[i].trainIdx ].pt.x &gt; 0 &amp;&amp; keypoints2[ good_matches[i].trainIdx ].pt.y &gt; 0){
           first_keypoints.push_back( keypoints1[ good_matches[i].queryIdx ].pt );
           //cout &lt;&lt; "first point" &lt;&lt; keypoints1[ good_matches[i].queryIdx ].pt &lt;&lt; endl;

           second_keypoints.push_back( keypoints2[ good_matches[i].trainIdx ].pt );
           //cout &lt;&lt; "second point" &lt;&lt; keypoints2[ good_matches[i].trainIdx ].pt &lt;&lt; endl;
       }
    }
    keypoints1.clear();
    keypoints2.clear();
    good_matches.clear();
    //-- Show detected matches
    imshow( "Good Matches &amp; Object detection", img_matches );
    waitKey(0);

    return SUCCESS;
}
</code></pre>