Welcome to Raspberry Pi 4B repository
3.Picture Shift
Picture shift
Convert the original image src to the target image dst by the conversion matrix M:
dst(x, y) = src(M11x + M12y+M13, M21x+M22y+M23)
Moving the original image src 200 pixels to the right and 100 pixels to down, the corresponding relationship is:
dst(x, y) = src(x+200, y+100)
Complete the above expression according to the formula, as shown below.
dst(x, y) = src(1·x + 0·y + 200, 0·x + 1·y + 100)
According to the above expression, we can determine the value of each element in the corresponding conversion matrix M, as shown below.
M11=1
M12=0
M13=200
M21=0
M22=1
M23=100
Substituting the above values into the transformation matrix M, we can get,
M = []
Next, we directly use the conversion matrix M to call the function cv2.warpAffine () to complete the translation of the image.
Code:
|
After running the following program, two images will be displayed in the jupyterLab control interface, that is original image and the translated image.
|
|

[Original picture] [Shift picture]
According to the above picture, this picture has moved to the lower right corner (200, 100).