In the reality of image manipulation software, often encountered is not given to zoom how many times, but by the user in the interface of the software to choose how big the region, or select a few points, so how to calculate the transformation matrix in this case? From the front to know the transformation matrix is a 2X3 matrix, indicating that there are six unknowns, and secondary school algebra knowledge to solve the six unknowns, then the system of equations at least three equations should be linked to prepare three equations of the prerequisites, is to have three sets of coordinates. Therefore, the transformation matrix can be computed simply by finding the coordinates of three different points in the region chosen by the user. If three sets of coordinates [0, 0], [200, 0], [0, 200] are given, and after the transformation the new coordinates are [0, 0], [128, 0], [0, 50], what function is used to compute this matrix? This is done using the getAffineTransform function in OpenCV.
This is demonstrated by the following example.
#python 3.7.4,opencv4.1 #Cai Junsheng /caimouse/article/details/51749579 # import cv2 import numpy as np # Path to the image imgname = "" #Read the picture image = (imgname, cv2.IMREAD_COLOR) # Height and width of the image h,w = [:2] # Calculate the 2X3 matrix from the target coordinates, then call warpAffine to execute the src = ([[0, 0], [200, 0], [0, 200]], np.float32) dst = ([[0, 0], [128, 0], [0, 50]], np.float32) A1 = (src, dst) d1 = (image, A1, (w, h), borderValue = 125) # Display the image after the operation ("d1",d1) #Display Image ("image", image) # Wait for user input, then delete all windows (0) ()
The output is as follows:
The use of coordinate transformations eliminates the need to know whether the middle is rotated first, or whether the operation is translated first.
summarize
The above is a small introduction to the Python in OpenCV to realize the effect of affine transformations - coordinate transformation, I hope to help you, if you have any questions please leave me a message, I will reply to you in a timely manner. I would also like to thank you very much for your support of my website!
If you find this article helpful, please feel free to reprint it, and please note the source, thank you!