COLMAP + OpenMVS scripts [Updated]

It’s been a while since I wrote anything on the blog – an extremely high teaching load has kept me from tinkering.

So to ease myself back in, here are updated scripts for running colmap and openMVS automatically.  COLMAP 3.4 changed the way things are called from the command line, breaking my previous script.

If you want detail on what each bit does, check out the original post here.

Updated COLMAP + OpenMVS script (v3.4+):


::These parameters are specific to computer

::Store current Directory:
set currDir=%CD%

::get folder name as variable
SET "MYDIR=%~p0"
set MYDIR1=%MYDIR:~0,-1%
for %%f in (%MYDIR1%) do set myfolder=%%~nxf

:: Set colmap directory (change this to where you've downloaded colmap):
set colDir=C:\Users\Peter\Downloads\COLMAP-3.4-windows\bin\colmap.exe

:: Set openMVS directory (change this to where you've downloaded openMVS)
set oMVS=C:\Users\Peter\Downloads\openMVS_sample-0.7a

:: Set Working Directory (I create a temporary folder on my D drive to process data in)
set workDir=D:\%myfolder%\

mkdir %workDir% 
copy *.jpg %workDir%\ 
cd /d %workDir%

%colDir% feature_extractor --database_path database.db --image_path .
%colDir% exhaustive_matcher --database_path database.db
mkdir sparse
%colDir% mapper --database_path %workDir%\database.db --image_path . --export_path %workDir%\sparse
%colDir% model_converter --input_path sparse\0 --output_path model.nvm --output_type NVM
%oMVS%\InterfaceVisualSFM.exe model.nvm
%oMVS%\DensifyPointCloud.exe model.mvs
%oMVS%\ReconstructMesh.exe model_dense.mvs
%oMVS%\RefineMesh.exe --resolution-level 1 model_dense_mesh.mvs
%oMVS%\TextureMesh.exe --export-type obj -o myfolder%.obj model_dense_mesh_refine.mvs

mkdir %currDir%\model\
copy *.obj %currDir%\model\
copy *.mtl %currDir%\model\
copy *Kd.jpg %currDir%\model\

cd %currDir%

::If you want to automate removal of the working folder, use the following line.
::Don't use it if you want to keep intermediate steps.
rmdir /S /Q %workDir%

This new script takes the current folder name and uses that to name the model. WARNING: SPACES CAN’T BE USED IN FOLDER/PATH NAMES.

Copy the above into a text file, rename the *.txt to *.bat, place in folder full of photos, and double click.

I also have a script that will run through folders:

Script for processing multiple photos automatically

Put this bat file and the above bat file in the directory that contains folders of photos, e.g.:

|– Folder1
|  | — Photo1.jpg, photo2.jpg, photo3.jpg …
|– Folder2
|  | — Photo1.jpg etc…


for /D %%i in (*) do (
cd %%i
copy ..\ColmapScript.bat COLMAP.bat
call COLMAP.bat
cd ..

Just set everything up as above, and double click Autoprocessing.bat. The terminal will move into Folder1, copy the colmap script in there, run the colmap script, then move up and into Folder 2 to repeat.

Hope that helps/is of use to people.




One thought on “COLMAP + OpenMVS scripts [Updated]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s