Spaces:
Sleeping
Sleeping
File size: 1,687 Bytes
9223079 4c88343 9223079 4c88343 9223079 |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import logging
from collections import defaultdict
from pathlib import Path
import numpy as np
import pycolmap
logger = logging.getLogger(__name__)
def parse_image_list(path, with_intrinsics=False):
images = []
with open(path, "r") as f:
for line in f:
line = line.strip("\n")
if len(line) == 0 or line[0] == "#":
continue
name, *data = line.split()
if with_intrinsics:
model, width, height, *params = data
params = np.array(params, float)
cam = pycolmap.Camera(
model=model, width=int(width), height=int(height), params=params
)
images.append((name, cam))
else:
images.append(name)
assert len(images) > 0
logger.info(f"Imported {len(images)} images from {path.name}")
return images
def parse_image_lists(paths, with_intrinsics=False):
images = []
files = list(Path(paths.parent).glob(paths.name))
assert len(files) > 0
for lfile in files:
images += parse_image_list(lfile, with_intrinsics=with_intrinsics)
return images
def parse_retrieval(path):
retrieval = defaultdict(list)
with open(path, "r") as f:
for p in f.read().rstrip("\n").split("\n"):
if len(p) == 0:
continue
q, r = p.split()
retrieval[q].append(r)
return dict(retrieval)
def names_to_pair(name0, name1, separator="/"):
return separator.join((name0.replace("/", "-"), name1.replace("/", "-")))
def names_to_pair_old(name0, name1):
return names_to_pair(name0, name1, separator="_")
|