• Python: 3.8.11
  • Opencv – python: 4.1.2.30
  • Opencv – contrib – python: 4.1.2.30
  • OS: Ubuntu Kylin 20.04
  • Conda: 4.10.1
  • Pycharm: 2021.1.3

Code sample

import cv2
import numpy as np

image = cv2.imread("opencv-image.png")

height, width = image.shape[:2]

# Three points in the original image
point1 = np.float32([[10.10], [15.20], [50.50]])
The three points of # point1 are converted to correspond to the three points on the resulting image
point2 = np.float32([[8.11], [14.19], [53.47]])
M = cv2.getAffineTransform(point1, point2)
print(M)

dst = cv2.warpAffine(image, M, (width, height))

cv2.imshow("image", image)
cv2.imshow("dst", dst)

cv2.waitKey(0)
cv2.destroyAllWindows()

Copy the code

The results

/ home/coder/anaconda3 / bin/python3.8 / home/coder/PycharmProjects pythonProject2 / main py [[1.05, 0.075 to 3.25] [0.2 0.7 2. ]] Process finished withexit code 0

Copy the code

Learning to recommend

  • Python documentation – English
  • Python documentation – Chinese
  • Python code PEP
  • Google version of the Python specification
  • opencv
  • Opencv help manual
  • Python source code
  • Python PEP
  • Optimal kirin
  • The nuggets platform
  • Gitee platform


Python is open source, cross-platform, interpretive, interactive, and worth learning. Python’s design philosophy: elegant, unambiguous, simple. Advocate one way, preferably only one way to do one thing. Code should be written in accordance with specifications to facilitate communication and understanding. Every language has its own unique ideas. Beginners need to change their thinking, practice and accumulate.