Photogrammetry Testing 12: Revisiting OpenMVG (with OpenMVS) [updated]

 Part 1: Photoscan | Part 2: VisualSFM+MeshRecon | Part 3: VisualSFM+PMVS+Meshlab | Part 4: OpenMVG + MVE | Part 5: MVE | Part 6: ReMake | Part 7: SMVS (+MVE) | Part 8: COLMAP | Part 9: 3DF Zephyr Free | Part 10: MicMac | Part 11: VisualSFM + openMVS, & COLMAP + openMVS |Part 11b – COLMAP + openMVS Scripts |

Current favourite: Part 11 Colmap+openMVS

[Note, the original post, posted a day or two ago used a different script and my timings were much higher.  I’ve now fixed that and updated the post to reflect more reasonable timings. If you’re interested in what the differences were in the script, see the bottom of the post]

I’ve previously tried using openMVG, but had limited success with matching failing frequently, and reconstructions not really working.  I’ve now got past that inspired by some discussions on the openMVG google group.

Basically, here I’m using OpenMVG to do the matching, and openMVS to do the dense reconstruction, meshing, and texturing.

Links:

OpenMVG can be found here: https://github.com/openMVG/openMVG  (direct link to binaries)

OpenMVS is available here: http://cdcseacave.github.io/openMVS/ (direct link to binaries)

The process simply goes as follows:

OpenMVG:

  • List Images
  • Compute Features
  • Compute Matches
  • SfM reconstruction
  • Compute Structure from Known Poses
  • Colour the sparse cloud
  • Convert to openMVS format

OpenMVS:

  • Densify point cloud
  • Reconstruct Mesh
  • Refine Mesh
  • Texture Mesh

Rather than give you each command individually, I’ll just provide the script I’m using.  If you copy and paste the below into a file and call it ‘openmvg_openmvs.bat’, you can put it in the directory of photos and just double click it.

NOTE: You’ll obviously need to set your openMVG/openMVS directories to wherever you downloaded those binaries to, and I work by making a directory on my D: drive for processing.  You’ll want to change these to your setup. (FYI: the beginning of my script is a clever little trick to end up with a model with the same name as the folder the script is run from, e.g. I put my test photos in a folder on my desktop called ‘Styracosaurus’, and at the end of the process I have a model named Styracosaurus.obj in D:\Styracosaurus).  I’ve also left in my timing commands – you can remove them if you like.

Script (apologies for formatting):

::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 openMVS directory
set oMVS=C:\Users\Peter\Downloads\openMVS_sample-0.7a

:: Set openMVG directory:
set oMVG=C:\Users\Peter\Downloads\OpenMVG_v1.3

:: Set Working Directory (windows)
set workDir=D:\%myfolder%\

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

echo "start %time%">>timings.txt
%oMVG%\openMVG_main_SfMInit_ImageListing -i . -d %oMVG%\sensor_width_database\sensor_width_camera_database.txt -o matches
echo "imagelisting %time%" >> timings.txt
%oMVG%\openMVG_main_ComputeFeatures -p HIGH -i matches\sfm_data.json -o matches
echo "features %time%" >> timings.txt
%oMVG%\openMVG_main_ComputeMatches -r .8 -i matches\sfm_data.json -o matches
echo "matches %time%" >> timings.txt
%oMVG%\openMVG_main_IncrementalSfM -i matches\sfm_data.json -m matches -o out_Incremental_Reconstruction
echo "SfM done %time%" >> timings.txt
mkdir mvs_dir
%oMVG%\openMVG_main_ComputeStructureFromKnownPoses -i out_Incremental_Reconstruction\sfm_data.bin -m matches -f matches\matches.f.bin -o :: out_Incremental_Reconstruction\robust.bin
echo "structure %time%" >> timings.txt
%oMVG%\openMVG_main_ComputeSfM_DataColor.exe -i out_Incremental_Reconstruction\robust_colorized.ply
echo "color %time%" >> timings.txt
%oMVG%\openMVG_main_openMVG2openMVS -i out_Incremental_Reconstruction\sfm_data.bin -o mvs_dir\model.mvs -d mvs_dir
echo "convert to mvs %time%" >> timings.txt
%oMVS%\DensifyPointCloud.exe -i mvs_dir\model.mvs
echo "densifydone %time%">>timings.txt
%oMVS%\ReconstructMesh.exe mvs_dir\model_dense.mvs
echo "reconstructmesh done %time%">>timings.txt
%oMVS%\RefineMesh.exe --resolution-level 2 mvs_dir\model_dense_mesh.mvs
echo "refine done %time%">>timings.txt
%oMVS%\TextureMesh.exe mvs_dir\model_dense_mesh_refine.mvs
echo "all done %time%">>timings.txt

RESULTS

Ok, so first of all, how about reconstruction?  Well, not bad:

styrac_openMVG_proper.JPG

As you can see, that’s quite good, it’s pretty complete.  Bit of a rough patch at the rear right, as is often the case with this dataset.

You can view the 3D model + texture below (I had to crop a little of the extraneous stuff to get it uploaded to sketchfab):

I’m really pleased with the final model, so how about the timings?  Luckily, my script spat all of those out for me:

OpenMVG:

  • List Images:—————————————— 0.5 sec
  • Compute Features——————————— 3 min 33 sec
  • Compute Matches——————————— ~40 sec
  • SfM reconstruction——————————- ~1min 30sec
  • Compute Structure from Known Poses– 15 sec
  • Colour the sparse cloud————————- ~0
  • Convert to openMVS format—————— ~45 sec

(total openMVG time:  6 min 43 sec)

OpenMVS:

  • Densify point cloud——————————- ~12 min
  • Reconstruct Mesh———————————- 4 min
  • Refine Mesh——————————————- ~14 min 20 sec
  • Texture Mesh—————————————- 2 min 8 sec

(total openMVS time:  30 min 50 sec)

Total Time: 37 min 33 sec


How does that compare with my previous favourite COLMAP? My 2017 review states COLMAP + openMVS took 37 minutes.  Except, that was using openMVS to do the dense reconstruction too, so what’s going on? My guess is that the reconstruction from OpenMVG actually contains more info, and thus is a bigger starting point for OpenMVS, which is able to build a higher resolution point cloud/mesh. I also used slightly different parameters. If we really want to be fair, we should run the identical script on COLMAP output.  I like being fair, so I did just that – I took the first half of the above script and replaced it with the relevant portion of my previous COLMAP script, and left the timings in:

COLMAP:

  • Feature extraction—————- 1 min 47 sec

(total COLMAP time: 1 min 47 sec)

OpenMVS:

  • Convert VSfM file to OpenMVS: —– 1 min 30 sec [huh!]
  • Densify—————————————— 8 min 50 sec
  • Reconstruct Mesh————————– ~4 min
  • Refine Mesh———————————– ~13 min
  • Texture Mesh——————————— 2 min

Total Time: 31 min 27 sec

So…  OpenMVS took the same amount of time this time too.  Which is good, I guess.  We can see COLMAP is considerably faster than OpenMVG, and producing a reconstruction of similar quality for openMVS to work on. A surprising part for me was that the conversion from vsfm format to openmvs took well over a minute, which is longer than I expected. The model looked very much the same:

styrac_colmap_propper.JPG

Long story short, openMVG and COLMAP are both excellent, though COLMAP does prove to be quicker, it’s just conversion to openMVS that takes a little time – how well this scales with numbers of images remains to be seen.  However, the dense cloud/mesh reconstruction portion is clearly the difficult part, and I’ve had quite a few issues with openMVS crashing when too much GPU memory is needed.


Explaining my Incompetence:

Ok, so the above was originally posted with times taking over 2 hours, as follows:

OpenMVG+openMVS:

OpenMVG:

  • List Images:—————————————— 1 second
  • Compute Features——————————— 3 min 25 sec
  • Compute Matches——————————— 37 sec
  • SfM reconstruction——————————- ~1min 30sec
  • Compute Structure from Known Poses– 15 sec
  • Colour the sparse cloud————————- ~0
  • Convert to openMVS format—————— ~50 sec

(total openMVG time:  6 min 35 sec)

OpenMVS:

  • Densify point cloud——————————- ~10 min
  • Reconstruct Mesh———————————- 4 min
  • Refine Mesh——————————————- ~1 hr 40min
  • Texture Mesh—————————————- 7 min

(total openMVS time:  2 hr 1 min 43 sec)

Total Time: 2 hours 8 minutes

COLMAP + openMVS

COLMAP:

  • Feature extraction—————- 13 sec
  • Exhaustive Matching———— 24 sec
  • Mapping——————————- 1 min 3 sec
  • conversion to vsfm format—- 0.5 sec

(total COLMAP time: 1 min 40 sec)

OpenMVS:

  • Convert VSfM file to OpenMVS: —– 1 min 40 sec [huh!]
  • Densify—————————————— 9 min 13 sec
  • Reconstruct Mesh————————– 4 min
  • Refine Mesh———————————– 1 hr 39 min
  • Texture Mesh——————————— 7 min

Total Time: 2 hr 2 min

So what went wrong?

Well, long story short, I tried to be clever.  The latter part of original script I used for both test cases looked like this – I’ve bolded the parts different from above:

%oMVS%\DensifyPointCloud --resolution-level 2 mvs_dir\scene.mvs
echo "densify %time%" >> openmvg_mvs_times.txt
%oMVS%\ReconstructMesh.exe --remove-spurious 50 mvs_dir\scene_dense.mvs
echo "mesh %time%" >> openmvg_mvs_times.txt
%oMVS%\RefineMesh.exe --decimate 0.7 --resolution-level 2 mvs_dir\scene_dense_mesh.mvs
echo "refine %time%" >> openmvg_mvs_times.txt
%oMVS%\TextureMesh.exe --export-type obj -o %myfolder%.obj mvs_dir\scene_dense_mesh_refine.mvs
echo "texture %time%" >> openmvg_mvs_times.txt

The timings tell us that it was the refine mesh stage that was taking far, far longer than it now is.  I thought it would be quicker adding the decimation factor.  I was wrong!  Attempting to decimate the mesh with openMVS during the refine mesh stage added a significant amount of time to the process.  The ‘remove spurious’ I added to the reconstruction phase didn’t adversely affect timings, nor did exporting as obj instead of the default ply.

However, arguably the final model retained more detail (or perhaps just noise):

Odd, but we live and learn.  Fun experience!  Here’s the original model on sketchfab for your perusal:

 

Advertisements

8 thoughts on “Photogrammetry Testing 12: Revisiting OpenMVG (with OpenMVS) [updated]

  1. Something is up with your numbers in general. Script execution or printout. There wasn’t a single time from the last set over 117 minutes. Both of these are over 120 each.

    1. Yeah, I need to figure out what’s going on. I’ll re-run some of my previous scripts/commands. Either I’ve changed a variable for openMVS here (likely), or something weird is going on… maybe Spectre/Meltdown patches are slowing this down?

      1. Quick test using VisualSFM to match – my previously reported time for sparse reconstruction was 95 seconds, but it just came in at 110, which depending on how you look at it is ‘just 15 seconds’ or ‘a 16% increase in time taken’.

    2. Good catch on this Timothy – post is updated with ‘proper’ parameters (or at least consistent with previous tests) and both workflows are at 37 minutes now.

      1. Yah I had noticed a SMALL slowdown in some areas after the meltdown / specture update in only some areas but double was a bit strange. Glad to see it worked out!

  2. Thanks for posting these tests, very useful. I wonder how COLMAP’s dense point cloud could be exported to reconstruction in OpenMVS. That would be something. I believe the camera positions are lost for some reason when you export it, whereas sparse works great.

  3. Thanks for the article! Would it be possible to reduce the time spent to generate the mesh down to less than 5 minutes if one is willing to sacrifice on quality?

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.