Python+OpenCV 给图像添加直线/矩形/圆/文字
1、代码部分
import cv2
import numpy as np
img = np.zeros((640, 640, 3), np.uint8)
img_green = np.zeros((512, 512, 3), np.uint8)
img_green[:] = 78,238,148
cv2.line(img, (350, 350), (img.shape[1], img.shape[0]), (153, 50, 204), 10)
cv2.rectangle(img, (0, 0), (350, 350), (255, 187, 197), cv2.FILLED)
cv2.circle(img, (100, 450), 90, (255, 255, 0), 5)
cv2.putText(img, "DON'T STOP! ", (360, 150), cv2.FONT_HERSHEY_COMPLEX, 1, (245, 255, 220), 3)
cv2.putText(img, "KEEP GOING! ", (360, 200), cv2.FONT_HERSHEY_COMPLEX, 1, (245, 245, 220), 3)
cv2.imshow("Green Image", img_green)
cv2.imshow("Image", img)
cv2.waitKey(0)
2、实现效果