CoolFace
Apppublic

k20hcmus/FishEye8K

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
3likes
draw.py37 linesDownload Raw Back to utils
1import numpy as np2import cv23 4palette = (2 ** 11 - 1, 2 ** 15 - 1, 2 ** 20 - 1)5 6 7def compute_color_for_labels(label):8    """9    Simple function that adds fixed color depending on the class10    """11    color = [int((p * (label ** 2 - label + 1)) % 255) for p in palette]12    return tuple(color)13 14 15def draw_boxes(img, bbox, identities=None, offset=(0,0)):16    for i,box in enumerate(bbox):17        x1,y1,x2,y2 = [int(i) for i in box]18        x1 += offset[0]19        x2 += offset[0]20        y1 += offset[1]21        y2 += offset[1]22        # box text and bar23        id = int(identities[i]) if identities is not None else 0    24        color = compute_color_for_labels(id)25        label = '{}{:d}'.format("", id)26        t_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_PLAIN, 2 , 2)[0]27        cv2.rectangle(img,(x1, y1),(x2,y2),color,3)28        cv2.rectangle(img,(x1, y1),(x1+t_size[0]+3,y1+t_size[1]+4), color,-1)29        cv2.putText(img,label,(x1,y1+t_size[1]+4), cv2.FONT_HERSHEY_PLAIN, 2, [255,255,255], 2)30    return img31 32 33 34if __name__ == '__main__':35    for i in range(82):36        print(compute_color_for_labels(i))37