题目:根据三角形顶点使用OPENCV绘制三角形
import numpy as np
from img_pakage.ocv import drawL_C_E_R_P,img_zero
img_pil = img_zero(800,800)
pts = np.array([(250,100),(350,500),(600,380)],np.int32)
drawL_C_E_R_P.polylines(img_pil,[pts],True,(255,255,2555),3,0)
threePoints = ['A','B','C']
for i in range(3):
img_pil = drawL_C_E_R_P.draw_text(img_pil,pts[i][0],pts[i][1]-5,threePoints[i]+f'({pts[i][0]},{pts[i][1]})',(255,255,2555))
drawL_C_E_R_P.show(img_pil)
if __name__ =='__main__':
pass
import numpy as np
from img_pakage.ocv import drawL_C_E_R_P,img_zero
img_pil = img_zero(900,800)
pts = np.array([(250,100),(350,500),(600,380)],np.int32)
drawL_C_E_R_P.polylines(img_pil,[pts],True,(255,255,2555),3,1)
#圈点三角形三个顶点
threePoints = ['A','B','C']
for i in range(3):
img_pil = drawL_C_E_R_P.draw_text(img_pil,pts[i][0]+35,pts[i][1]-15,threePoints[i]+f'({pts[i][0]},{pts[i][1]})',(255,255,2555))
drawL_C_E_R_P.circle(img_pil, pts[i][0], pts[i][1], 25, (255, 255, 2555), 3)
drawL_C_E_R_P.show(img_pil,'三角形01',820,600,3)
if __name__ =='__main__':
pass
import numpy as np
from img_pakage.ocv import drawL_C_E_R_P,img_zero
import numpy as np
from img_pakage.ocv import drawL_C_E_R_P,img_zero
img_pil = img_zero(900,800)
pts = np.array([(250,100),(350,500),(600,380)],np.int32)
drawL_C_E_R_P.polylines(img_pil,[pts],True,(255,255,2555),3,1)
#圈点三角形三个顶点
threePoints = ['A','B','C']
for i in range(3):
img_pil = drawL_C_E_R_P.draw_text(img_pil,pts[i][0]+35,pts[i][1]-15,threePoints[i]+f'({pts[i][0]},{pts[i][1]})',(255,255,2555))
drawL_C_E_R_P.circle(img_pil, pts[i][0], pts[i][1], 25, (255, 255, 2555), -1)
drawL_C_E_R_P.show(img_pil,'三角形实心效果图03',820,600,0)
if __name__ =='__main__':
pass
输出:
源代码文件下载链接