James
James

Reputation: 77

How can i get more inliers when using ransac?

matches = sorted(matches, key = lambda x: x.distance)
src_pts = np.float32([ kp1[m.queryIdx].pt for m in matches ]).reshape(-1,1,2)
dst_pts = np.float32([ kp2[m.trainIdx].pt for m in matches ]).reshape(-1,1,2)
M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)
matchesMask = mask.ravel().tolist()

I'm using the value in matchesMask as the inliers which is proving to be too severely affected by ransac, i tried to get only the first 100 best matches out of matches but the % of outliers was still too high.

Upvotes: 1

Views: 1426

Answers (1)

mr NAE
mr NAE

Reputation: 3372

cv2.findHomography treat a point pair as an inlier if the distance between the source point and the projection of the destination is grater than ransacReprojThreshold (5.0 - in your code):

norm(src_pts[i] - M * dst_pts[i]) > ransacReprojThreshold

ransacReprojThreshold - Maximum allowed reprojection error to treat a point pair as an inlier.

So, If you want to find 100 "best" matches, even if it's reprojection error more than 5.0:

  1. create an array of pairs: (point pair and reprojection error),
  2. sort by reprojection error,
  3. take 100 points with smallest reprojection error.

Upvotes: 1

Related Questions