单应性变换(Homography)

概要:

来源:http://www.learnopencv.com/homography-examples-using-opencv-python-c/

 

单应性变换就是一个平面到另一个平面的映射关系。

 

Center

 

如图,两张图片中相同颜色的点叫做corresponding Points,比如两个红点就是一对corresponding points。单应性矩阵(Homography)就是一个从一张图像到另一张图像映射关系的转换矩阵(3*3)。可以由下面的公式来表示:

Center

以图像中的红点为例,可以将单应性变换写成如下形式:

Center

 

 

Python实现:

 

import cv2
import numpy as np
import pylab as pl
 
if __name__ == '__main__' :
    
 
    # Read source image.
    im_src = cv2.imread('book2.jpg')
    # Four corners of the book in source image
    pts_src = np.array([[167.0, 264.0], [482.0, 798.0], [1079.0, 403.0],[613.0, 84.0]])
 
 
    # Read destination image.
    im_dst = cv2.imread('book1.jpg')
    # Four corners of the book in destination image.
    pts_dst = np.array([[193.0, 742.0],[996.0, 874.0],[1059.0, 157.0],[266.0, 145.0]])
 
    # Calculate Homography
    h, status = cv2.findHomography(pts_src, pts_dst)
     
    # Warp source image to destination based on homography
    im_out = cv2.warpPerspective(im_src, h, (im_dst.shape[1],im_dst.shape[0]))
     
    pl.figure(), pl.imshow(im_src[:, :, ::-1]), pl.title('src'),
    pl.figure(), pl.imshow(im_dst[:, :, ::-1]), pl.title('dst')
    pl.figure(), pl.imshow(im_out[:, :, ::-1]), pl.title('out'), pl.show()  #show dst 

结果:

CenterCenterCenter

 

 

 

 

  • 14
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值