title: opencv c++ compare keypoint locations in different images
body: <p>When comparing 2 images via <code>feature extraction</code>, how do you compare <code>keypoint</code> distances so to disregard those that are obviously incorrect?</p>
  
  <p>I've found when comparing similar images against each other, most of the time it can fairly accurate, but other times it can throws matches that are completely separate.</p>
  
  <p>So I'm after a way of looking at the 2 sets of <code>keypoints</code> from both images and determining whether the matched <code>keypoints</code> are relatively in the same locations on both. As in it knows that <code>keypoints</code> 1, 2, and 3 are so far apart on image 1, so the corresponding keypoints matched on image 2 should be of a fairly similar distance away from each other again.</p>
  
  <p>I've used <code>RANSAC</code> and <code>minimum distance</code> checks in the past but only to some effect, they don't seem to be as thorough as I'm after.</p>
  
  <p>(Using <code>ORB</code> and <code>BruteForce</code>)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Changed <em>"x, y, and z"</em> to <em>"1, 2, and 3"</em></p>
  
  <p><strong>EDIT 2</strong> -- I'll try to explain further with quick Paint made examples:</p>
  
  <p>Say I have this as my image:</p>
  
  <p><img src="https://i.stack.imgur.com/OcxMb.png" alt="enter image description here"></p>
  
  <p>And I give it this image to compare against:</p>
  
  <p><img src="https://i.stack.imgur.com/tWk7L.png" alt="enter image description here"></p>
  
  <p>Its a cropped and squashed version of the original, but obviously similar.</p>
  
  <p>Now, say you ran it through <code>feature detection</code> and it came back with these results for the <code>keypoints</code> for the two images:</p>
  
  <p><img src="https://i.stack.imgur.com/IaRV2.png" alt="enter image description here"><img src="https://i.stack.imgur.com/mzozd.png" alt="enter image description here"></p>
  
  <p>The <code>keypoints</code> on both images are in roughly the same areas, and proportionately the same distance away from each other. Take the <code>keypoint</code> I've circled, lets call it <strong><em>"Image 1 Keypoint 1"</em></strong>.</p>
  
  <p><img src="https://i.stack.imgur.com/rcDzn.png" alt="enter image description here"></p>
  
  <p>We can see that there are 5 <code>keypoints</code> around it. Its these distances between them and <strong><em>"Image 1 Keypoint 1"</em></strong> that I want to obtain so to compare them against <strong><em>"Image 2 Keypoint 1"</em></strong> and its 5 surround <code>keypoints</code> in the same area (see below) so as to not just compare a <code>keypoint</code> to another <code>keypoint</code>, but to compare <strong>"known shapes"</strong> based off of the locations of the <code>keypoints</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/rjZ42.png" alt="enter image description here"></p>
  
  <p>--</p>
  
  <p>Does that make sense?</p>