绘图函数
绘图函数 cv2.line(), cv2.rectangle(), cv2.circle(), cv2.ellipse(), cv2.putText()
绘图函数需要的参数为 img:画布图像,color:绘制的色彩, thickness:线条的粗细(-1表示闭合曲线的填充),lineType:线条类型(默认8连接)。
代码
import cv2
import numpy as np
img = np.ones((500, 500, 3), np.uint8)
img = img * 255
# cv2.line(img, start_point, end_point, color, thickness, lineType)
cv2.line(img, (50, 50), (150, 150), (255, 0, 0), 5)
# cv2.rectangle(img, top_left_point, bottom_right_point, color, thickness, lineType)
cv2.rectangle(img, (50, 50), (450, 450), (0, 255, 0), 2, cv2.LINE_AA)
# cv2.circle(img, center, radius, color, thickness, lineType)
cv2.circle(img, (250, 250), 80, (0, 0, 255), -1)
# cv2.ellipse(img, center, long_short_radius, rotate_angle, start_angle, end_angle, color, thickness, lineType)
cv2.ellipse(img, (250, 250), (100, 80), 0, 0, 360, (255, 0, 0), 3)
# cv2.putText(img, str, start_point, fontFace, fontScale, color, thickness, lineType)
cv2.putText(img, "OPENCV", (150, 100), fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=2, color=(0, 0, 0), thickness=2)
cv2.imshow('img', img)
cv2.waitKey()
cv2.destroyAllWindows()
结果显示
参考
1.OpenCV-Python官方教程