概要:

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

 

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


homography单应性

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

homography单应性

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

homography单应性


Python实现:


[python] view plain copy
  1. import cv2  
  2. import numpy as np  
  3. import pylab as pl  
  4.    
  5. if __name__ == '__main__' :  
  6.       
  7.    
  8.     # Read source image.  
  9.     im_src = cv2.imread('book2.jpg')  
  10.     # Four corners of the book in source image  
  11.     pts_src = np.array([[167.0264.0], [482.0798.0], [1079.0403.0],[613.084.0]])  
  12.    
  13.    
  14.     # Read destination image.  
  15.     im_dst = cv2.imread('book1.jpg')  
  16.     # Four corners of the book in destination image.  
  17.     pts_dst = np.array([[193.0742.0],[996.0874.0],[1059.0157.0],[266.0145.0]])  
  18.    
  19.     # Calculate Homography  
  20.     h, status = cv2.findHomography(pts_src, pts_dst)  
  21.        
  22.     # Warp source image to destination based on homography  
  23.     im_out = cv2.warpPerspective(im_src, h, (im_dst.shape[1],im_dst.shape[0]))  
  24.        
  25.     pl.figure(), pl.imshow(im_src[:, :, ::-1]), pl.title('src'),  
  26.     pl.figure(), pl.imshow(im_dst[:, :, ::-1]), pl.title('dst')  
  27.     pl.figure(), pl.imshow(im_out[:, :, ::-1]), pl.title('out'), pl.show()  #show dst   
结果:

homography单应性homography单应性homography单应性

相关文章:

  • 2021-10-05
  • 2021-09-30
  • 2021-05-13
  • 2021-11-21
  • 2022-01-04
  • 2021-08-01
  • 2021-04-17
  • 2021-05-14
猜你喜欢
  • 2021-06-10
  • 2021-11-25
  • 2021-09-02
  • 2021-05-01
  • 2022-12-23
  • 2021-12-04
  • 2021-07-28
相关资源
相似解决方案