File size: 1,083 Bytes
9d80cbe
 
 
c22c8c5
 
9d80cbe
 
 
 
 
 
 
c22c8c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()})