Pythonスクリプトはビルド先フォルダ以下のsoftware\SfMフォルダにSfM_SequentialPipeline.pyなどで生成されています。IncrementalSfMを実行する場合は、このSfM_SequentialPipeline.pyを使います。主に下記で赤字の部分を環境に合わせて変更して、第一引数に写真を格納したフォルダ名、第二引数に出力先フォルダ名を指定します。実行すると出力先フォルダ以下のmatchesフォルダに特徴点情報のファイル、reconstruction_sequentialフォルダに再構築結果が出力されます。
C:/Git/openMVG/src/openMVG/exif/sensor_width_database/sensor_width_camera_database.txtがセンサーサイズを定義したデータベースファイルです。定義方法などはOpenMVGをVisual Studio 2017(x64)でビルド(その2)を参照してください。
先頭行の"# coding: Shift_JIS"は、ファイルパスに日本語が入るときのために定義しています。
# coding: Shift_JIS
# 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
#
# 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 = "C:/Git/openMVG/build/Windows-AMD64-Release/Release"
OPENMVG_SFM_BIN = "C:/Git/openMVG/build/Windows-AMD64-Release/Release"
# Indicate the openMVG camera sensor width directory
CAMERA_SENSOR_WIDTH_DIRECTORY = "C:/Git/openMVG/src/openMVG/exif/sensor_width_database"
CAMERA_SENSOR_WIDTH_DIRECTORY = "C:/Git/openMVG/src/openMVG/exif/sensor_width_database"
#import commands
import os
import subprocess
import sys
import os
import subprocess
import sys
if len(sys.argv)
print ("Usage %s image_dir output_dir" % sys.argv[0])
sys.exit(1)
print ("Usage %s image_dir output_dir" % sys.argv[0])
sys.exit(1)
input_dir = sys.argv[1]
output_dir = sys.argv[2]
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")
output_dir = sys.argv[2]
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 (" output_dir : ", output_dir)
# 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)
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, "-c", "4"] )
pIntrisics.wait()
pIntrisics = subprocess.Popen( [os.path.join(OPENMVG_SFM_BIN, "openMVG_main_SfMInit_ImageListing"), "-i", input_dir, "-o", matches_dir, "-d", camera_file_params, "-c", "4"] )
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()
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()
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)
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, "-c", "4"] )
pRecons.wait()
pRecons = subprocess.Popen( [os.path.join(OPENMVG_SFM_BIN, "openMVG_main_IncrementalSfM"), "-i", matches_dir+"/sfm_data.json", "-m", matches_dir, "-o", reconstruction_dir, "-c", "4"] )
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()
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()
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()
pRecons.wait()