2.6图像镜像
import cv2
import numpy as np
img = cv2.imread('lenacolor.png',1)
cv2.imshow('src',img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
deep = imgInfo[2]
newImgInfo = (height*2,width,deep)
dst = np.zeros(newImgInfo,np.uint8)
for i in range(0,height):
for j in range(0,width):
dst[i,j] = img[i,j]
dst[height*2-i-1,j] = img[i,j]
for i in range(0,width):
dst[height,i] = (0,0,255)
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
2.7图像仿射变换
图像仿射变换详解
图像透视变换详解
import cv2
import numpy as np
img = cv2.imread('lenacolor.png',1)
cv2.imshow('src',img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
matSrc = np.float32([[0,0],[0,height-1],[width-1,0]])
matDst = np.float32([[50,50],[300,300],[50,300]])
matAffine = cv2.getAffineTransform(matSrc,matDst)
dst = cv2.warpAffine(img,matAffine,(width,height))
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
2.8图像旋转
import cv2
import numpy as np
img = cv2.imread('lenacolor.png',1)
cv2.imshow('src',img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
matRotate = cv2.getRotationMatrix2D((height*0.5,width*0.5),45,1)
dst = cv2.warpAffine(img,matRotate,(height,width))
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()