图片移动、旋转、resize、

image = imread('image.jpg')
M = np.float32([[1,0,250],[0,1,500]])
#X轴右移250个像素,Y轴下移500个像素
#前面的0,1 是在选择坐标轴
shifted = cv2.warpAffine(image, M, (image.shape[1],image.shape[0]))
show(shifted)

#旋转

image = imread('image.jpg')
(h,w) = image.shape[:2]
(cX,cY) = (w/2,h/2)

# (cX,cY)-旋转中心点
# 45-逆时针旋转45度
# 1.0-缩放
M = cv2.getRotationMatrix2D((cX,cY), 45, 1.0)
image = cv2.warpAffine(image, M, (w,h))
show(image)

#resize

#有5种插值方法
image = cv2.resize(image, (width, high))
# 5种插值方法:
image = imread('image.jpg')
width = 150
high = 150 
# 最邻近
image = cv2.resize(image, (width, high), interpolation=cv2.INTER_NEAREST)
# 双线性
image = cv2.resize(image, (width, high), interpolation=cv2.INTER_LINEAR)
# 基于像素区域
image = cv2.resize(image, (width, high), interpolation=cv2.INTER_AREA)
# 立方插值
image = cv2.resize(image, (width, high), interpolation=cv2.INTER_CUBIC)
# 兰索斯插值
image = cv2.resize(image, (width, high), interpolation=cv2.INTER_LANCZOS4)

show(image)
print(image.shape)

 

posted @ 2020-08-30 09:08  yunshangyue  阅读(248)  评论(0编辑  收藏  举报