opencv学习10——图像的定点仿射变换

一、

1.仿射变换是对多种变换的综合,包括平移、缩放、旋转

2.定点仿射变换,基于给定3点的变化前后坐标,得出对应的变换关系,调用函数得出变换矩阵,并根据矩阵对图像进行仿射变换

3.cv2.getAffineTransform(pst1,pst2),

pst1,原矩阵;pst2,变换后矩阵。形式为二维列表,维度[3,2],代表3个点变化前后的坐标

二、

# 定点仿射变换

import cv2
import numpy as np

img = cv2.imread('image01.jpg',1)
imgHeight,imgWidth,imgMode = img.shape

matSrc = np.float32([[0,0],[0,imgHeight-1],[imgWidth-1,0]])
matDst = np.float32([[50,50],[200,imgHeight-200],[imgWidth-200,200]])

matAffine = cv2.getAffineTransform(matSrc,matDst)
dstImg = cv2.warpAffine(img,matAffine,(imgWidth,imgHeight))

cv2.imshow('image', dstImg)

cv2.waitKey(0)
cv2.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/nominior/article/details/82810099
今日推荐