# -*- 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()
OpenCV学习(6)-投影变换
最新推荐文章于 2025-11-16 17:38:32 发布
该博客主要介绍了如何使用OpenCV库在Python中进行透视变换。通过读取图片,定义源点和目标点,计算投影变换矩阵,并应用warpPerspective函数,将图像转换为新的视角。此外,还展示了在变换后的图像上绘制圆的方法。
1万+

被折叠的 条评论
为什么被折叠?



