OpenMVS 的编译与运行

Title: OpenMVS 的编译与运行



简单记录一下,备忘.

I. 编译与准备

1. 获得源码

git clone https://github.com/cdcseacave/openMVS.git

切换分支:

git checkout develop

一些 bug 在 develop 版本中修正了, 比如程序自己 “killed” 退出.

2. wiki

https://github.com/cdcseacave/openMVS/wiki/Usage

3. 退出 Conda 环境

隔离 Conda 环境与系统库, 不然容易冲突. 原先在 docker 容器的 conda 虚拟环境中编译, 版本冲突较多.

conda deactivate

4. 编译

makedir openMVS_build
cd openMVS_build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4
make install

说明:

在 docker 的 ubuntu24 镜像下, 没有能够生成 Viewer. cmake 步骤中提示 -- Can't find GLAD. Continuing without it. 尝试好多次都没能配置成功.
Windows 下应该更容易生成 Viewer.

5. 数据准备

参考博文 https://blog.csdn.net/yangyu0515/article/details/129235389

.
|-- images
|   |-- 00000.jpg
|   |-- 00001.jpg
|   |-- 00002.jpg
|   |-- 00003.jpg
|   |-- 00004.jpg
|   |-- 00005.jpg
|   |-- 00006.jpg
|   |-- 00007.jpg
|   |-- 00008.jpg
|   |-- 00009.jpg
|   `-- 00010.jpg
`-- scene.mvs

II. 命令了解

1. 稠密重建 DensifyPointCloud

../openMVS_build/bin/DensifyPointCloud -h
17:14:59 [App     ] OpenMVS x64 v2.3.0
17:14:59 [App     ] Build date: May  7 2025, 16:53:39
17:14:59 [App     ] CPU: Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz (64 cores)
17:14:59 [App     ] RAM: 31.05GB Physical Memory 9.31GB Virtual Memory
17:14:59 [App     ] OS: Linux 5.14.0-1059-oem (x86_64)
17:14:59 [App     ] Disk: 416.64GB (881.87GB) space
17:14:59 [App     ] SSE & AVX compatible CPU & OS detected
17:14:59 [App     ] Command line: DensifyPointCloud -h
17:14:59 [App     ] Available options:

Generic options:
  -h [ --help ]                         produce this help message
  -w [ --working-folder ] arg           working directory (default current 
                                        directory)
  -c [ --config-file ] arg (=DensifyPointCloud.cfg)
                                        file name containing program options
  --archive-type arg (=-1)              project archive type: -1-interface, 
                                        0-text, 1-binary, 2-compressed binary
  --process-priority arg (=-1)          process priority (below normal by 
                                        default)
  --max-threads arg (=0)                maximum number of threads (0 for using 
                                        all available cores)
  -v [ --verbosity ] arg (=2)           verbosity level

Densify options:
  -i [ --input-file ] arg               input filename containing camera poses 
                                        and image list
  -p [ --pointcloud-file ] arg          sparse point-cloud with views file name
                                        to densify (overwrite existing 
                                        point-cloud)
  -m [ --mask-path ] arg                path to folder containing mask images 
                                        with '.mask.png' extension
  -o [ --output-file ] arg              output filename for storing the dense 
                                        point-cloud (optional)
  --view-neighbors-file arg             input filename containing the list of 
                                        views and their neighbors (optional)
  --output-view-neighbors-file arg      output filename containing the 
                                        generated list of views and their 
                                        neighbors
  --resolution-level arg (=1)           how many times to scale down the images
                                        before point-cloud computation
  --max-resolution arg (=2560)          do not scale images higher than this 
                                        resolution
  --min-resolution arg (=640)           do not scale images lower than this 
                                        resolution
  --sub-resolution-levels arg (=2)      number of patch-match sub-resolution 
                                        iterations (0 - disabled)
  --number-views arg (=5)               number of views used for depth-map 
                                        estimation (0 - all neighbor views 
                                        available)
  --number-views-fuse arg (=2)          minimum number of images that agrees 
                                        with an estimate during fusion in order
                                        to consider it inlier (<2 - only merge 
                                        depth-maps)
  --ignore-mask-label arg (=-1)         label value to ignore in the image 
                                        mask, stored in the MVS scene or next 
                                        to each image with '.mask.png' 
                                        extension (<0 - disabled)
  --iters arg (=3)                      number of patch-match iterations
  --geometric-iters arg (=2)            number of geometric consistent 
                                        patch-match iterations (0 - disabled)
  --estimate-colors arg (=2)            estimate the colors for the dense 
                                        point-cloud (0 - disabled, 1 - final, 2
                                        - estimate)
  --estimate-normals arg (=2)           estimate the normals for the dense 
                                        point-cloud (0 - disabled, 1 - final, 2
                                        - estimate)
  --estimate-scale arg (=0)             estimate the point-scale for the dense 
                                        point-cloud (scale multiplier, 0 - 
                                        disabled)
  --estimate-segmentation arg (=0)      estimate segmentation of the dense 
                                        point-cloud based on the image 
                                        segmentation masks; num views to agree 
                                        (0 - disabled, <0 - only segmentation)
  --sub-scene-area arg (=0)             split the scene in sub-scenes such that
                                        each sub-scene surface does not exceed 
                                        the given maximum sampling area (0 - 
                                        disabled)
  --sample-mesh arg (=0)                uniformly samples points on a mesh (0 -
                                        disabled, <0 - number of points, >0 - 
                                        sample density per square unit)
  --fusion-mode arg (=0)                depth-maps fusion mode (-2 - fuse 
                                        disparity-maps, -1 - export 
                                        disparity-maps only, 0 - depth-maps & 
                                        fusion, 1 - export depth-maps only)
  --fusion-filter arg (=2)              filter used to fuse the depth-maps (0 -
                                        merge, 1 - fuse, 2 - dense-fuse)
  --postprocess-dmaps arg (=0)          flags used to filter the depth-maps 
                                        after estimation (0 - disabled, 1 - 
                                        remove-speckles, 2 - fill-gaps, 4 - 
                                        adjust-confidence)
  --filter-point-cloud arg (=0)         filter dense point-cloud based on 
                                        visibility (0 - disabled)
  --export-number-views arg (=0)        export points with >= number of views 
                                        (0 - disabled, <0 - save MVS project 
                                        too)
  --roi-border arg (=0)                 add a border to the region-of-interest 
                                        when cropping the scene (0 - disabled, 
                                        >0 - percentage, <0 - absolute)
  --estimate-roi arg (=2)               estimate and set region-of-interest (0 
                                        - disabled, 1 - enabled, 2 - adaptive)
  --crop-to-roi arg (=1)                crop scene using the region-of-interest
  --remove-dmaps arg (=0)               remove depth-maps after fusion
  --tower-mode arg (=4)                 add a cylinder of points in the center 
                                        of ROI; scene assume to be Z-up 
                                        oriented (0 - disabled, 1 - replace, 2 
                                        - append, 3 - select neighbors, 4 - 
                                        select neighbors & append, <0 - force 
                                        tower mode)
  --normalize-coordinates arg (=0)      normalize scene coordinates and output 
                                        the inverse transform to file (0 - 
                                        disabled, 1 - center, 2 - center & 
                                        scale17:14:59 [App     ] MEMORYINFO: {
17:14:59 [App     ] 	VmPeak:	  182316 kB
17:14:59 [App     ] 	VmSize:	  182256 kB
17:14:59 [App     ] } ENDINFO

2. 曲面重建 ReconstructMesh

../openMVS_build/bin/ReconstructMesh -h
17:17:23 [App     ] OpenMVS x64 v2.3.0
17:17:23 [App     ] Build date: May  7 2025, 16:53:39
17:17:23 [App     ] CPU: Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz (64 cores)
17:17:23 [App     ] RAM: 31.05GB Physical Memory 9.31GB Virtual Memory
17:17:23 [App     ] OS: Linux 5.14.0-1059-oem (x86_64)
17:17:23 [App     ] Disk: 416.64GB (881.87GB) space
17:17:23 [App     ] SSE & AVX compatible CPU & OS detected
17:17:23 [App     ] Command line: ReconstructMesh -h
17:17:23 [App     ] Available options:

Generic options:
  -h [ --help ]                         produce this help message
  -w [ --working-folder ] arg           working directory (default current 
                                        directory)
  -c [ --config-file ] arg (=ReconstructMesh.cfg)
                                        file name containing program options
  --export-type arg (=ply)              file type used to export the 3D scene 
                                        (ply or obj)
  --archive-type arg (=4294967295)      project archive type: -1-interface, 
                                        0-text, 1-binary, 2-compressed binary
  --process-priority arg (=-1)          process priority (below normal by 
                                        default)
  --max-threads arg (=0)                maximum number of threads (0 for using 
                                        all available cores)
  -v [ --verbosity ] arg (=2)           verbosity level

Reconstruct options:
  -i [ --input-file ] arg               input filename containing camera poses 
                                        and image list
  -p [ --pointcloud-file ] arg          dense point-cloud with views file name 
                                        to reconstruct (overwrite existing 
                                        point-cloud)
  -o [ --output-file ] arg              output filename for storing the mesh
  -d [ --min-point-distance ] arg (=1.5)
                                        minimum distance in pixels between the 
                                        projection of two 3D points to consider
                                        them different while triangulating (0 -
                                        disabled)
  --integrate-only-roi arg (=0)         use only the points inside the ROI
  --constant-weight arg (=1)            considers all view weights 1 instead of
                                        the available weight
  -f [ --free-space-support ] arg (=0)  exploits the free-space support in 
                                        order to reconstruct weakly-represented
                                        surfaces
  --thickness-factor arg (=1)           multiplier adjusting the minimum 
                                        thickness considered during visibility 
                                        weighting
  --quality-factor arg (=1)             multiplier adjusting the quality weight
                                        considered during graph-cut

Clean options:
  --decimate arg (=1)                   decimation factor in range (0..1] to be
                                        applied to the reconstructed surface (1
                                        - disabled)
  --target-face-num arg (=0)            target number of faces to be applied to
                                        the reconstructed surface. (0 - 
                                        disabled)
  --remove-spurious arg (=20)           spurious factor for removing faces with
                                        too long edges or isolated components 
                                        (0 - disabled)
  --remove-spikes arg (=1)              flag controlling the removal of spike 
                                        faces
  --close-holes arg (=30)               try to close small holes in the 
                                        reconstructed surface (0 - disabled)
  --smooth arg (=2)                     number of iterations to smooth the 
                                        reconstructed surface (0 - disabled)
  --edge-length arg (=0)                remesh such that the average edge 
                                        length is this size (0 - disabled)
  --roi-border arg (=0)                 add a border to the region-of-interest 
                                        when cropping the scene (0 - disabled, 
                                        >0 - percentage, <0 - absolute)
  --crop-to-roi arg (=1)                crop scene using the region-of-interes17:17:23 [App     ] MEMORYINFO: {
17:17:23 [App     ] 	VmPeak:	  179168 kB
17:17:23 [App     ] 	VmSize:	  179108 kB
17:17:23 [App     ] } ENDINFO

3. 网格优化 RefineMesh

../openMVS_build/bin/RefineMesh -h
17:21:23 [App     ] OpenMVS x64 v2.3.0
17:21:23 [App     ] Build date: May  7 2025, 16:53:39
17:21:23 [App     ] CPU: Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz (64 cores)
17:21:23 [App     ] RAM: 31.05GB Physical Memory 9.31GB Virtual Memory
17:21:23 [App     ] OS: Linux 5.14.0-1059-oem (x86_64)
17:21:23 [App     ] Disk: 416.64GB (881.87GB) space
17:21:23 [App     ] SSE & AVX compatible CPU & OS detected
17:21:23 [App     ] Command line: RefineMesh -h
17:21:23 [App     ] Available options:

Generic options:
  -h [ --help ]                         produce this help message
  -w [ --working-folder ] arg           working directory (default current 
                                        directory)
  -c [ --config-file ] arg (=RefineMesh.cfg)
                                        file name containing program options
  --export-type arg (=ply)              file type used to export the 3D scene 
                                        (ply or obj)
  --archive-type arg (=4294967295)      project archive type: -1-interface, 
                                        0-text, 1-binary, 2-compressed binary
  --process-priority arg (=-1)          process priority (below normal by 
                                        default)
  --max-threads arg (=0)                maximum number of threads (0 for using 
                                        all available cores)
  -v [ --verbosity ] arg (=2)           verbosity level

Refine options:
  -i [ --input-file ] arg               input filename containing camera poses 
                                        and image list
  -m [ --mesh-file ] arg                mesh file name to refine (overwrite 
                                        existing mesh)
  -o [ --output-file ] arg              output filename for storing the mesh
  --resolution-level arg (=0)           how many times to scale down the images
                                        before mesh refinement
  --min-resolution arg (=640)           do not scale images lower than this 
                                        resolution
  --max-views arg (=8)                  maximum number of neighbor images used 
                                        to refine the mesh
  --decimate arg (=0)                   decimation factor in range [0..1] to be
                                        applied to the input surface before 
                                        refinement (0 - auto, 1 - disabled)
  --close-holes arg (=30)               try to close small holes in the input 
                                        surface (0 - disabled)
  --ensure-edge-size arg (=1)           ensure edge size and improve vertex 
                                        valence of the input surface (0 - 
                                        disabled, 1 - auto, 2 - force)
  --max-face-area arg (=32)             maximum face area projected in any pair
                                        of images that is not subdivided (0 - 
                                        disabled)
  --scales arg (=2)                     how many iterations to run mesh 
                                        optimization on multi-scale images
  --scale-step arg (=0.5)               image scale factor used at each mesh 
                                        optimization step
  --alternate-pair arg (=0)             refine mesh using an image pair 
                                        alternatively as reference (0 - both, 1
                                        - alternate, 2 - only left, 3 - only 
                                        right)
  --regularity-weight arg (=0.200000003)
                                        scalar regularity weight to balance 
                                        between photo-consistency and 
                                        regularization terms during mesh 
                                        optimization
  --rigidity-elasticity-ratio arg (=0.899999976)
                                        scalar ratio used to compute the 
                                        regularity gradient as a combination of
                                        rigidity and elasticity
  --gradient-step arg (=45.0499992)     gradient step to be used instead (0 - 
                                        auto)
  --planar-vertex-ratio arg (=0)        threshold used to remove vertices on 
                                        planar patches (0 - disabled)
  --reduce-memory arg (=1)              recompute some data in order to reduce 
                                        memory requirement17:21:23 [App     ] MEMORYINFO: {
17:21:23 [App     ] 	VmPeak:	  178968 kB
17:21:23 [App     ] 	VmSize:	  178908 kB
17:21:23 [App     ] } ENDINFO

4. 纹理贴图 TextureMesh

../openMVS_build/bin/TextureMesh -h
17:22:19 [App     ] OpenMVS x64 v2.3.0
17:22:19 [App     ] Build date: May  7 2025, 16:53:39
17:22:19 [App     ] CPU: Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz (64 cores)
17:22:19 [App     ] RAM: 31.05GB Physical Memory 9.31GB Virtual Memory
17:22:19 [App     ] OS: Linux 5.14.0-1059-oem (x86_64)
17:22:19 [App     ] Disk: 416.64GB (881.87GB) space
17:22:19 [App     ] SSE & AVX compatible CPU & OS detected
17:22:19 [App     ] Command line: TextureMesh -h
17:22:19 [App     ] Available options:

Generic options:
  -h [ --help ]                         produce this help message
  -w [ --working-folder ] arg           working directory (default current 
                                        directory)
  -c [ --config-file ] arg (=TextureMesh.cfg)
                                        file name containing program options
  --export-type arg (=ply)              file type used to export the 3D scene 
                                        (ply, obj, glb or gltf)
  --archive-type arg (=4294967295)      project archive type: -1-interface, 
                                        0-text, 1-binary, 2-compressed binary
  --process-priority arg (=-1)          process priority (below normal by 
                                        default)
  --max-threads arg (=0)                maximum number of threads (0 for using 
                                        all available cores)
  -v [ --verbosity ] arg (=2)           verbosity level

Texture options:
  -i [ --input-file ] arg               input filename containing camera poses 
                                        and image list
  -m [ --mesh-file ] arg                mesh file name to texture (overwrite 
                                        existing mesh)
  -o [ --output-file ] arg              output filename for storing the mesh
  --decimate arg (=1)                   decimation factor in range [0..1] to be
                                        applied to the input surface before 
                                        refinement (0 - auto, 1 - disabled)
  --close-holes arg (=30)               try to close small holes in the input 
                                        surface (0 - disabled)
  --resolution-level arg (=0)           how many times to scale down the images
                                        before mesh refinement
  --min-resolution arg (=640)           do not scale images lower than this 
                                        resolution
  --outlier-threshold arg (=0.0599999987)
                                        threshold used to find and remove 
                                        outlier face textures (0 - disabled)
  --cost-smoothness-ratio arg (=0.100000001)
                                        ratio used to adjust the preference for
                                        more compact patches (1 - best 
                                        quality/worst compactness, ~0 - worst 
                                        quality/best compactness)
  --virtual-face-images arg (=0)        generate texture patches using virtual 
                                        faces composed of coplanar triangles 
                                        sharing at least this number of views 
                                        (0 - disabled, 3 - good value)
  --global-seam-leveling arg (=1)       generate uniform texture patches using 
                                        global seam leveling
  --local-seam-leveling arg (=1)        generate uniform texture patch borders 
                                        using local seam leveling
  --texture-size-multiple arg (=0)      texture size should be a multiple of 
                                        this value (0 - power of two)
  --patch-packing-heuristic arg (=3)    specify the heuristic used when 
                                        deciding where to place a new patch (0 
                                        - best fit, 3 - good speed, 100 - best 
                                        speed)
  --empty-color arg (=16744231)         color used for faces not covered by any
                                        image
  --sharpness-weight arg (=0.5)         amount of sharpness to be applied on 
                                        the texture (0 - disabled)
  --orthographic-image-resolution arg (=0)
                                        orthographic image resolution to be 
                                        generated from the textured mesh - the 
                                        mesh is expected to be already 
                                        geo-referenced or at least properly 
                                        oriented (0 - disabled)
  --ignore-mask-label arg (=-1)         label value to ignore in the image 
                                        mask, stored in the MVS scene or next 
                                        to each image with '.mask.png' 
                                        extension (-1 - auto estimate mask for 
                                        lens distortion, -2 - disabled)
  --max-texture-size arg (=8192)        maximum texture size, split it in 
                                        multiple textures of this size if 
                                        needed (0 - unbounded17:22:19 [App     ] MEMORYINFO: {
17:22:19 [App     ] 	VmPeak:	  179196 kB
17:22:19 [App     ] 	VmSize:	  179136 kB
17:22:19 [App     ] } ENDINFO

III. 命令运行

1. 运行稠密重建

../openMVS_build/bin/DensifyPointCloud scene.mvs

生成 scene_dense.mvsscene_dense.ply 稠密点云模型. 其中 scene_dense.mvs 主要描述相机位姿、特征匹配等, 后面的命令中都用同一个 .mvs 文件.

2. 运行网格重建

../openMVS_build/bin/ReconstructMesh -i scene_dense.mvs

生成 scene_dense_mesh.ply 网格重建的三维模型.

3. 运行网格优化

上一步的输出作为下一步的输入, 输入的 .mvs 和 .ply 需要同名. scene_dense.mvs 复制一份为 scene_dense_mesh.mvs.

cp scene_dense.mvs scene_dense_mesh.mvs

直接运行 RefineMesh, 应该电脑内存不够的缘故, 程序自己 “killed” 退出了.

../openMVS_build/bin/RefineMesh -i scene_dense_mesh.mvs

降低精度等级就可以运行, 但是这相当于降采样了, 还不如上一步获得效果好. 这一步会生成 scene_dense_mesh_refine.ply.

../openMVS_build/bin/RefineMesh -i scene_dense_mesh.mvs --resolution-level 1

注意: RefineMesh 只是优化/微调 mesh 三维模型, 不是必须要处理的步骤. 这一步可以跳过.

4. 运行纹理贴图

如果使用网格重建中生成的 scene_dense_mesh.ply 来做纹理贴图, 则直接运行

../openMVS_build/bin/TextureMesh -i scene_dense_mesh.mvs

生成 scene_dense_mesh_texture.plyscene_dense_mesh_texture0.png. 这两个文件放在同一文件夹下, meshlab 打开 scene_dense_mesh_texture.ply 就可获得纹理贴图效果. 注意 conda 虚拟环境也可能引起冲突, 退出虚拟环境即可.

如果使用网格优化中生成 .ply 来做纹理贴图, 还是需要先复制一份 .mvs, 然后再运行纹理贴图命令.

cp scene_dense.mvs scene_dense_mesh_refine.mvs
../openMVS_build/bin/TextureMesh -i scene_dense_mesh_refine.mvs

IV. 简单结果

点云 网格 纹理

版权声明:本文为博主原创文章,遵循 CC 4.0 BY 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/woyaomaishu2/article/details/147773670
本文作者:wzf@robotics_notes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值