cdcseacave / openMVS

open Multi-View Stereo reconstruction library
http://cdcseacave.github.io
GNU Affero General Public License v3.0
3.3k stars 906 forks source link

A `tutorial` for `colmap` to `openMVS` #692

Open FavorMylikes opened 3 years ago

FavorMylikes commented 3 years ago

Through a lot of reading about those doc and issue.

I wanna write a tutorial for fresh people.

This is prepare for linux server (means no desktop)

And I have compile the latest version colmap and openmvs

Step 1

colmap feature_extractor\
--SiftExtraction.use_gpu 0 \
--ImageReader.camera_model PINHOLE \
--database_path $PROJECT/database.db\
--image_path $DATA_ROOT/$PROJECT/images

Step 2

colmap exhaustive_matcher\
--SiftMatching.use_gpu 0\
--database_path $PROJECT/database.db

Step 3

colmap mapper\
--database_path $PROJECT/database.db \
--image_path $DATA_ROOT/$PROJECT/images \
--output_path $PROJECT/sparse 

Step 4

colmap model_converter \
--input_path $PROJECT/sparse/0 \
--output_path $PROJECT/sparse  \
--output_type TXT

Step 5

InterfaceCOLMAP \
--working-folder $(pwd)/$PROJECT/ \
--input-file $(pwd)/$PROJECT/ \
--output-file $(pwd)/$PROJECT/model_colmap.mvs

Step 6

DensifyPointCloud \
--input-file $(pwd)/$PROJECT/model_colmap.mvs \
--working-folder $(pwd)/$PROJECT/ \
--output-file $(pwd)/$PROJECT/model_dense.mvs \
--archive-type -1 \

Step 7

ReconstructMesh --input-file $(pwd)/$PROJECT/model_dense.mvs \
--working-folder $(pwd)/$PROJECT/ \
--output-file $(pwd)/$PROJECT/model_dense_mesh.mvs

Step 8

RefineMesh \
--resolution-level 1 \
--input-file $(pwd)/$PROJECT/model_dense_mesh.mvs \
--working-folder $(pwd)/$PROJECT/ \
--output-file $(pwd)/$PROJECT/model_dense_mesh_refine.mvs

Step 9

TextureMesh \
--export-type obj \
--output-file $(pwd)/$PROJECT/model.obj \
--working-folder $(pwd)/$PROJECT/ \
--input-file $(pwd)/$PROJECT/model_dense_mesh_refine.mvs

FINAL

Attantion

cdcseacave commented 3 years ago

Thanks for putting this tutorial together, but there are some mistakes, like:

FavorMylikes commented 3 years ago

@cdcseacave Thanks for correction.

Update

Step 1

colmap feature_extractor \
--SiftExtraction.use_gpu 0 \
--database_path $PROJECT/database.db\
--image_path $DATA_ROOT/$PROJECT/images

Step 4

Step 4.1

colmap image_undistorter \
--image_path $DATA_ROOT/$PROJECT/images \
--input_path $PROJECT/sparse/0 \
--output_path $PROJECT/dense \
--output_type COLMAP \

Step 4.2

colmap model_converter \
--input_path $PROJECT/dense/sparse \
--output_path $PROJECT/dense/sparse  \
--output_type TXT

Why am I use absolute path $(pwd)

thomas-graphopti commented 2 years ago

Helps a lot, Thanks!

GraphOpti commented 2 years ago

I combined the command lines into a script. That requires config the $working_folder and $openmvs_bin_path. The images store in the folder $working_folder/images. It will automatically transfer images into textured mode (obj).

#!/bin/bash
working_folder=..../
images_folder=$working_folder/images
database_folder=$working_folder/database.db
output_folder=$working_folder/sparse/
openmvs_bin_path=...../openMVS/build/bin
use_gpu=1
mkdir -p $output_folder
mkdir -p $output_folder/0
echo ">>>>>>>>>>>>>>Starting colmap feature extraction"
colmap feature_extractor \
--SiftExtraction.use_gpu $use_gpu \
--ImageReader.camera_model OPENCV \
--database_path $database_folder \
--image_path $images_folder \
echo ">>>>>>>>>>>>>>Starting colmap exhaustive matching"
colmap exhaustive_matcher \
--SiftMatching.use_gpu $use_gpu \
--database_path $database_folder \
echo ">>>>>>>>>>>>>>Starting colmap mapping"
colmap mapper \
--database_path $database_folder \
--image_path $images_folder \
--output_path $output_folder \
echo "image undistort"
sudo colmap image_undistorter \
--image_path $images_folder \
--input_path $output_folder/0 \
--output_path $working_folder/dense \
--output_type COLMAP \
echo ">>>>>>>>>>>>>>Start colmap model_converter"
colmap model_converter \
--input_path $working_folder/dense/sparse \
--output_path $working_folder/dense/sparse \
--output_type TXT
echo ">>>>>>>>>>>>>>Starting InterfaceCOLMAP"
echo $working_folder/dense
cd $openmvs_bin_path
sudo ./InterfaceCOLMAP \
--working-folder $working_folder \
-i $working_folder/dense/ \
--output-file $working_folder/model_colmap.mvs \
echo ">>>>>>>>>>>>>>>Starting DensifyPointCloud"
echo $working_folder/model_colmap.mvs
cd $openmvs_bin_path
sudo ./DensifyPointCloud \
--input-file $working_folder/model_colmap.mvs \
--working-folder $working_folder \
--output-file $working_folder/model_dense.mvs \
#--archive-type -1\
echo ">>>>>>>>>>>>>>>>Starting ReconstructMesh"
cd $openmvs_bin_path
sudo ./ReconstructMesh \
--input-file $working_folder/model_dense.mvs \
--working-folder $working_folder \
--output-file $working_folder/model_dense_mesh.mvs
echo ">>>>>>>>>>>Refine mesh"
cd $openmvs_bin_path
sudo ./RefineMesh \
--resolution-level 1 \
--input-file $working_folder/model_dense_mesh.mvs \
--working-folder $working_folder \
--output-file $working_folder/model_dense_mesh_refine.mvs
echo ">>>>>>>>>> Texture mesh"
sudo ./TextureMesh \
--export-type obj \
--output-file $working_folder/openmvs_model.obj \
--working-folder $working_folder/ \
--input-file $working_folder/model_dense_mesh_refine.mvs
echo "Finishing script. The final model is locate at"
echo $working_folder
echo "/model.obj"
shinxg commented 1 year ago

Through a lot of reading about those doc and issue.

I wanna write a tutorial for fresh people.

This is prepare for linux server (means no desktop)

And I have compile the latest version colmap and openmvs

Step 1

colmap feature_extractor\
--SiftExtraction.use_gpu 0 \
--ImageReader.camera_model PINHOLE \
--database_path $PROJECT/database.db\
--image_path $DATA_ROOT/$PROJECT/images
  • here --SiftExtraction.use_gpu is using for linux server only, you can comment it out if you have desktop.
  • --ImageReader.camera_model PINHOLE, you could choice other one, check the list camera model
  • For using InterfaceCOLMAP, you must specify PINHOLE model

Step 2

colmap exhaustive_matcher\
--SiftMatching.use_gpu 0\
--database_path $PROJECT/database.db
  • here --SiftMatching.use_gpu 0 has same effect with SiftExtraction.use_gpu

Step 3

colmap mapper\
--database_path $PROJECT/database.db \
--image_path $DATA_ROOT/$PROJECT/images \
--output_path $PROJECT/sparse 

Step 4

colmap model_converter \
--input_path $PROJECT/sparse/0 \
--output_path $PROJECT/sparse  \
--output_type TXT
  • Under this step, you will see three txt file will be created at sparse dir.

    • cameras.txt, images.txt, point3D.txt
    • And PINHOLE is in cameras.txt you will see

Step 5

InterfaceCOLMAP \
--working-folder $(pwd)/$PROJECT/ \
--input-file $(pwd)/$PROJECT/ \
--output-file $(pwd)/$PROJECT/model_colmap.mvs

Step 6

DensifyPointCloud \
--input-file $(pwd)/$PROJECT/model_colmap.mvs \
--working-folder $(pwd)/$PROJECT/ \
--output-file $(pwd)/$PROJECT/model_dense.mvs \
--archive-type -1 \
  • Here --archive-type -1 must be set

Step 7

ReconstructMesh --input-file $(pwd)/$PROJECT/model_dense.mvs \
--working-folder $(pwd)/$PROJECT/ \
--output-file $(pwd)/$PROJECT/model_dense_mesh.mvs

Step 8

RefineMesh \
--resolution-level 1 \
--input-file $(pwd)/$PROJECT/model_dense_mesh.mvs \
--working-folder $(pwd)/$PROJECT/ \
--output-file $(pwd)/$PROJECT/model_dense_mesh_refine.mvs

Step 9

TextureMesh \
--export-type obj \
--output-file $(pwd)/$PROJECT/model.obj \
--working-folder $(pwd)/$PROJECT/ \
--input-file $(pwd)/$PROJECT/model_dense_mesh_refine.mvs

FINAL

  • You will get model.mtl model.obj and the texure model_material_0_map_Kd.jpg
  • Open obj with software you like, I'll recommend MAYA

Attantion

  • It is a little bit confusing
  • Unlike other document, I have to delete images path under --working-folder args.
  • I'm not sure if it is a bug.

Does this support --mask-path option in the DensifyPointCloud process? I tried with the following commands with --mask-path and without --mask-path and found that there is no difference in the output pointcloud file: ./bin/DensifyPointCloud --input-file /data1/wutong/Ali_Data/3D/fila_my1/model_colmap.mvs --working-folder /data1/wutong/Ali_Data/3D/fila_my1 --output-file /data1/wutong/Ali_Data/3D/fila_my1/model_dense.mvs --archive-type -1 --mask-path /data1/wutong/Ali_Data/3D/fila_my1/masks --ignore-mask-label 0 --filter-point-cloud 1

./bin/DensifyPointCloud --input-file /data1/wutong/Ali_Data/3D/fila_my1/model_colmap.mvs --working-folder /data1/wutong/Ali_Data/3D/fila_my1 --output-file /data1/wutong/Ali_Data/3D/fila_my1/model_dense.mvs --archive-type -1

cdcseacave commented 1 year ago

great tutorial, thank you! could you pls modify the MvgMvsPipeline.py script to add COLMAP steps as additional steps in the script so that newcomers can run just one script that does both COLMAP and OpenMVS reconstruction?

cdcseacave commented 1 year ago

@FavorMylikes ^

FavorMylikes commented 1 year ago

@cdcseacave All right, I'm very glad to do this

citystrawman commented 7 months ago

Hi, thank you for this great pipeline tutorial! I am trying to reallize this pipeline on my computer but at step 7, the ReconstructMesh, I just can't get the .mvs file. It is strange because after execute the program, I can get model_dense_mesh.mlp as well as model_dense_mesh.ply, the only file that I do not get is the mvs file. Do you have any idea of this problem? Thank you.

cdcseacave commented 7 months ago

you do not need the MVS file for the mesh stage, use the same MVS file

citystrawman commented 7 months ago

you do not need the MVS file for the mesh stage, use the same MVS file

Hi, I tried to use the old mvs file (model_dense.mvs that is generated in step 6) for step8(RefineMesh) as well as step9(TextureMesh), but both of the two give error saying "error: invalid mesh file, cannot load mesh file". I am not sure what is going wrong.

ps: my script is as follows:

 echo ==================Refine mesh==================
 RefineMesh.exe ^
 --resolution-level 1 ^
 --input-file E:\sfm_mvs_pipeline_test\project\model_dense.mvs ^
 --working-folder E:\sfm_mvs_pipeline_test\project ^
 --output-file E:\sfm_mvs_pipeline_test\project\model_dense_mesh_refine.mvs
 echo ==================Texture mesh==================
TextureMesh.exe ^
 --export-type obj ^
 --output-file E:\sfm_mvs_pipeline_test\project\openmvs_model.obj ^
 --working-folder E:\sfm_mvs_pipeline_test\project ^
 --input-file E:\sfm_mvs_pipeline_test\project\model_dense.mvs
cdcseacave commented 7 months ago

Pls see the wiki

On Sat, Feb 10, 2024 at 04:59 citystrawman @.***> wrote:

you do not need the MVS file for the mesh stage, use the same MVS file

Hi, I tried to use the old mvs file (model_dense.mvs that is generated in step 6) for step8(RefineMesh) as well as step9(TextureMesh), but neither of the two give error saying "error: invalid mesh file, cannot load mesh file". I am not sure what is going wrong.

— Reply to this email directly, view it on GitHub https://github.com/cdcseacave/openMVS/issues/692#issuecomment-1936829345, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVMH3QJUS5NU3BSEMMV6TDYS3PBRAVCNFSM5CAJW3R2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJTGY4DEOJTGQ2Q . You are receiving this because you were mentioned.Message ID: @.***>

citystrawman commented 7 months ago

Pls see the wiki On Sat, Feb 10, 2024 at 04:59 citystrawman @.> wrote: you do not need the MVS file for the mesh stage, use the same MVS file Hi, I tried to use the old mvs file (model_dense.mvs that is generated in step 6) for step8(RefineMesh) as well as step9(TextureMesh), but neither of the two give error saying "error: invalid mesh file, cannot load mesh file". I am not sure what is going wrong. — Reply to this email directly, view it on GitHub <#692 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVMH3QJUS5NU3BSEMMV6TDYS3PBRAVCNFSM5CAJW3R2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJTGY4DEOJTGQ2Q . You are receiving this because you were mentioned.Message ID: @.>

Thank you. Now I ran code like this: TextureMesh model_dense.mvs -m model_dense_mesh.ply -o model_texture.mvs , and it does not report errors; however, it shows that some library failed load, and now the program just stuck at "Initialized views" for hours. Here's the last lines that I copied :

17:47:59 [App     ] Mesh loaded: 520355 vertices, 1040677 faces (467ms)
[ INFO:0@23.578] global registry_parallel.impl.hpp:96 cv::parallel::ParallelBackendRegistry::ParallelBackendRegistry core(parallel): Enabled backends(3, sorted by priority): ONETBB(1000); TBB(990); OPENMP(980)
[ INFO:0@23.579] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load D:\programs\openMVS\make\bin\vc16\x64\Debug\opencv_core_parallel_onetbb480_64d.dll => FAILED
[ INFO:0@23.746] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_onetbb480_64d.dll => FAILED
[ INFO:0@23.749] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load D:\programs\openMVS\make\bin\vc16\x64\Debug\opencv_core_parallel_tbb480_64d.dll => FAILED
[ INFO:0@23.922] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_tbb480_64d.dll => FAILED
[ INFO:0@23.929] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load D:\programs\openMVS\make\bin\vc16\x64\Debug\opencv_core_parallel_openmp480_64d.dll => FAILED
[ INFO:0@23.937] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_openmp480_64d.dll => FAILED
Initialized views 33 (100%, 1m14s642ms)
cdcseacave commented 7 months ago

It is slow in debug, recompile in release

On Sat, Feb 10, 2024 at 13:05 citystrawman @.***> wrote:

Pls see the wiki … <#m-286968189595765442> On Sat, Feb 10, 2024 at 04:59 citystrawman @.> wrote: you do not need the MVS file for the mesh stage, use the same MVS file Hi, I tried to use the old mvs file (model_dense.mvs that is generated in step 6) for step8(RefineMesh) as well as step9(TextureMesh), but neither of the two give error saying "error: invalid mesh file, cannot load mesh file". I am not sure what is going wrong. — Reply to this email directly, view it on GitHub <#692 (comment) https://github.com/cdcseacave/openMVS/issues/692#issuecomment-1936829345>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVMH3QJUS5NU3BSEMMV6TDYS3PBRAVCNFSM5CAJW3R2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJTGY4DEOJTGQ2Q https://github.com/notifications/unsubscribe-auth/AAVMH3QJUS5NU3BSEMMV6TDYS3PBRAVCNFSM5CAJW3R2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJTGY4DEOJTGQ2Q . You are receiving this because you were mentioned.Message ID: @.>

Thank you. Now I ran code like this: TextureMesh model_dense.mvs -m model_dense_mesh.ply -o model_texture.mvs , and it does not report errors; however, it shows that some library failed load, and now the program just stuck at "Initialized views" for hours. Here's the last lines that I copied :

17:47:59 [App ] Mesh loaded: 520355 vertices, 1040677 faces (467ms) [ @. global registry_parallel.impl.hpp:96 cv::parallel::ParallelBackendRegistry::ParallelBackendRegistry core(parallel): Enabled backends(3, sorted by priority): ONETBB(1000); TBB(990); OPENMP(980) [ @. global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load D:\programs\openMVS\make\bin\vc16\x64\Debug\opencv_core_parallel_onetbb480_64d.dll => FAILED [ @. global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_onetbb480_64d.dll => FAILED [ @. global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load D:\programs\openMVS\make\bin\vc16\x64\Debug\opencv_core_parallel_tbb480_64d.dll => FAILED [ @. global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_tbb480_64d.dll => FAILED [ @. global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load D:\programs\openMVS\make\bin\vc16\x64\Debug\opencv_core_parallel_openmp480_64d.dll => FAILED [ @.*** global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_openmp480_64d.dll => FAILED Initialized views 33 (100%, 1m14s642ms)

— Reply to this email directly, view it on GitHub https://github.com/cdcseacave/openMVS/issues/692#issuecomment-1936974601, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVMH3SBO44SQG4D5HTOTYDYS5IAXAVCNFSM5CAJW3R2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJTGY4TONBWGAYQ . You are receiving this because you were mentioned.Message ID: @.***>