3-10 图片缩放

# [[A1 A2 B1],[A3 A4 B2]]
# [[A1 A2],[A3 A4]] [[B1],[B2]]
# newX = A1*x + A2*y+B1
# newY = A3*x + A4*y+B2
# x->x*0.5 y->y*0.5
# newX = 0.5*x

import cv2
import numpy as np
img = cv2.imread('image0.jpg',1)
cv2.imshow('src',img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
#matScale = np.float32([[A1 A2 B1],[A3 A4 B2]]) # 定义一个2*3的矩阵
matScale = np.float32([[0.5,0,0],[0,0.5,0]]) # 缩放矩阵
dst = cv2.warpAffine(img,matScale,(int(width/2),int(height/2))) #定义一个仿射方法 原始数据 缩放矩阵 最终生成的图片的宽高信息
cv2.imshow('dst',dst)
cv2.waitKey(0)

猜你喜欢

转载自www.cnblogs.com/ZHONGZHENHUA/p/9686341.html