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.

 

 

Advertisements

20 thoughts on “COLMAP + OpenMVS scripts [Updated]

  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:

    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!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

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