forked from cdcseacave/openMVS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MvgOptimizeSfM.py
77 lines (63 loc) · 2.86 KB
/
MvgOptimizeSfM.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python3
# -*- encoding: utf-8 -*-
"""
This script is for comparing the poses stored in an OpenMVS project to the poses optimized by OpenMVG
usage: run 'MvgOptimizeSfM.py' in a sub-folder to the OpenMVS project folder containing
'scene.mvs' and images stored in 'images' folder; structure ex:
-OpenMVS_project
-images
-scene.mvs
-mvg
-run script here
"""
import os
import sys
import subprocess
if sys.platform.startswith('win'):
PATH_DELIM = ';'
else:
PATH_DELIM = ':'
# add this script's directory to PATH
os.environ['PATH'] += PATH_DELIM + os.path.dirname(os.path.abspath(__file__))
# add current directory to PATH
os.environ['PATH'] += PATH_DELIM + os.getcwd()
def whereis(afile):
"""
return directory in which afile is, None if not found. Look in PATH
"""
if sys.platform.startswith('win'):
cmd = "where"
else:
cmd = "which"
try:
ret = subprocess.run([cmd, afile], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True)
return os.path.split(ret.stdout.decode())[0]
except subprocess.CalledProcessError:
return None
def launch(cmdline):
# Launch the current step
print('Cmd: ' + ' '.join(cmdline))
try:
pStep = subprocess.Popen(cmdline)
pStep.wait()
if pStep.returncode != 0:
return
except KeyboardInterrupt:
sys.exit('\r\nProcess canceled by user, all files remains')
# Try to find openMVG and openMVS binaries in PATH
OPENMVG_BIN = whereis("openMVG_main_SfMInit_ImageListing")
OPENMVS_BIN = whereis("ReconstructMesh")
# Ask user for openMVG and openMVS directories if not found
if not OPENMVG_BIN:
OPENMVG_BIN = input("openMVG binary folder?\n")
if not OPENMVS_BIN:
OPENMVS_BIN = input("openMVS binary folder?\n")
launch([os.path.join(OPENMVS_BIN, 'InterfaceCOLMAP'), '../scene.mvs', '-o', '../gt_dense_cameras.camera'])
launch([os.path.join(OPENMVG_BIN, 'openMVG_main_SfMInit_ImageListingFromKnownPoses'), '-i', '../images', '-g', '../gt_dense_cameras', '-t', '1', '-o', '.'])
launch([os.path.join(OPENMVG_BIN, 'openMVG_main_ComputeFeatures'), '-i', 'sfm_data.json', '-o', '.'])
launch([os.path.join(OPENMVG_BIN, 'openMVG_main_ComputeMatches'), '-i', 'sfm_data.json', '-o', '.', '-m', '1'])
launch([os.path.join(OPENMVG_BIN, 'openMVG_main_ComputeStructureFromKnownPoses'), '-i', 'sfm_data.json', '-m', '.', '-o', 'sfm_data_struct.bin', '-b'])
launch([os.path.join(OPENMVG_BIN, 'openMVG_main_ComputeSfM_DataColor'), '-i', 'sfm_data_struct.bin', '-o', 'scene.ply'])
launch([os.path.join(OPENMVG_BIN, 'openMVG_main_openMVG2openMVS'), '-i', 'sfm_data_struct.bin', '-o', 'scene.mvs', '-d', 'images'])
launch([os.path.join(OPENMVS_BIN, 'InterfaceCOLMAP'), 'scene.mvs', '-o', 'cameras.camera'])
launch([os.path.join(OPENMVG_BIN, 'openMVG_main_evalQuality'), '-i', '..', '-c', 'sfm_data_struct.bin', '-o', 'compare'])