OpenCV 图形变换

1、图片缩小

matScale=np.float32([[0.5,0,0],[0,0.5,0]])
dst=cv2.warpAffine(img,matScale,(int(height/2),int(width/2)))
cv2.imshow('dst',dst)
cv2.imshow('src',img)
cv2.waitKey(0)

2、图片移位

# matScale=np.float32([[1,0,100],[0,1,200]])
# dst=cv2.warpAffine(img,matScale,(height,width))
# cv2.imshow('dst',dst)
# cv2.waitKey(0)

3,变形

# 图片变形
#src 3-->dst 3 (左上角 左下角  右上角 3点)
matSrc=np.float32([[0,0],[0,height-1],[width-1,0]])
matDst=np.float32([[50,50],[300,height-200],[width-300,100]])

#组合
matAffine=cv2.getAffineTransform(matSrc,matDst)#变换矩阵
dst=cv2.warpAffine(img,matAffine,(width,height))#将图像经过变换矩阵变换
cv2.imshow('img',dst)
cv2.waitKey(0)

4、图像旋转

matRotate=cv2.getRotationMatrix2D((height*0.2,width*0.2),45,0.2)#参1:旋转中心点  参2:旋转角度  参3旋转后大小比例
dst=cv2.warpAffine(img,matRotate,(height,width))
cv2.imshow('img',dst)
cv2.waitKey(0)
原文地址:https://www.cnblogs.com/wbdream/p/10287278.html