OpenMVS(Multi-View Stereo reconstruction library)是一个比较经典的MVS开源库,集成了三维重建的完整技术方案,含:相机模型、多视立体几何、稠密重建、曲面重建、点云融合、纹理贴图等,主要用于从多个图像中创建高质量的三维模型,还可以从图像集合中恢复三维集合和纹理信息以创建更真实的场景重建。其基本算法流程如下:
%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BentryX%3D0%3BentryY%3D0.5%3BentryDx%3D0%3BentryDy%3D0%3B%22%20edge%3D%221%22%20source%3D%223%22%20target%3D%227%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22%E5%9B%BE%E5%83%8F%E6%95%B0%E6%8D%AE%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%2280%22%20y%3D%22160%22%20width%3D%2290%22%20height%3D%2240%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%224%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BentryX%3D0%3BentryY%3D0.5%3BentryDx%3D0%3BentryDy%3D0%3B%22%20edge%3D%221%22%20source%3D%225%22%20target%3D%227%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%225%22%20value%3D%22%E5%9B%BE%E5%83%8F%E4%BD%8D%E5%A7%BF%E6%95%B0%E6%8D%AE%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%2280%22%20y%3D%22240%22%20width%3D%2290%22%20height%3D%2240%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%226%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BentryX%3D0%3BentryY%3D0.5%3BentryDx%3D0%3BentryDy%3D0%3B%22%20edge%3D%221%22%20source%3D%227%22%20target%3D%229%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%227%22%20value%3D%22%E7%A8%A0%E5%AF%86%E9%87%8D%E5%BB%BA%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22250%22%20y%3D%22200%22%20width%3D%2290%22%20height%3D%2240%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%228%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BentryX%3D0%3BentryY%3D0.5%3BentryDx%3D0%3BentryDy%3D0%3B%22%20edge%3D%221%22%20source%3D%229%22%20target%3D%2213%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%229%22%20value%3D%22%E7%82%B9%E4%BA%91%E8%9E%8D%E5%90%88%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22390%22%20y%3D%22200%22%20width%3D%2290%22%20height%3D%2240%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2210%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BentryX%3D0%3BentryY%3D0.5%3BentryDx%3D0%3BentryDy%3D0%3B%22%20edge%3D%221%22%20source%3D%2211%22%20target%3D%2214%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2211%22%20value%3D%22%E7%BD%91%E6%A0%BC%E4%BC%98%E5%8C%96%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22680%22%20y%3D%22200%22%20width%3D%2290%22%20height%3D%2240%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2212%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BentryX%3D0%3BentryY%3D0.5%3BentryDx%3D0%3BentryDy%3D0%3B%22%20edge%3D%221%22%20source%3D%2213%22%20target%3D%2211%22%20parent%3D%221%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2213%22%20value%3D%22%E7%BD%91%E6%A0%BC%E9%87%8D%E5%BB%BA%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22540%22%20y%3D%22200%22%20width%3D%2290%22%20height%3D%2240%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2214%22%20value%3D%22%E7%BA%B9%E7%90%86%E8%B4%B4%E5%9B%BE%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22820%22%20y%3D%22200%22%20width%3D%2290%22%20height%3D%2240%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3
现在记录下安装使用过程,后面其他文章再补充更多相关知识了。
环境说明
- MacOS Sonoma14.5 - Intel芯片
- Docker Desktop For Mac 4.24.2
- 容器镜像:Ubuntu:16.04
安装步骤
容器创建
docker run -it --name openMVS -v /Users/linjk/Documents/docker/mvs:/data ubuntu:16.04
基础依赖包
执行如下命令:
- apt-get update
- apt-get install git libpng-dev libjpeg-dev libtiff-dev libglu1-mesa-dev
- apt-get install libboost-iostreams-dev libboost-program-options-dev libboost-system-dev libboost-serialization-dev libcgal-dev libcgal-qt5-dev
- apt-get install build-essential libgtk-3-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
CMake源码安装
构建OpenMVS需要版本3.5以上,这里官网下载3.30.0版本,直接解压后配置环境变量即可。
Eigen安装
git clone https://gitlab.com/libeigen/eigen.git--branch 3.2
mkdir eigen_build && cd eigen_build
cmake . ../eigen && make && make install
VCGLib依赖下载
git clone https://github.com/cdcseacave/VCG.git -b v1.0.1 vcglib101
OpenCV源码编译安装
官网下载4.1.1版本源码解压后【推荐使用4.1.1,其他版本编译MVS会出现错误或者成功但在稠密重建时实现段异常错误,估计和特定OpenCV版本函数有关】:
cd opencv4.1.1
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make && make install
OpenMVS源码编译安装
git clone https://github.com/cdcseacave/openMVS.git
mkdir openMVS_build && cd openMVS_build
cmake . ../openMVS -DCMAKE_BUILD_TYPE=Release -DVCG_ROOT="/data/code/vcglib101"
make && make install
安装好后,在openMVS_build的bin目录下是相关的可执行文件:
三维重建
案例数据下载
git clone https://github.com/cdcseacave/openMVS_sample.git,然后把images文件和位姿数据文件scene.mvs拷贝到容器与主机的映射文件夹中,如下所示:
images文件夹下是建筑物的10个不同视角的照片:
scene.mvs里面包含稀疏的点云,在稠密重建时会利用它提供的相机内外参以及稀疏点云进行图像矫正,这样后面就能利用平行的极线约束检测到更多特征得到密集视差图计算深度,实现密集点云重建。
MeshLab下载
重建过程的结果,可以通过 MeshLab来查看,它是一个开源、可移植和可扩展的三维几何处理系统,主要用于交互处理和非结构化编辑三维三角形网格。
步骤
密集点云重建
./DensifyPointCloud -w /data/samples -i /data/samples/scene.mvs -o /data/samples/test_dense.mvs
网格模型生成
./ReconstructMesh -w /data/samples -i /data/samples/test_dense.mvs -o /data/samples/test_mesh.mvs
网格模型优化
./RefineMesh -w /data/samples -i /data/samples/test_mesh.mvs -o /data/samples/test_refinemesh.mvs
纹理贴图
./TextureMesh -w /data/samples -i /data/samples/test_refinemesh.mvs -o /data/samples/test_texture.mvs
过程中的容器资源消耗如下:
还是挺耗CPU的,委屈这台i5的MBP了。流程实操成功,后面就是了解每一步的细节和原理了。