用python&OpenCV实现图片的移动
这里需要提前配置好OpenCV环境,才能使用cv2包,可查相关配置博客,本文不作赘述
import cv2
import math
import numpy as np
#图片移动函数
def move(img):
height, width, channels = img.shape
emptyimage0 = img.copy()
x = 18
y = 18
for i in range(height):
for j in range(width):
if i >= x and j >= y:
emptyimage0[i, j] = img[i - x][j - y]
else:
emptyimage0[i, j] = (0, 0, 0)
return emptyimage0
#导入图片
img = cv2.imread("F:\\erciyuan.jpg")
#设置窗口
cv2.namedWindow("image")
#显示图片
SaltImage=move(img)
cv2.imshow("image",img)
cv2.imshow("ss",SaltImage)
cv2.waitKey(0)
运行结果可见,ss为移动后的图片