This repository was archived by the owner on Feb 26, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathSfM_SequentialPipeline.py
More file actions
83 lines (64 loc) · 3.35 KB
/
Copy pathSfM_SequentialPipeline.py
File metadata and controls
83 lines (64 loc) · 3.35 KB
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
#!/usr/bin/python
#! -*- encoding: utf-8 -*-
# This file is part of OpenMVG (Open Multiple View Geometry) C++ library.
# Python implementation of the bash script written by Romuald Perrot
# Created by @vins31
# Modified by Pierre Moulon
#
# this script is for easy use of OpenMVG
#
# usage : python openmvg.py image_dir output_dir
#
# image_dir is the input directory where images are located
# output_dir is where the project must be saved
#
# if output_dir is not present script will create it
#
# Indicate the openMVG binary directory
OPENMVG_SFM_BIN = "/opt/openMVG/build/Linux-x86_64-Release"
# Indicate the openMVG camera sensor width directory
CAMERA_SENSOR_WIDTH_DIRECTORY = "/opt/openMVG/src/software/SfM" + "/../../openMVG/exif/sensor_width_database"
import os
import subprocess
import sys
if len(sys.argv) < 4:
print ("Usage %s image_dir output_dir focal_length" % sys.argv[0])
sys.exit(1)
input_dir = sys.argv[1]
output_dir = sys.argv[2]
focal_length = sys.argv[3]
matches_dir = os.path.join(output_dir, "matches")
reconstruction_dir = os.path.join(output_dir, "reconstruction_sequential")
camera_file_params = os.path.join(CAMERA_SENSOR_WIDTH_DIRECTORY, "sensor_width_camera_database.txt")
print ("Using input dir : ", input_dir)
print (" output_dir : ", output_dir)
print (" focal_length: ",focal_length)
# Create the ouput/matches folder if not present
if not os.path.exists(output_dir):
os.mkdir(output_dir)
if not os.path.exists(matches_dir):
os.mkdir(matches_dir)
print ("1. Intrinsics analysis")
pIntrisics = subprocess.Popen( [os.path.join(OPENMVG_SFM_BIN, "openMVG_main_SfMInit_ImageListing"), "-i", input_dir, "-o", matches_dir, "-d", camera_file_params, "-f" , focal_length] )
pIntrisics.wait()
print ("2. Compute features")
pFeatures = subprocess.Popen( [os.path.join(OPENMVG_SFM_BIN, "openMVG_main_ComputeFeatures"), "-i", matches_dir+"/sfm_data.json", "-o", matches_dir, "-m", "SIFT"] )
pFeatures.wait()
print ("3. Compute matches")
pMatches = subprocess.Popen( [os.path.join(OPENMVG_SFM_BIN, "openMVG_main_ComputeMatches"), "-i", matches_dir+"/sfm_data.json", "-o", matches_dir] )
pMatches.wait()
# Create the reconstruction if not present
if not os.path.exists(reconstruction_dir):
os.mkdir(reconstruction_dir)
print ("4. Do Sequential/Incremental reconstruction")
pRecons = subprocess.Popen( [os.path.join(OPENMVG_SFM_BIN, "openMVG_main_IncrementalSfM"), "-i", matches_dir+"/sfm_data.json", "-m", matches_dir, "-o", reconstruction_dir] )
pRecons.wait()
print ("5. Colorize Structure")
pRecons = subprocess.Popen( [os.path.join(OPENMVG_SFM_BIN, "openMVG_main_ComputeSfM_DataColor"), "-i", reconstruction_dir+"/sfm_data.bin", "-o", os.path.join(reconstruction_dir,"colorized.ply")] )
pRecons.wait()
# optional, compute final valid structure from the known camera poses
#print ("6. Structure from Known Poses (robust triangulation)")
#pRecons = subprocess.Popen( [os.path.join(OPENMVG_SFM_BIN, "openMVG_main_ComputeStructureFromKnownPoses"), "-i", reconstruction_dir+"/sfm_data.bin", "-m", matches_dir, "-f", os.path.join(matches_dir, "matches.f.bin"), "-o", os.path.join(reconstruction_dir,"robust.bin")] )
#pRecons.wait()
#pRecons = subprocess.Popen( [os.path.join(OPENMVG_SFM_BIN, "openMVG_main_ComputeSfM_DataColor"), "-i", reconstruction_dir+"/robust.bin", "-o", os.path.join(reconstruction_dir,"robust_colorized.ply")] )
#pRecons.wait()