File size: 7,136 Bytes
d4b77ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import json
import os
import re
import numpy as np
import cv2

from glob import glob
from fire import Fire

def process(dataset_name):
    with open(os.path.join(dataset_name, 'list.txt'), 'r') as f:
        lines = f.readlines()
    videos = [x.strip() for x in lines]

    # if dataset_name == 'VOT2016':
    meta_data = {}
    tags = []
    for video in videos:
        with open(os.path.join(dataset_name, video, "groundtruth.txt"),'r') as f:
            gt_traj = [list(map(float, x.strip().split(','))) for x in f.readlines()]

        img_names = sorted(glob(os.path.join(dataset_name, video, 'color', '*.jpg')))
        if len(img_names) == 0:
            img_names = sorted(glob(os.path.join(dataset_name, video, '*.jpg')))
        im = cv2.imread(img_names[0])
        img_names = [x.split('/', 1)[1] for x in img_names]
        # tag
        if dataset_name in ['VOT2018', 'VOT2019']:
            tag_file = os.path.join(dataset_name, video, 'camera_motion.tag')
            if os.path.exists(tag_file):
                with open(tag_file, 'r') as f:
                    camera_motion = [int(x.strip()) for x in f.readlines()]
                    camera_motion += [0] * (len(gt_traj) - len(camera_motion))
            else:
                print("File not exists: ", tag_file)
                camera_motion = [] # [0] * len(gt_traj)

            tag_file = os.path.join(dataset_name, video, 'illum_change.tag')
            if os.path.exists(tag_file):
                with open(tag_file, 'r') as f:
                    illum_change = [int(x.strip()) for x in f.readlines()]
                    illum_change += [0] * (len(gt_traj) - len(illum_change))
            else:
                print("File not exists: ", tag_file)
                illum_change = [] # [0] * len(gt_traj)

            tag_file = os.path.join(dataset_name, video, 'motion_change.tag')
            if os.path.exists(tag_file):
                with open(tag_file, 'r') as f:
                    motion_change = [int(x.strip()) for x in f.readlines()]
                    motion_change  += [0] * (len(gt_traj) - len(motion_change))
            else:
                print("File not exists: ", tag_file)
                motion_change = [] # [0] * len(gt_traj)

            tag_file = os.path.join(dataset_name, video, 'size_change.tag')
            if os.path.exists(tag_file):
                with open(tag_file, 'r') as f:
                    size_change = [int(x.strip()) for x in f.readlines()]
                    size_change  += [0] * (len(gt_traj) - len(size_change))
            else:
                print("File not exists: ", tag_file)
                size_change  = [] # [0] * len(gt_traj)

            tag_file = os.path.join(dataset_name, video, 'occlusion.tag')
            if os.path.exists(tag_file):
                with open(tag_file, 'r') as f:
                    occlusion = [int(x.strip()) for x in f.readlines()]
                    occlusion  += [0] * (len(gt_traj) - len(occlusion))
            else:
                print("File not exists: ", tag_file)
                occlusion  = [] # [0] * len(gt_traj)
            img_files = os.path.join('VOT2019', )
            meta_data[video] = {'video_dir': video,
                                'init_rect': gt_traj[0],
                                'img_names': img_names,
                                'width': im.shape[1],
                                'height': im.shape[0],
                                'gt_rect': gt_traj,
                                'camera_motion': camera_motion,
                                'illum_change': illum_change,
                                'motion_change': motion_change,
                                'size_change': size_change,
                                'occlusion': occlusion}
        elif 'VOT2016' == dataset_name:
            tag_file = os.path.join(dataset_name, video, 'camera_motion.label')
            if os.path.exists(tag_file):
                with open(tag_file, 'r') as f:
                    camera_motion = [int(x.strip()) for x in f.readlines()]
                    camera_motion += [0] * (len(gt_traj) - len(camera_motion))
            else:
                print("File not exists: ", tag_file)
                camera_motion = [] # [0] * len(gt_traj)

            tag_file = os.path.join(dataset_name, video, 'illum_change.label')
            if os.path.exists(tag_file):
                with open(tag_file, 'r') as f:
                    illum_change = [int(x.strip()) for x in f.readlines()]
                    illum_change += [0] * (len(gt_traj) - len(illum_change))
            else:
                print("File not exists: ", tag_file)
                illum_change = [] # [0] * len(gt_traj)

            tag_file = os.path.join(dataset_name, video, 'motion_change.label')
            if os.path.exists(tag_file):
                with open(tag_file, 'r') as f:
                    motion_change = [int(x.strip()) for x in f.readlines()]
                    motion_change  += [0] * (len(gt_traj) - len(motion_change))
            else:
                print("File not exists: ", tag_file)
                motion_change = [] # [0] * len(gt_traj)

            tag_file = os.path.join(dataset_name, video, 'size_change.label')
            if os.path.exists(tag_file):
                with open(tag_file, 'r') as f:
                    size_change = [int(x.strip()) for x in f.readlines()]
                    size_change  += [0] * (len(gt_traj) - len(size_change))
            else:
                print("File not exists: ", tag_file)
                size_change  = [] # [0] * len(gt_traj)

            tag_file = os.path.join(dataset_name, video, 'occlusion.label')
            if os.path.exists(tag_file):
                with open(tag_file, 'r') as f:
                    occlusion = [int(x.strip()) for x in f.readlines()]
                    occlusion  += [0] * (len(gt_traj) - len(occlusion))
            else:
                print("File not exists: ", tag_file)
                occlusion  = [] # [0] * len(gt_traj)

            meta_data[video] = {'video_dir': video,
                                'init_rect': gt_traj[0],
                                'img_names': img_names,
                                'gt_rect': gt_traj,
                                'width': im.shape[1],
                                'height': im.shape[0],
                                'camera_motion': camera_motion,
                                'illum_change': illum_change,
                                'motion_change': motion_change,
                                'size_change': size_change,
                                'occlusion': occlusion}
        else:
            meta_data[video] = {'video_dir': video,
                                'init_rect': gt_traj[0],
                                'img_names': img_names,
                                'gt_rect': gt_traj,
                                'width': im.shape[1],
                                'height': im.shape[0]}


    json.dump(meta_data, open(dataset_name+'.json', 'w'))

if __name__ == '__main__':
    Fire(process)