How can I retrieve the points of the homography computed findHomography and RANSAC?

Tongxin Wang picture Tongxin Wang · Jul 23, 2015 · Viewed 7.5k times · Source

I am new to OpenCV. I noticed that the line

Mat H = findHomography( obj, scene, CV_RANSAC );

helps to find the homography H using RANSAC.

However, I need the locations of the 'purified' matching points after RANSAC and I simply cannot find which function I can use. I need a function that uses RANSAC and returns the matching points' locations after RANSAC.

Answer

Miki picture Miki · Jul 29, 2015

findHomography can optionally provide the mask of inliers and outliers (inliers are what you call purified matching).

C++: Mat findHomography(InputArray srcPoints, InputArray dstPoints, int method=0, double ransacReprojThreshold=3, OutputArray mask=noArray() )

Python: cv2.findHomography(srcPoints, dstPoints[, method[, ransacReprojThreshold[, mask]]]) → retval, mask

You can use only inliers (i.e. points with corresponding mask value equals to 1) when doing your match.