import cv2
class_name = "car"
ptLeftTop = np.array([40, 145])
textleftop = []
ptRightBottom =np.array([365, 400])
point_color = (0, 255, 0)
thickness = 2
lineType = 4
src = cv2.imread('data/detect/000020.jpg')
cv2.namedWindow('image', cv2.WINDOW_AUTOSIZE)
src = np.array(src)
cv2.rectangle(src, tuple(ptLeftTop), tuple(ptRightBottom), point_color, thickness, lineType)
t_size = cv2.getTextSize(class_name, 1, cv2.FONT_HERSHEY_PLAIN, 1)[0]
textlbottom = ptLeftTop + np.array(list(t_size))
cv2.rectangle(src, tuple(ptLeftTop), tuple(textlbottom), point_color, -1)
ptLeftTop[1] = ptLeftTop[1] + (t_size[1]/2 + 4)
cv2.putText(src, class_name , tuple(ptLeftTop), cv2.FONT_HERSHEY_PLAIN, 1.0, (255, 0, 255), 1)
print(src.shape)
cv2.imshow('image', src)
cv2.waitKey(0)
cv2.destroyAllWindows()
结果: