# -*- coding: utf-8 -*-
import sys
import cv2
import numpy as np
if __name__=="__main__":
if len(sys.argv)>1 :
img = cv2.imread(sys.argv[1],cv2.IMREAD_ANYCOLOR)
else:
print('None')
h,w=img.shape[:2]#原图的高宽
src=np.array([[0,0],[w-1,0],[0,h-1],[w-1,h-1]],np.float32)
dst=np.array([[50,50],[w/3,50],[50,h-1],[w-1,h-1]],np.float32)#至少四组值
p=cv2.getPerspectiveTransform(src,dst)#计算投影变换矩阵
r=cv2.warpPerspective(img,p,(w,h),borderValue=(255,255,255))#投影变换
cv2.imshow("image",img)
cv2.circle(r, center=(w-100,h-100), radius=8, color=(0,0,255), thickness=1, lineType=8, shift=0)
#center,raduis,thickness,lineType必须为int;thickness为轮廓粗细,-1代表绘制实心圆;linetype为圆边界类型;shift为中心坐标和半径的小数位数
cv2.imshow("warpPerspective",r)
cv2.waitKey(0)
cv2.destroyAllWindows()
01-01