?opencv API :
cv2.warpAffine
def warpAffineTest(imgDir):
img=cv2.imread(imgDir,cv2.IMREAD_GRAYSCALE)
h,w=img.shape[:2]
A1=np.array([[0.5,0,0],[0,0.5,0]],np.float32)# 缩小2倍
d1=cv2.warpAffine(img,A1,(h,w),borderValue=125)
cv2.imshow("A1 affine",d1)
A2=np.array([[0.5,0,w/4],[0,0.5,h/4]],np.float32)# 先缩小2倍,在平移
d2=cv2.warpAffine(img,A2,(h,w),borderValue=125)
cv2.imshow("A2 affine",d2)
A3=cv2.getRotationMatrix2D((w/2.0,h/2.0),30,1) #旋转30
d3=cv2.warpAffine(img,A3,(h,w),borderValue=125)
cv2.imshow("A3 afine",d3)
cv2.waitKey(0)
效果图:
?
|