File size: 645 Bytes
a8d5de3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)