opencv notes-image translation

Image translation:
according to the specified direction and distance, move to the corresponding position

格式:cv.warpAffine(img,M,dsize)

parameter:
Insert picture description here

Implementation code:

import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
# 中文显示配置
plt.rcParams['font.sans-serif']=['SimHei']      # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False        # 用来正常显示负号

# 载入图片
img0 = cv.imread("img/img1.jpeg")

# 图像平移
rows, cols = img0.shape[:2]
# 简单理解:x方向移动100个单位,y方向移动50个单位
M = np.float32([[1,0,100],[0,1,50]])
# 输出图像大小
dst = cv.warpAffine(img0,M,(cols*3,rows*3))

# 图像显示
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10,8),dpi=100)
axes[0].imshow(img0[:,:,::-1])
axes[0].set_title("原图")
axes[1].imshow(dst[:,:,::-1])
axes[1].set_title("平移后图片")
plt.show()

Operation result:
Insert picture description herecv Xiaobai, hope the big guy will give pointers

Guess you like

Origin blog.csdn.net/weixin_45666249/article/details/114945318