[updated 17/12/17 to get rid of unnecessary meshlab portion]
[updated 01/04/18 – Updated scripts for version 3.4+ of COLMAP]
In a vain attempt to be useful, I want to share the script I’m currently using to automate my photogrammetry workflow.
I’m using COLMAP in conjunction with openMVS on Windows 10 at the moment, and I feel that gives me robust results, in a good amount of time. You do need a decent computer with an Nvidia graphics card for this to work.
Essentially, I’ve automated my workflow so I don’t have to open up the COLMAP GUI each time, and then type in openMVS commands at the command prompt. I’ve written the following script so that I can just take a folder full of photos, drop my batch file in there, double click it and come back a little later to a fully textured model (assuming it works without hiccup).
Let’s unzip the colmap and openMVS folders into our downloads folder, and install meshlab.
Create an empty text file with notepad, and paste in the following:
::These parameters are specific to computer ::Store current Directory: set currDir=%CD% :: Set colmap directory: set colDir=C:\Users\Peter\Downloads\COLMAP-dev-windows\bin :: Set openMVS directory set oMVS=C:\Users\Peter\Downloads\openMVS_sample-0.7a :: Set Working Directory (windows) set workDir=D:\Output 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.exe --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 model_dense_mesh_refine.mvs copy *.obj %currDir%\model\ copy *.mtl %currDir%\model\ copy *.png %currDir%\model\ ::Uncomment these lines in to delete working directory ::cd /d %currDir% ::RD /S /Q %workDir%
Alter the script accordingly (see below) then change the extension of the file from *.txt to *.bat.
What this script does, is copy all the images in the same directory as the script into a working directory, run the COLMAP commands there, then the openMVS commands, then uses meshlab to convert the ply to obj. Let me talk you through it, because there’s some bits you’ll need to change according to your setup.
::These parameters are specific to computer
::Store current Directory:
:: Set colmap directory:
:: Set openMVS directory
:: Set Working Directory (windows)
set meshDir=”C:\Program Files\VCG\MeshLab”
copy *.jpg %workDir%\
cd /d %workDir%
This sets the directories for the colmap and openmvs binaries so that I didn’t have to type them out multiple times in the script, and so it’s easier to change depending on which computer it’s running on. If you’ve left the two folders in your Downloads folder, you can probably just change the username from ‘Peter’ to whatever your username is.
I also put in the default install directory for Meshlab, as we’ll be using the meshlabserver.exe in there later on.
I’ve set my working directory (%workDir%) to D:\Output. The script will run everything from there so that a) I always know where intermediate files will be saved, b) by copying the current images, it reduces the chance of accidentally deleting something vital, and c) I keep my image sets in onedrive; by moving the working directory outside onedrive, I make sure that it’s not trying to upload all the intermediate steps.
%colDir%\feature_extractor –database_path database.db –image_path .
%colDir%\exhaustive_matcher –database_path database.db
%colDir%\mapper –database_path %workDir%\database.db –image_path . –export_path %workDir%\sparse
%colDir%\model_converter.exe –input_path sparse\0 –output_path model.nvm –output_type NVM
The next few lines work through the colmap executables in order to: Extract features, match features, create depth mapps, and save the matched cameras as an NVM file (VisualSFM file format, needed by openMVS below). The instructions for this were taken from the COLMAP executables documentation.
This runs, in turn, various commands to convert the nvm file to openMVS, create a dense point cloud, then reconstruct, refine, and texture the mesh. On lower memory systems, it tends to be the refine mesh stage that really brings a computer to it’s knees, and if that’s happening you might want to look into the openMVS documentation to see how to scale down images for this step.
The last few lines are optional:
::Uncomment these lines in to delete working directory
::cd /d %currDir%
::RD /S /Q %workDir%
But these will delete the working directory automatically. It’s actually better to do this manually, because if something fails half way through, these commands will delete all those intermediate files and you won’t be able to see where it failed.
I hope this is useful to people that have a lot of photogrammetry to do, and don’t want to manually run every stage for every dataset. I offer this of course with absolutely zero support! If it doesn’t work or makes your computer blow up, not my fault!