3-11 图片仿射变换

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]
# src 3->dst 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)   # 仿射变换矩阵 mat 1 src 2 dst 原来图片上这三个点在dst上新的位置

dst = cv2.warpAffine(img,matAffine,(width,height)) # 图片的宽高信息
cv2.imshow('dst',dst)
cv2.waitKey(0)

 

posted on 2018-09-21 15:23  绿茵好莱坞  阅读(318)  评论(0编辑  收藏  举报

导航