单应性

                          
               

概要:

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

 

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


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


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


Python实现:



   
   
  1. import cv2
  2. import numpy as np
  3. import pylab as pl
  4. if __name__ == '__main__' :
  5.    
  6.     # Read source image.
  7.     im_src = cv2.imread( 'book2.jpg')
  8.     # Four corners of the book in source image
  9.     pts_src = np.array([[ 167.0, 264.0], [ 482.0, 798.0], [ 1079.0, 403.0],[ 613.0, 84.0]])
  10.     # Read destination image.
  11.     im_dst = cv2.imread( 'book1.jpg')
  12.     # Four corners of the book in destination image.
  13.     pts_dst = np.array([[ 193.0, 742.0],[ 996.0, 874.0],[ 1059.0, 157.0],[ 266.0, 145.0]])
  14.     # Calculate Homography
  15.     h, status = cv2.findHomography(pts_src, pts_dst)
  16.     
  17.     # Warp source image to destination based on homography
  18.     im_out = cv2.warpPerspective(im_src, h, (im_dst.shape[ 1],im_dst.shape[ 0]))
  19.     
  20.     pl.figure(), pl.imshow(im_src[:, :, :: -1]), pl.title( 'src'),
  21.     pl.figure(), pl.imshow(im_dst[:, :, :: -1]), pl.title( 'dst')
  22.     pl.figure(), pl.imshow(im_out[:, :, :: -1]), pl.title( 'out'), pl.show()  #show dst
结果:




           
               
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值