import pycolmap import tempfile,zipfile import io import numpy as np from typing import Dict def read_colmap_rec(colmap_data): with tempfile.TemporaryDirectory() as tmpdir: with zipfile.ZipFile(io.BytesIO(colmap_data), "r") as zf: zf.extractall(tmpdir) # unpacks cameras.txt, images.txt, etc. to tmpdir # Now parse with pycolmap rec = pycolmap.Reconstruction(tmpdir) return rec def empty_solution(): '''Return a minimal valid solution, i.e. 2 vertices and 1 edge.''' return np.zeros((2,3)), [(0, 1)] class Sample(Dict): def pick_repr_data(self, x): if hasattr(x, 'shape'): return x.shape if isinstance(x, (str, float, int)): return x if isinstance(x, list): return [type(x[0])] if len(x) > 0 else [] return type(x) def __repr__(self): # return str({k: v.shape if hasattr(v, 'shape') else [type(v[0])] if isinstance(v, list) else type(v) for k,v in self.items()}) return str({k: self.pick_repr_data(v) for k,v in self.items()})