File size: 13,102 Bytes
25986db | 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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | from typing import Union, TextIO
import numpy as np
from numba import jit
from lib.test.evaluation.data import SequenceList, BaseDataset, Sequence
class VOTDataset(BaseDataset):
"""
VOT2018 dataset
Publication:
The sixth Visual Object Tracking VOT2018 challenge results.
Matej Kristan, Ales Leonardis, Jiri Matas, Michael Felsberg, Roman Pfugfelder, Luka Cehovin Zajc, Tomas Vojir,
Goutam Bhat, Alan Lukezic et al.
ECCV, 2018
https://prints.vicos.si/publications/365
Download the dataset from http://www.votchallenge.net/vot2018/dataset.html
"""
def __init__(self, year=18):
super().__init__()
self.year = year
if year == 18:
self.base_path = self.env_settings.vot18_path
elif year == 20:
self.base_path = self.env_settings.vot20_path
elif year == 22:
self.base_path = self.env_settings.vot22_path
self.sequence_list = self._get_sequence_list(year)
def get_sequence_list(self):
return SequenceList([self._construct_sequence(s) for s in self.sequence_list])
def _construct_sequence(self, sequence_name):
sequence_path = sequence_name
nz = 8
ext = 'jpg'
start_frame = 1
anno_path = '{}/{}/groundtruth.txt'.format(self.base_path, sequence_name)
if self.year == 18 or self.year == 22:
try:
ground_truth_rect = np.loadtxt(str(anno_path), dtype=np.float64)
except:
ground_truth_rect = np.loadtxt(str(anno_path), delimiter=',', dtype=np.float64)
end_frame = ground_truth_rect.shape[0]
frames = ['{base_path}/{sequence_path}/color/{frame:0{nz}}.{ext}'.format(base_path=self.base_path,
sequence_path=sequence_path, frame=frame_num, nz=nz, ext=ext)
for frame_num in range(start_frame, end_frame+1)]
# Convert gt
if ground_truth_rect.shape[1] > 4:
gt_x_all = ground_truth_rect[:, [0, 2, 4, 6]]
gt_y_all = ground_truth_rect[:, [1, 3, 5, 7]]
x1 = np.amin(gt_x_all, 1).reshape(-1,1)
y1 = np.amin(gt_y_all, 1).reshape(-1,1)
x2 = np.amax(gt_x_all, 1).reshape(-1,1)
y2 = np.amax(gt_y_all, 1).reshape(-1,1)
ground_truth_rect = np.concatenate((x1, y1, x2-x1, y2-y1), 1)
elif self.year == 20:
ground_truth_rect = read_file(str(anno_path))
ground_truth_rect = np.array(ground_truth_rect, dtype=np.float64)
end_frame = ground_truth_rect.shape[0]
frames = ['{base_path}/{sequence_path}/color/{frame:0{nz}}.{ext}'.format(base_path=self.base_path,
sequence_path=sequence_path,
frame=frame_num, nz=nz, ext=ext)
for frame_num in range(start_frame, end_frame + 1)]
else:
raise NotImplementedError
return Sequence(sequence_name, frames, 'vot', ground_truth_rect)
def __len__(self):
return len(self.sequence_list)
def _get_sequence_list(self, year):
if year == 18:
sequence_list= ['ants1',
'ants3',
'bag',
'ball1',
'ball2',
'basketball',
'birds1',
'blanket',
'bmx',
'bolt1',
'bolt2',
'book',
'butterfly',
'car1',
'conduction1',
'crabs1',
'crossing',
'dinosaur',
'drone_across',
'drone_flip',
'drone1',
'fernando',
'fish1',
'fish2',
'fish3',
'flamingo1',
'frisbee',
'girl',
'glove',
'godfather',
'graduate',
'gymnastics1',
'gymnastics2',
'gymnastics3',
'hand',
'handball1',
'handball2',
'helicopter',
'iceskater1',
'iceskater2',
'leaves',
'matrix',
'motocross1',
'motocross2',
'nature',
'pedestrian1',
'rabbit',
'racing',
'road',
'shaking',
'sheep',
'singer2',
'singer3',
'soccer1',
'soccer2',
'soldier',
'tiger',
'traffic',
'wiper',
'zebrafish1']
elif year == 20:
sequence_list= ['agility',
'ants1',
'ball2',
'ball3',
'basketball',
'birds1',
'bolt1',
'book',
'butterfly',
'car1',
'conduction1',
'crabs1',
'dinosaur',
'dribble',
'drone1',
'drone_across',
'drone_flip',
'fernando',
'fish1',
'fish2',
'flamingo1',
'frisbee',
'girl',
'glove',
'godfather',
'graduate',
'gymnastics1',
'gymnastics2',
'gymnastics3',
'hand',
'hand02',
'hand2',
'handball1',
'handball2',
'helicopter',
'iceskater1',
'iceskater2',
'lamb',
'leaves',
'marathon',
'matrix',
'monkey',
'motocross1',
'nature',
'polo',
'rabbit',
'rabbit2',
'road',
'rowing',
'shaking',
'singer2',
'singer3',
'soccer1',
'soccer2',
'soldier',
'surfing',
'tiger',
'wheel',
'wiper',
'zebrafish1']
elif year == 22:
sequence_list= ['agility',
'animal',
'ants1',
'bag',
'ball2',
'ball3',
'basketball',
'birds1',
'birds2',
'bolt1',
'book',
'bubble',
'butterfly',
'car1',
'conduction1',
'crabs1',
'dinosaur',
'diver',
'drone1',
'drone_across',
'fernando',
'fish1',
'fish2',
'flamingo1',
'frisbee',
'girl',
'graduate',
'gymnastics1',
'gymnastics2',
'gymnastics3',
'hand',
'hand2',
'handball1',
'handball2',
'helicopter',
'iceskater1',
'iceskater2',
'kangaroo',
'lamb',
'leaves',
'marathon',
'matrix',
'monkey',
'motocross1',
'nature',
'polo',
'rabbit',
'rabbit2',
'rowing',
'shaking',
'singer2',
'singer3',
'snake',
'soccer1',
'soccer2',
'soldier',
'surfing',
'tennis',
'tiger',
'wheel',
'wiper',
'zebrafish1']
else:
raise NotImplementedError
return sequence_list
def parse(string):
"""
parse string to the appropriate region format and return region object
"""
from vot.region.shapes import Rectangle, Polygon, Mask
if string[0] == 'm':
# input is a mask - decode it
m_, offset_, region = create_mask_from_string(string[1:].split(','))
# return Mask(m_, offset=offset_)
return region
else:
# input is not a mask - check if special, rectangle or polygon
raise NotImplementedError
print('Unknown region format.')
return None
def read_file(fp: Union[str, TextIO]):
if isinstance(fp, str):
with open(fp) as file:
lines = file.readlines()
else:
lines = fp.readlines()
regions = []
# iterate over all lines in the file
for i, line in enumerate(lines):
regions.append(parse(line.strip()))
return regions
def create_mask_from_string(mask_encoding):
"""
mask_encoding: a string in the following format: x0, y0, w, h, RLE
output: mask, offset
mask: 2-D binary mask, size defined in the mask encoding
offset: (x, y) offset of the mask in the image coordinates
"""
elements = [int(el) for el in mask_encoding]
tl_x, tl_y, region_w, region_h = elements[:4]
rle = np.array([el for el in elements[4:]], dtype=np.int32)
# create mask from RLE within target region
mask = rle_to_mask(rle, region_w, region_h)
region = [tl_x, tl_y, region_w, region_h]
return mask, (tl_x, tl_y), region
@jit(nopython=True)
def rle_to_mask(rle, width, height):
"""
rle: input rle mask encoding
each evenly-indexed element represents number of consecutive 0s
each oddly indexed element represents number of consecutive 1s
width and height are dimensions of the mask
output: 2-D binary mask
"""
# allocate list of zeros
v = [0] * (width * height)
# set id of the last different element to the beginning of the vector
idx_ = 0
for i in range(len(rle)):
if i % 2 != 0:
# write as many 1s as RLE says (zeros are already in the vector)
for j in range(rle[i]):
v[idx_+j] = 1
idx_ += rle[i] |