-
Notifications
You must be signed in to change notification settings - Fork 6
/
visualize_objects.py
53 lines (36 loc) · 1.51 KB
/
visualize_objects.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
""" Module for visualizing object detection annotations as a slidehsow-like video.
This module is a bit dated and not connected to STRUDL's API, since the Web UI
for annotations can already show annotations.
"""
import imageio as io
import cv2
from load_data import LoadDetections
from visualize import class_colors, draw
from classnames import get_classnames
from apply_mask import Masker
def slideshow(dataset, outpath, fps=10, repeat=20):
ld = LoadDetections()
dets = ld.custom(dataset)
imfiles = list(set(dets.image_file))
if not imfiles:
return False
cc = class_colors()
mask = Masker(dataset)
classnames = get_classnames(dataset)
with io.get_writer(outpath, fps=fps) as vid:
for imfile in imfiles:
d = dets[dets.image_file == imfile]
# Add "class_name" and "class_index" columns which are missing
d = d.rename(index=str, columns={"type":"class_name"})
indices = [1+classnames.index(x) for x in d['class_name']]
d['class_index'] = indices
im = io.imread(imfile)
im = mask.mask(im, alpha=0.5)
width = float(im.shape[1])
height = float(im.shape[0])
frame = draw(im, d, cc, conf_thresh=-1.0, x_scale=width, y_scale=height)
for i in range(repeat):
vid.append_data(frame)
return True
if __name__ == '__main__':
slideshow('rgb', 'slideshow.mp4')