got-10k / toolkit

Official Python toolkit for generic object tracking benchmark GOT-10k and beyond
http://got-10k.aitestunion.com/
MIT License
555 stars 95 forks source link

show_frame function is super slow, any ideas how to speed it up? #19

Closed yiminglin-ai closed 5 years ago

yiminglin-ai commented 5 years ago

Hi Lianghua, The visualization method in the experiments is slow. I timed the show_frame function and it took 0.5 seconds to visualize one frame of size 1280*720. I tried to improve the speed but still cannot find any good solutions. Do you know any possible alternative methods or libraries to implement the same function?

Best, Yiming

huanglianghua commented 5 years ago

Hi, you can try the OpenCV code, which is much faster:

def show_frame(img, boxes=None, colors=None, thickness=3,
               fig_n=1, delay=1, cvt_code=cv2.COLOR_RGB2BGR):
    if cvt_code is not None:
        img = cv2.cvtColor(img, cvt_code)

    if boxes is not None:
        boxes = np.array(boxes, dtype=np.int32)
        if boxes.ndim == 1:
            boxes = np.expand_dims(boxes, axis=0)

        if colors is None:
            colors = [
                (0, 0, 255),
                (0, 255, 0),
                (255, 0, 0),
                (0, 255, 255),
                (255, 0, 255),
                (255, 255, 0),
                (0, 0, 128),
                (0, 128, 0),
                (128, 0, 0),
                (0, 128, 128),
                (128, 0, 128),
                (128, 128, 0)]
        colors = np.array(colors, dtype=np.int32)
        if colors.ndim == 1:
            colors = np.expand_dims(colors, axis=0)

        for box, color in zip(boxes, colors):
            pt1 = (box[0], box[1])
            pt2 = (box[0] + box[2], box[1] + box[3])
            img = cv2.rectangle(img, pt1, pt2, color.tolist(), thickness)

    winname = 'window_{}'.format(fig_n)
    cv2.imshow(winname, img)
    cv2.waitKey(delay)

I use it myself. May later be integrated in the toolkit.