MCPcopy Create free account
hub / github.com/FoundationVision/ByteTrack / vis

Function vis

yolox/utils/visualize.py:11–42  ·  view source on GitHub ↗
(img, boxes, scores, cls_ids, conf=0.5, class_names=None)

Source from the content-addressed store, hash-verified

9
10
11def vis(img, boxes, scores, cls_ids, conf=0.5, class_names=None):
12
13 for i in range(len(boxes)):
14 box = boxes[i]
15 cls_id = int(cls_ids[i])
16 score = scores[i]
17 if score < conf:
18 continue
19 x0 = int(box[0])
20 y0 = int(box[1])
21 x1 = int(box[2])
22 y1 = int(box[3])
23
24 color = (_COLORS[cls_id] * 255).astype(np.uint8).tolist()
25 text = '{}:{:.1f}%'.format(class_names[cls_id], score * 100)
26 txt_color = (0, 0, 0) if np.mean(_COLORS[cls_id]) > 0.5 else (255, 255, 255)
27 font = cv2.FONT_HERSHEY_SIMPLEX
28
29 txt_size = cv2.getTextSize(text, font, 0.4, 1)[0]
30 cv2.rectangle(img, (x0, y0), (x1, y1), color, 2)
31
32 txt_bk_color = (_COLORS[cls_id] * 255 * 0.7).astype(np.uint8).tolist()
33 cv2.rectangle(
34 img,
35 (x0, y0 + 1),
36 (x0 + txt_size[0] + 1, y0 + int(1.5*txt_size[1])),
37 txt_bk_color,
38 -1
39 )
40 cv2.putText(img, text, (x0, y0 + txt_size[1]), font, 0.4, txt_color, thickness=1)
41
42 return img
43
44
45def get_color(idx):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected