File size: 1,471 Bytes
df9abf4
 
 
 
 
b0547a1
df9abf4
 
 
 
 
 
 
 
8c31b90
 
df9abf4
8c31b90
df9abf4
 
8c31b90
 
 
 
 
 
 
 
 
 
 
 
0d0ab89
8b5d61a
0d0ab89
8b5d61a
0d0ab89
 
 
db457c7
 
 
 
 
 
3ff595d
 
24aac30
3ff595d
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
import os
import glob
import json
from pathlib import Path
from collections import OrderedDict
import ffmpeg


def read_json(fname):
    fname = Path(fname)
    with fname.open('rt') as handle:
        return json.load(handle, object_hook=OrderedDict)


def get_configs(base_path, filename_pattern="*.json"):
    configs = []
    glob_pattern = os.path.join(base_path, filename_pattern)
    file_paths = sorted(glob.glob(glob_pattern))
    for file_path in file_paths:
        file_name = Path(file_path).stem
        config = read_json(file_path)
        config['name'] = file_name
        configs.append(config)
    return configs


def get_display_names(configs):
    display_names = []
    for config in configs:
        display_names.append(config['display_name'])
    return display_names


def get_path_for_viz(basedir, dataset, sequence, model, viz):
    dat_seq = "_".join([dataset["name"], sequence])
    video_path = os.path.join(basedir, model['model_id'], dat_seq, "videos", viz["name"] + ".mp4")
    return video_path


def get_meta_path(basedir, dataset, sequence):
    dat_seq = "_".join([dataset["name"], sequence])
    meta_path = os.path.join(basedir, "meta", dat_seq, "videos", "meta.mp4")
    return meta_path


def get_text_str(height, width, text, fontsize, fontcolor="black"):
    return "drawtext=text='{}':" \
           "fontsize={}:fontcolor={}:" \
           "x=({}-text_w)/2:y=({}-text_h)/2".format(text, fontsize, fontcolor, width, height)