findHomography, getPerspectiveTransform, & getAffineTransform

前端 未结 5 942
情话喂你
情话喂你 2020-12-23 11:35

This question is on the OpenCV functions findHomography, getPerspectiveTransform & getAffineTransform

  1. What is the

5条回答
  •  一个人的身影
    2020-12-23 12:41

    I concur with everything @vasile has written. I just want to add some observations:

    getPerspectiveTransform() and getAffineTransform() are meant to work on 4 or 3 points (respectively), that are known to be correct correspondences. On real-life images taken with a real camera, you can never get correspondences that accurate, not with automatic nor manual marking of the corresponding points.

    There are always outliers. Just look at the simple case of wanting to fit a curve through points (e.g. take a generative equation with noise y1 = f(x) = 3.12x + gauss_noise or y2 = g(x) = 0.1x^2 + 3.1x + gauss_noise): it will be much more easier to find a good quadratic function to estimate the points in both cases, than a good linear one. Quadratic might be an overkill, but in most cases will not be (after removing outliers), and if you want to fit a straight line there you better be mightily sure that is the right model, otherwise you are going to get unusable results.

    That said, if you are mightily sure that affine transform is the right one, here's a suggestion:

    • use findHomography, that has RANSAC incorporated in to the functionality, to get rid of the outliers and get an initial estimate of the image transformation
    • select 3 correct matches-correspondances (that fit with the homography found), or reproject 3 points from the 1st image to the 2nd (using the homography)
    • use those 3 matches (that are as close to correct as you can get) in getAffineTransform()
    • wrap all of that in your own findAffine() if you want - and voila!

提交回复
热议问题