title: OpenCV: How to get inlier points using findHomography()/findFundamental() and RANSAC
body: <p>OpenCV does not provide a RANSAC-function per se or at least in such a form that you can just call it and be done with it (e.g. <code>cv::ransac(...)</code>). All functions/methods that are able to use RANSAC have a flag that enables it. However this is not always useful if you actually want to do something else with the inliers RANSAC computes after you have estimated a homography/fundamental matrix for example create a nice plot in Octave or similar software/library of the points, apply additional algorithms on the remaining set of filtered matches etc.</p>
  
  <p>After matching two images one gets a vector of matches. Along with that we have of course 2 sets of keypoints (one for each image) that were used in the matching process. Using matches and keypoints we create two vectors of points (e.g. <code>cv::Point2f points</code>) and pass these to <code>findHomography()</code>. From <a href="https://stackoverflow.com/questions/10059162/getting-the-5-points-used-by-ransac-in-findhomography-opencv-for-android">this</a> and <a href="https://stackoverflow.com/questions/15815304/opencv-c-findhomography-mask-values-meaning">this</a> posts I discovered how exactly the inliers are marked using a mask, that we pass to that function. Each row inside the mask relates to an inlier/outlier. However I am unable to figure out how to use the row-index information from my two sets of points. Looking at OpenCV's source code didn't get me too far. In <code>findFundamental()</code> (similar to <code>findHomography()</code> when it comes to its signature and the mask-part) they use <code>compressPoints()</code>, which seems to somehow combine the two sets we have as input (source and destination points) into one. While testing in order to determine the nature of the mask I tried 2 sets of matched points (converted <code>cv::Keypoints</code> to <code>cv::Point2f</code> - a standard procedure). Each set contains 300 points so in total we have 600 points. The returned mask contains 300 rows (values are not important for this topic at hand).</p>
  
  <p>EDIT: While writing this I discovered the answer (see below) but decided to post this question anyway in case someone needs this information as soon as possible and in compact form. Note that we still need one of OpenCV's function, which support RANSAC. So if you have a set of points but no intention of computing homography or fundamental matrix, this is obviously not the way and I dare say that I was unable to find anything useful in OpenCV's API that can help avoid this obstacle therefore you need to use an external library.</p>