[updated 10/7/18 to use development version of COLMAP, and include environment variables]
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, and the author now recommends using the dev version as standard
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, replace 'dev' with version number if necessary): set colDir=C:\Users\Peter\Downloads\COLMAP-dev-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.
Remember to add the colmap libraries to your environment variables:
- Type “edit the system environment variables” into start and click it
- Click ‘Environment Variables’
- Double click the ‘path’ variable, and add a new line that goes straight to the COLMAP lib folder, e.g. “C:\Users\pfalkingham\Downloads\COLMAP-dev-windows\lib” Click ok. Now the script should work.
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.:
| | — Photo1.jpg, photo2.jpg, photo3.jpg …
| | — 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.