COLMAP + OpenMVS scripts [Updated]

[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+):

ColmapScript.bat:

::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:

  1. Type “edit the system environment variables” into start and click it
  2. Click ‘Environment Variables’
  3. 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.:

Folders_to_Process
|– Folder1
|  | — Photo1.jpg, photo2.jpg, photo3.jpg …
|– Folder2
|  | — Photo1.jpg etc…
|–ColmapScript.bat
|–AutoProcessing.bat

Autoprocessing.bat:

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.

 

 

34 thoughts on “COLMAP + OpenMVS scripts [Updated]

Add yours

  1. Thanks a lot for sharing your scripts, it makes it easy to use these open source tools!
    I had to copy the content of the lib folder into the bin folder to get it to work though, otherwise it was complaining it couldn’t find the dll libraries.

  2. I’ve been trying to figure out how to use photogrammetry software just out of personal interest, and your blog has been incredibly helpful to me, but I haven’t been able to get OpenMVS to do anything, even when I use your script, no matter what I do. All it does is create a short log file along these lines for each step:
    20:41:08 [App ] Build date: May 26 2017, 18:38:57
    20:41:08 [App ] CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    20:41:08 [App ] RAM: 15.87GB Physical Memory 128.00TB Virtual Memory
    20:41:08 [App ] OS: Windows 10+ x64
    20:41:08 [App ] SSE & AVX compatible CPU & OS detected
    20:41:08 [App ] Command line: -i .\P13020
    20:41:08 [App ] Loading cameras/points: ./P13020
    and then exits out without producing any other output. When I try and do it myself, I can make a sparse point cloud in COLMAP just fine, and get the exact same lack of results from OpenMVS.

    1. Ah, not a lot to go on then. Is it definately reconstructing camera positions in COLMAP? (Using the GUI, does it reconstruct a sparse model?). If so, do you have a CUDA enabled GPU – that may be necessary for openMVS.

    2. Colmap requires CUDA to work… So you will need a CUDA enabled graphics card… Don’t know if PMVS recquires it too.

  3. Small typo in the first .bat…

    %oMVS%\TextureMesh.exe –export-type obj -o myfolder%.obj model_dense_mesh_refine.mvs

    Should be,

    %oMVS%\TextureMesh.exe –export-type obj -o %myfolder%.obj model_dense_mesh_refine.mvs

    I found it failed to export and realized why. Otherwise, works great! Thanks for sharing the automation.

  4. Greetings Dr. Falkingham, Thank you for posting your research! It has been very helpful… I was wondering if you ever had trouble building the dense cloud with openMvs after rendering the sparse cloud with colmap. My sparse cloud looks very good and camera positions look great but when I attempt to DensifyPointCloud in openMVS, I get an error for all images saying: error: reference image # has no good images in view. And the resulting *_dense.mvs file is empty. I have made sure that everything is installed correctly by using the sample mvs file from the website. Thanks again and I’d appreciate any feedback if you get the chance.

    I used a total of 80 pictures of the subject in a white background, my cameras are fixed. Here is a picture of my sparse cloud:
    https://ibb.co/fbQMOK

    sample pictures:
    https://ibb.co/kxpUce
    https://ibb.co/fevPAz
    https://ibb.co/eRoNxe

    Terminal:

    16:43:15 [App ] Build date: Aug 11 2018, 12:41:00
    16:43:15 [App ] CPU: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    16:43:15 [App ] RAM: 16.00GB Physical Memory 16.00GB Virtual Memory
    16:43:15 [App ] OS: Darwin 17.4.0 (x86_64)
    16:43:15 [App ] SSE & AVX compatible CPU & OS detected
    16:43:15 [App ] Command line: rock.mvs
    16:43:15 [App ] Camera model loaded: platform 0; camera 0; f 0.776×0.776; poses 1
    16:43:15 [App ] Camera model loaded: platform 1; camera 0; f 0.776×0.776; poses 1
    16:43:15 [App ] Camera model loaded: platform 2; camera 0; f 0.791×0.791; poses 1
    16:43:15 [App ] Camera model loaded: platform 3; camera 0; f 0.788×0.788; poses 1
    .
    ..

    16:43:15 [App ] Camera model loaded: platform 78; camera 0; f 0.770×0.770; poses 1
    16:43:15 [App ] Camera model loaded: platform 79; camera 0; f 0.791×0.791; poses 1
    16:43:15 [App ] Image loaded 0: 2018-08-20_151206.jpg
    16:43:15 [App ] Image loaded 1: 2018-08-20_150635.jpg
    16:43:15 [App ] Image loaded 2: 2018-08-20_151100.jpg
    16:43:15 [App ] Image loaded 3: 2018-08-20_151116.jpg
    16:43:15 [App ] Image loaded 4: 2018-08-20_151043.jpg
    16:43:15 [App ] Image loaded 5: 2018-08-20_151055.jpg
    .
    ..

    16:43:22 [App ] error: reference image 76 has no good images in view
    16:43:22 [App ] error: reference image 77 has no good images in view
    16:43:22 [App ] error: reference image 78 has no good images in view
    16:43:22 [App ] error: reference image 79 has no good images in view
    16:43:22 [App ] Selecting images for dense reconstruction completed: 0 images (133ms)
    Fused depth-maps 0 (100%, 0ms)
    16:43:22 [App ] Depth-maps fused and filtered: 0 depth-maps, 0 depths, 0 points (-2147483648%%) (0ms)
    16:43:22 [App ] Densifying point-cloud completed: 0 points (6s212ms)
    16:43:22 [App ] Scene saved (7ms):
    80 images (80 calibrated)
    0 points, 0 vertices, 0 faces

    1. I forgot to include this part of the log:

      16:43:15 [App ] Image loaded 77: 2018-08-20_150652.jpg
      16:43:15 [App ] Image loaded 78: 2018-08-20_150721.jpg
      16:43:15 [App ] Image loaded 79: 2018-08-20_151243.jpg
      16:43:15 [App ] Scene loaded from interface format (22ms):
      80 images (80 calibrated) with a total of 616.60 MPixels (7.71 MPixels/image)
      5429 points, 0 vertices, 0 faces
      16:43:22 [App ] Preparing images for dense reconstruction completed: 80 images (6s75ms)
      16:43:22 [App ] error: reference image 0 has no good images in view
      16:43:22 [App ] error: reference image 1 has no good images in view
      16:43:22 [App ] error: reference image 2 has no good images in view
      16:43:22 [App ] error: reference image 3 has no good images in view

  5. I reworked your script, so that it now can be used with folders including spaces. Would you mind, if I share it on github (as s gist)?

  6. For all that want to use folders with spaces: you can find my modified script on github:


    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Generates a 3D model out of multiple photographs using ::
    :: COLMAP and openMVS. See https://peterfalkingham.com/ for more ::
    :: information about photogrammetrie. ::
    :: ::
    :: Note that the COLMAP library folder needs to be added to the ::
    :: PATH environment variable in order for this script to work. ::
    :: ::
    :: Copyright 2018, Peter Falkingham (v1.0, v1.1) ::
    :: Copyright 2018, Nikolaus Krismer (v1.2) ::
    :: ::
    :: Licensed under the MIT License (since v1.2) ::
    :: ::
    :: Permission is hereby granted, free of charge, to any person obtaining ::
    :: a copy of this software and associated documentation files (the ::
    :: "Software"), to deal in the Software without restriction, including ::
    :: without limitation the rights to use, copy, modify, merge, publish, ::
    :: distribute, sublicense, and/or sell copies of the Software, and to ::
    :: permit persons to whom the Software is furnished to do so, subject to ::
    :: the following conditions: ::
    :: The above copyright notice and this permission notice shall be ::
    :: included in all copies or substantial portions of the Software. ::
    :: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ::
    :: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ::
    :: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ::
    :: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE ::
    :: LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION ::
    :: OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION ::
    :: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ::
    :: ::
    :: Revision history: ::
    :: 2018-10-06 (v1.2) allows usage of spaces in folder names ::
    :: restructuring source, support for COLMAP v3.6 ::
    :: 2018-07-10 (v1.1) allows usage of development version of COLMAP ::
    :: support for COLMAP v3.4+ ::
    :: 2018-04-01 (v1.0) initial release ::
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Modify the following parameters according to your system
    set "colDir=C:\Program Files\colmap"
    set "oMVS=C:\Program Files\openMVS"
    set "keepIntermediate=true"
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: Do not modify anything below this line!
    set "colBin=%colDir%\bin\colmap.exe"
    set "currDir=%CD%"
    set "workDir=%currDir%\processed"
    set "MYDIR=%~p0"
    set "MYDIR1=%MYDIR:~0,-1%"
    for %%f in ("%MYDIR1%") do (
    set "myfolder=%%~nxf"
    )
    mkdir "%workDir%"
    copy *.jpg "%workDir%"
    cd "%workDir%"
    mkdir "sparse"
    "%colBin%" feature_extractor –database_path database.db –image_path .
    "%colBin%" exhaustive_matcher –database_path database.db
    "%colBin%" mapper –database_path "%workDir%\database.db" –image_path . –output_path "%workDir%\sparse"
    "%colBin%" 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 %keepIntermediate% == false (
    rmdir /S /Q "%workDir%"
    )

    BTW: I licensed my changes under MIT and stated that in a script header

    1. I tried to run your script for some sample images of the sceaux castle, but unfortunately it doesn’t work. I got the following error message when executing the .bat file:
      C:\SfM\test_images\SceauxCastle\processed>”C:\SfM\COLMAP-dev-windows-no-cuda\bin\colmap.exe” feature_extractor –database_path database.db –image_path .
      qt.qpa.plugin: Could not find the Qt platform plugin “windows” in “”
      This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
      does it also work with the non-CUDA version of COLMAP?
      I tried both, but ran into the same problem… Thanks!

      1. I’ve not tried it with the non cuda version, but I wouldn’t expect that error. Looks like a formatting/incorrect path issue in there somewhere.

  7. Just getting started. Installed colmap, etc, set PATH environment variables, and copied script. Replaced drive letter, etc. Got this error in 1st colmap call. Can you help? Thanks much.
    ============
    F:\Calculate>C:\Users\sbrande\Downloads\COLMAP-dev-windows\bin\colmap.exe feature_extractor –database_path database.db –image_path .
    qt.qpa.plugin: Could not find the Qt platform plugin “windows” in “”
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
    ============

  8. Using the autoprocessing batch file, say I were to have a couple directories with images to process when I run the file, and while the processing is occurring I add another directory of images. Would it move into the new directory after finishing processing on the original two directories? If not, what modifications would I need to make to get that to happen?

  9. Just got this running for the first time. Any suggestions for using this in 2019? Did you ever happen to work out that turntable setup? I have been looking to use one. Not use if Colmap works with stationary camera though. Thanks for all your hard work!

    1. I never got a turntable set up, but COLMAP works great with photos taken with a stationary camera and turning the object manually. You could also give alicevision Meshroom a go, which is a bit newer and handles texturing too.

  10. Hi. Thank you for posting this tutorial. I would be really grateful if you could kindly mention how to use “InterfaceCOLMAP.exe” instead of “InterfaceVisualSFM.exe”.

    1. I don’t have OpenMVS installed at the minute, but when I last used it there wasn’t an InterfaceCOLMAP.exe – looks like that was added in a recent(ish) commit.

      I’ll take another look at some point, but can’t gaurantee it’ll be soon.

Leave a reply to Arnandsway Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Built with WordPress.com.

Up ↑