几何变换类型
- 保距变换 isometry
- 相似变换 similarity
- 仿射变换 affine
- 射影变换 projective -> homography
What is Homography?
A Homography is a transformation ( a 3×3 matrix ) that maps the points in one image to the corresponding points in the other image.
- homography只针对同一平面
How to calculate a Homography ?
摄影变换的自由度为8,一对点能产生两个方程,共需要4对对应点,即可求取H矩阵;如超过4对,通过最小二乘法或RANSAC求取最优参数
理论推导
假设一对对应点和
有,其中
当有n对点时,,对A进行SVD分解,即,取的最后一列求解h,再转换成矩阵即得到
[U,S,V]=svd(A);
h=V(:,9);
H= reshape(h,3,3);
工程实践
If you have more than 4 corresponding points, it is even better. OpenCV will robustly estimate a homography that best fits all corresponding points.
Usually, these point correspondences are found automatically by matching features like SIFT or SURF between the images.
'''
pts_src and pts_dst are numpy arrays of points
in source and destination images. We need at least
4 corresponding points.
'''
h, status = cv2.findHomography(pts_src, pts_dst)
'''
The calculated homography can be used to warp
the source image to destination. Size is the
size (width,height) of im_dst
'''
im_dst = cv2.warpPerspective(im_src, h, size)
Application
- 图像矫正
- 图像扫描
- 虚拟广告牌 虚拟广告牌
网友评论