MCPcopy
hub / github.com/WongKinYiu/PyTorch_YOLOv4 / plot_one_box

Function plot_one_box

utils/plots.py:54–65  ·  view source on GitHub ↗
(x, img, color=None, label=None, line_thickness=None)

Source from the content-addressed store, hash-verified

52
53
54def plot_one_box(x, img, color=None, label=None, line_thickness=None):
55 # Plots one bounding box on image img
56 tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line/font thickness
57 color = color or [random.randint(0, 255) for _ in range(3)]
58 c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3]))
59 cv2.rectangle(img, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA)
60 if label:
61 tf = max(tl - 1, 1) # font thickness
62 t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0]
63 c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3
64 cv2.rectangle(img, c1, c2, color, -1, cv2.LINE_AA) # filled
65 cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)
66
67
68def plot_wh_methods(): # from utils.general import *; plot_wh_methods()

Callers 2

detectFunction · 0.90
plot_imagesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected