MCPcopy Create free account
hub / github.com/JasonLSC/GSCodec_Studio / __init__

Method __init__

examples/datasets/colmap.py:32–310  ·  view source on GitHub ↗
(
        self,
        data_dir: str,
        factor: int = 1,
        normalize: bool = False,
        test_every: int = 8,
        mask_dir: Optional[str] = None
    )

Source from the content-addressed store, hash-verified

30 """COLMAP parser."""
31
32 def __init__(
33 self,
34 data_dir: str,
35 factor: int = 1,
36 normalize: bool = False,
37 test_every: int = 8,
38 mask_dir: Optional[str] = None
39 ):
40 self.data_dir = data_dir
41 self.factor = factor
42 self.normalize = normalize
43 self.test_every = test_every
44 self.mask_dir = mask_dir # only used when object-centric content in MPEG GSC
45
46 colmap_dir = os.path.join(data_dir, "sparse/0/")
47 if not os.path.exists(colmap_dir):
48 colmap_dir = os.path.join(data_dir, "sparse")
49 assert os.path.exists(
50 colmap_dir
51 ), f"COLMAP directory {colmap_dir} does not exist."
52
53 manager = SceneManager(colmap_dir)
54 manager.load_cameras()
55 manager.load_images()
56 manager.load_points3D()
57
58 # Extract extrinsic matrices in world-to-camera format.
59 imdata = manager.images
60 w2c_mats = []
61 camera_ids = []
62 Ks_dict = dict()
63 params_dict = dict()
64 imsize_dict = dict() # width, height
65 mask_dict = dict()
66 bottom = np.array([0, 0, 0, 1]).reshape(1, 4)
67 for k in imdata:
68 im = imdata[k]
69 rot = im.R()
70 trans = im.tvec.reshape(3, 1)
71 w2c = np.concatenate([np.concatenate([rot, trans], 1), bottom], axis=0)
72 w2c_mats.append(w2c)
73
74 # support different camera intrinsics
75 camera_id = im.camera_id
76 camera_ids.append(camera_id)
77
78 # camera intrinsics
79 cam = manager.cameras[camera_id]
80 fx, fy, cx, cy = cam.fx, cam.fy, cam.cx, cam.cy
81 K = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]])
82 K[:2, :] /= factor
83 Ks_dict[camera_id] = K
84
85 # Get distortion parameters.
86 type_ = cam.camera_type
87 if type_ == 0 or type_ == "SIMPLE_PINHOLE":
88 params = np.empty(0, dtype=np.float32)
89 camtype = "perspective"

Callers 1

__init__Method · 0.45

Calls 6

_get_rel_pathsFunction · 0.85
similarity_from_camerasFunction · 0.85
transform_camerasFunction · 0.85
transform_pointsFunction · 0.85
align_principle_axesFunction · 0.85
updateMethod · 0.80

Tested by

no test coverage detected