xref: /aosp_15_r20/external/libvpx/tools/3D-Reconstruction/MotionEST/GroundTruth.py (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
1##  Copyright (c) 2020 The WebM project authors. All Rights Reserved.
2##
3##  Use of this source code is governed by a BSD-style license
4##  that can be found in the LICENSE file in the root of the source
5##  tree. An additional intellectual property rights grant can be found
6##  in the file PATENTS.  All contributing project authors may
7##  be found in the AUTHORS file in the root of the source tree.
8##
9
10#coding : utf - 8
11import numpy as np
12import numpy.linalg as LA
13from MotionEST import MotionEST
14"""Ground Truth:
15
16  Load in ground truth motion field and mask
17"""
18
19
20class GroundTruth(MotionEST):
21  """constructor:
22
23    cur_f:current
24    frame ref_f:reference
25    frame blk_sz:block size
26    gt_path:ground truth motion field file path
27    """
28
29  def __init__(self, cur_f, ref_f, blk_sz, gt_path, mf=None, mask=None):
30    self.name = 'ground truth'
31    super(GroundTruth, self).__init__(cur_f, ref_f, blk_sz)
32    self.mask = np.zeros((self.num_row, self.num_col), dtype=bool)
33    if gt_path:
34      with open(gt_path) as gt_file:
35        lines = gt_file.readlines()
36        for i in xrange(len(lines)):
37          info = lines[i].split(';')
38          for j in xrange(len(info)):
39            x, y = info[j].split(',')
40            #-, - stands for nothing
41            if x == '-' or y == '-':
42              self.mask[i, -j - 1] = True
43              continue
44            #the order of original file is flipped on the x axis
45            self.mf[i, -j - 1] = np.array([float(y), -float(x)], dtype=int)
46    else:
47      self.mf = mf
48      self.mask = mask
49