def __load_from_xra(self, input_file):
trs = sppasXRA('VideoCoordinates')
trs.read(input_file)
if len(trs) == 1:
tier = trs[0]
else:
tier = trs.find(sppasCoordsVideoWriter().get_xra_tiername())
if tier is None:
raise Exception('No valid tier in XRA: not found. Cant load coordinates.')
media = tier.get_media()
if media is None:
raise Exception('Invalid tier in XRA: no media. Cant load coordinates.')
fps = media.get_meta('fps', None)
if fps is None:
raise Exception('Invalid media: no fps metadata. Cant load coordinates.')
fps = float(fps)
image_idx = 0
for ann in tier:
frame_idx = ann.get_meta('frame_index', None)
if frame_idx is None:
loc = ann.get_location().get_highest_localization()
start_time = loc.get_midpoint() - loc.get_radius()
frame_idx = round(start_time * fps)
else:
frame_idx = int(frame_idx)
for i in range(image_idx, frame_idx + 1):
self.coords.append(list())
for label in ann.get_labels():
for tag, score in label:
fuzzy_rect = tag.get_typed_content()
x, y, w, h = fuzzy_rect.get_midpoint()
coord = sppasCoords(x, y, w, h, score)
self.coords[frame_idx].append(coord)
image_idx = frame_idx + 1