text: # -*- coding: UTF-8 -*-
  import cv2
  import numpy as np
   
  #  仿射变换（图像位置校正）
  
  
  def img_three(imgPath):
      # ---------------------------三点得到一个变换矩阵 ---------------------------
      """
          三点确定一个平面，通过确定三个点的关系来得到转换矩阵
          然后再通过warpAffine来进行变换
      """
      img = cv2.imread(imgPath)
      rows,cols,_ = img.shape
      points1 = np.float32([[50,50],[200,50],[50,200]])
      points2 = np.float32([[10,100],[200,50],[100,250]])
  
      matrix = cv2.getAffineTransform(points1,points2)
      output = cv2.warpAffine(img,matrix,(cols,rows))
  
      cv2.imshow('input1',img)
      cv2.imshow('output1',output)
      cv2.waitKey(0)
      cv2.destroyAllWindows()
  
  def img_four(imgPath):
      # ---------------------------四点得到一个变换矩阵---------------------------
      """
          进行透视变换
          可以先用四个点来确定一个3*3的变换矩阵（cv2.getPerspectiveTransform）
          然后通过cv2.warpPerspective和上述矩阵对图像进行变换
      """
      img = cv2.imread(imgPath)
      rows,cols,_ = img.shape
      points1 = np.float32([[56,65],[368,52],[28,387],[389,390]])
      points2 = np.float32([[0,0],[300,0],[0,300],[300,300]])
  
      matrix = cv2.getPerspectiveTransform(points1,points2)
      # 将四个点组成的平面转换成另四个点组成的一个平面
      output = cv2.warpPerspective(img, matrix, (cols, rows))
      # 通过warpPerspective函数来进行变换
  
      cv2.imshow('input2',img)
      cv2.imshow('output2',output)
      cv2.waitKey(0)
      cv2.destroyAllWindows()
  
  if __name__ == "__main__":
      imgPath = 'src/python-opencv/a.jpg'
      # img_three(imgPath)
      img_four(imgPath)