in models/01_YoloV5/01_Pytorch/processing.py [0:0]
def draw_box(self, image, bbox, label, color=None):
if color is None:
color = [rnd.randint(0, 255) for _ in range(3)]
x1, y1, x2, y2 = bbox
cv2.rectangle(image, (x1, y1), (x2, y2), color=color, thickness=5)
# Assure label is visible
h, w = image.shape[:2]
thickness = 2 if w < 1000 else 3 if w < 2000 else 6
font_scale = 0.8 if w < 1000 else 2 if w < 2000 else 3
lbl_h = 20 if h < 1000 else 70 if h < 2000 else 150
lbl_y1 = y1 - lbl_h
lbl_y2 = y1
if lbl_y1 < 0:
lbl_y1, lbl_y2 = y2, y2 + lbl_h
elif lbl_y2 > h:
lbl_y1, lbl_y2 = y2 - lbl_h, y2
cv2.rectangle(image, (x1, lbl_y1), (x2, lbl_y2), color=color, thickness=cv2.FILLED)
cv2.putText(image, label, (x1 + 5, lbl_y2 - 2), cv2.FONT_HERSHEY_SIMPLEX, fontScale=font_scale,
color=(255, 255, 255), thickness=thickness, lineType=1)