Rishabh Uikey
wip
a8d5de3
import cv2
import random
def visualize(image_path, detections, output_path):
image = cv2.imread(image_path)
colors = {}
for det in detections:
gid = det["group_id"]
if gid not in colors:
rng = random.Random(gid)
colors[gid] = [rng.randint(0, 255) for _ in range(3)]
x1,y1,x2,y2 = det["bbox"]
cv2.rectangle(image,(x1,y1),(x2,y2),colors[gid],3)
cv2.putText(
image,
f"G{gid}",
(x1,y1-5),
cv2.FONT_HERSHEY_SIMPLEX,
0.6,
colors[gid],
2
)
cv2.imwrite(output_path,image)