# Is there a way to compute a RANSAC based affine transformation?

I know of findHomography(), but that computes all kinds of perspective transformations. I'd like to restrict the degrees of freedom to translation, rotation and scale.

There is a method estimateRigidTransform in the video module, but it's not RANSAC based.

Am I missing something?

Or do I have to implement it on my own?

edit retag close merge delete

Sort by ยป oldest newest most voted

I solved this problem by first finding a homography and then estimating the rigid transform using only the homography's inlier matches.

more

That's dangerous... You might get wrong inliers e.g. if you have a degenerated perspective transformation that maps all points to infinity your inlier criterion is basically useless. You must check the homography for sanity (which is non-trivial in practice).

( 2013-06-30 16:32:03 -0500 )edit

I know. These degenerated transformations are annoying. But they usually occur in image pairs that don't match anyway. Do you have a better solution?

( 2013-07-01 02:43:41 -0500 )edit

Afaik this doesn't exist, so you need to implement it on your own.

more

Yes it does :

    # Compute a rigid transformation (without depth, only scale + rotation + translation)


It is RANSAC based, as you can see there : https://docs.opencv.org/4.0.0/d9/d0c/...

estimateAffinePartial2D (
InputArray  from,
InputArray  to,
OutputArray     inliers = noArray(),
int     method = RANSAC,
double  ransacReprojThreshold = 3,
size_t  maxIters = 2000,
double  confidence = 0.99,
size_t  refineIters = 10
)

more

How to get the scale factor from Mx,i = cv2.estimateAffinePartial2D(src_pts, dst_pts)? scale = np.sqrt((Mx[0,1] * Mx[0,1]) + (Mx[0,0] * Mx[0,0])) right?

more

Official site

GitHub

Wiki

Documentation