MCPcopy
hub / github.com/magicleap/Atlas / process

Function process

inference_colmap.py:26–144  ·  view source on GitHub ↗

Run Colmap dense reconstruction with ground truth pose. Copies and creates the necessary file structure required by Colmap. Then runs Colmap. Args: info_file: path to info_json file for the scene pathout: path to store intermediate and final results stride: num

(info_file, pathout, stride, scale)

Source from the content-addressed store, hash-verified

24from atlas.data import load_info_json, parse_splits_list
25
26def process(info_file, pathout, stride, scale):
27 """ Run Colmap dense reconstruction with ground truth pose.
28
29 Copies and creates the necessary file structure required by Colmap.
30 Then runs Colmap.
31
32 Args:
33 info_file: path to info_json file for the scene
34 pathout: path to store intermediate and final results
35 stride: number of frames to skip (reduces runtime)
36 scale: how much to downsample images (reduces runtime and often
37 improves stereo matching results)
38 """
39
40 info = load_info_json(info_file)
41 dataset = info['dataset']
42 scene = info['scene']
43 frames = info['frames'][::stride]
44
45 os.makedirs(os.path.join(pathout, dataset, scene, 'images'), exist_ok=True)
46
47 for i, frame in enumerate(frames):
48 if i%25 == 0:
49 print(i,len(frames))
50
51 img = Image.open(frame['file_name_image'])
52 w = img.width//scale
53 h = img.height//scale
54 fname_out = os.path.split(frame['file_name_image'])[1]
55 fname_out = os.path.join(pathout, dataset, scene, 'images', fname_out)
56 img.resize((w,h), Image.BILINEAR).save(fname_out)
57
58 with open(os.path.join(pathout, dataset, scene, 'cameras.txt'), 'w') as fp:
59 fp.write('1 PINHOLE {w} {h} {fx} {fy} {cx} {cy}'.format(
60 w=w,
61 h=h,
62 fx=frames[0]['intrinsics'][0][0]/scale,
63 fy=frames[0]['intrinsics'][1][1]/scale,
64 cx=frames[0]['intrinsics'][0][2]/scale,
65 cy=frames[0]['intrinsics'][1][2]/scale,
66 ))
67
68 with open(os.path.join(pathout, dataset, scene, 'points3D.txt'), 'w') as fp:
69 pass
70
71
72 cmd = 'colmap feature_extractor --database_path %s --image_path %s'%(
73 os.path.join(pathout, dataset, scene, 'database.db'),
74 os.path.join(pathout, dataset, scene, 'images')
75 )
76 os.system(cmd)
77 cmd = 'colmap exhaustive_matcher --database_path %s'%(
78 os.path.join(pathout, dataset, scene, 'database.db')
79 )
80 os.system(cmd)
81
82
83

Callers 1

mainFunction · 0.70

Calls 2

load_info_jsonFunction · 0.90
saveMethod · 0.80

Tested by

no test coverage detected