Opencv从入门到精通(四):在图像上画线/矩形/圆/文字

import cv2
import numpy as np

img = np.ones(shape=(512, 512, 3))  # HWC
print(img.dtype)
# img[:] = 255, 0, 0 # 整个图像变为蓝色

# 画直线
# cv2.line(img, (0, 0), (100, 100), color=(0, 255, 0), thickness=3) 

# 画对角线
cv2.line(img, (0, 0), (img.shape[1], img.shape[0]), color=(0, 255, 0), thickness=3)  

# 画矩形 cv2.FILLED填满
cv2.rectangle(img, (0, 0), (200, 100), color=(0, 0, 255), thickness=cv2.FILLED) 

# 画圆
cv2.circle(img, (100, 50), 30, (255, 0, 0))  

# 写文字 fontScale:字体比例
cv2.putText(img, ' OPEN CV ', org=(300, 100), fontFace=cv2.FONT_ITALIC, fontScale=0.5, color=(0, 0, 255), thickness=3)


cv2.imshow('Img', img)
cv2.waitKey(0)

你可能感兴趣的:(#,Opencv,opencv)