-
Notifications
You must be signed in to change notification settings - Fork 48
/
EvaluationLauncher.py
executable file
·118 lines (100 loc) · 4.21 KB
/
EvaluationLauncher.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/python
#! -*- encoding: utf-8 -*-
# Copyright (c) 2015 Pierre MOULON.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#
# this script is to evaluate the Global SfM pipeline to a known camera trajectory
# Notes:
# - OpenMVG 0.9 is required
#
# Usage:
# $ python EvaluationLauncher.py OPENMVG_BIN_DIR ./Benchmarking_Camera_Calibration_2008 ./Benchmarking_Camera_Calibration_2008_out
# i.e:
# $ python EvaluationLauncher.py /home/user/openMVG_Build/Linux-x86_64-RELEASE ./Benchmarking_Camera_Calibration_2008 ./Benchmarking_Camera_Calibration_2008_out
#
#
import os
import subprocess
import sys
def ensure_dir(f):
d = os.path.dirname(f)
if not os.path.exists(d):
os.makedirs(d)
if len(sys.argv) < 4:
print ("Invalid input")
print ("Usage %s OPENMVG_BIN_DIR ./GT_DATASET ./GT_DATASET_out" % sys.argv[0])
sys.exit(1)
OPENMVG_SFM_BIN = sys.argv[1]
if not (os.path.exists(OPENMVG_SFM_BIN)):
print("Please use a valid OPENMVG_SFM_BIN directory.")
sys.exit(1)
input_eval_dir = sys.argv[2]
output_eval_dir = os.path.join(sys.argv[3], "evaluation_output")
# Run for each dataset of the input eval dir perform
# . intrinsic setup
# . compute features
# . compute matches
# . compute camera motion
# . perform quality evaluation regarding ground truth camera trajectory
for directory in os.listdir(input_eval_dir):
print(directory)
matches_dir = os.path.join(output_eval_dir, directory, "matching")
ensure_dir(matches_dir)
print(". intrinsic setup")
command = OPENMVG_SFM_BIN + "/openMVG_main_SfMInit_ImageListing"
command = command + " -i " + input_eval_dir + "/" + directory + "/images/"
command = command + " -o " + matches_dir
command = command + " -k \"2759.48;0;1520.69;0;2764.16;1006.81;0;0;1\""
command = command + " -c 1" # force pinhole camera
command = command + " -g 1" # shared intrinsic
proc = subprocess.Popen((str(command)), shell=True)
proc.wait()
print(". compute features")
command = OPENMVG_SFM_BIN + "/openMVG_main_ComputeFeatures"
command = command + " -i " + matches_dir + "/sfm_data.json"
command = command + " -o " + matches_dir
proc = subprocess.Popen((str(command)), shell=True)
proc.wait()
print(". compute pairs")
command = OPENMVG_SFM_BIN + "/openMVG_main_PairGenerator"
command = command + " -i " + matches_dir + "/sfm_data.json"
command = command + " -o " + matches_dir + "/pairs.bin"
proc = subprocess.Popen((str(command)), shell=True)
proc.wait()
print(". compute matches")
command = OPENMVG_SFM_BIN + "/openMVG_main_ComputeMatches"
command = command + " -i " + matches_dir + "/sfm_data.json"
command = command + " -p " + matches_dir + "/pairs.bin"
command = command + " -o " + matches_dir + "/matches.putative.bin -n AUTO"
proc = subprocess.Popen((str(command)), shell=True)
proc.wait()
print(". filter matches")
command = OPENMVG_SFM_BIN + "/openMVG_main_GeometricFilter"
command = command + " -i " + matches_dir + "/sfm_data.json"
command = command + " -m " + matches_dir + "/matches.putative.bin"
command = command + " -o " + matches_dir + "/matches.e.bin"
proc = subprocess.Popen((str(command)), shell=True)
proc.wait()
print(". compute camera motion")
outGlobal_dir = os.path.join(output_eval_dir, directory, "SfM")
command = OPENMVG_SFM_BIN + "/openMVG_main_SfM"
command = command + " -i " + matches_dir + "/sfm_data.json"
command = command + " -m " + matches_dir
command = command + " -o " + outGlobal_dir
command = command + " -M " + matches_dir + "/matches.e.bin"
command = command + " -f NONE -s GLOBAL" # Do not refine intrinsics & udr global sfm
proc = subprocess.Popen((str(command)), shell=True)
proc.wait()
print(". perform quality evaluation")
gt_camera_dir = os.path.join(input_eval_dir, directory)
outStatistics_dir = os.path.join(outGlobal_dir, "stats")
command = OPENMVG_SFM_BIN + "/openMVG_main_evalQuality"
command = command + " -i " + gt_camera_dir
command = command + " -c " + outGlobal_dir + "/sfm_data.bin"
command = command + " -o " + outStatistics_dir
proc = subprocess.Popen((str(command)), shell=True)
proc.wait()
sys.exit(1)