(1)CV2中的绘图函数:
cv2.line() 绘制线条 cv2.circle() 绘制圆 cv2.rectangle() 绘制矩形 cv2.ellipse() 绘制椭圆 cv2.putText() 添加注记
(2)注释
img表示需要绘制的图像 color表示线条的颜色,采用颜色矩阵 thickness表示线条的粗细 linestype表示线条的线型
(3)实例
"""
@author: LIFEI
@time: 2023/8/27 10:21
@file: im_rd.py
@project: main.py
@describe: TODO
"""
import cv2
import numpy as npdef mask ( img_img) : draw_marker = cv2. drawMarker( img_img, ( 256 , 256 ) , ( 255 , 0 , 0 ) , cv2. MARKER_CROSS, thickness= 8 ) draw_line = cv2. line( draw_marker, ( 50 , 50 ) , ( 450 , 450 ) , ( 0 , 0 , 255 ) , thickness= 2 ) circle = cv2. circle( draw_line, ( 447 , 100 ) , 63 , ( 0 , 255 , 0 ) , 1 ) rect = cv2. rectangle( circle, ( 300 , 300 ) , ( 400 , 400 ) , ( 255 , 0 , 0 ) , 3 ) ellipse = cv2. ellipse( rect, ( 120 , 120 ) , ( 100 , 50 ) , 0 , 0 , 360 , 255 , 1 ) text = cv2. putText( ellipse, 'Open_cv' , ( 400 , 500 ) , cv2. FONT_HERSHEY_SIMPLEX, 4 , [ 255 , 30 , 56 ] , 2 ) return textif __name__ == '__main__' : img = cv2. imread( r"D:\data\img.png" ) result = mask( img) cv2. imshow( "img" , result) cv2. waitKey( 0 ) cv2. destroyAllWindows( )
(4)结果