【colmap】基于colmap的多视图三维重建

《基于多视角图像的三维重建》👉https://github.com/XYZ-qiyh/multi-view-3d-reconstruction

本文将介绍COLMAP的安装与使用,重点介绍3D重建过程中每个步骤的输入输出。

一、安装

本文使用colmap-3.6版本,但同样适合新版本,下载完毕后进入colmap目录进行源码编译

cd ./colmap-3.6              # 进入colmap目录
mkdir build && cd ./build    # 创建build文件夹,并进入
cmake ..                     # cmake
make -j8                     # make多线程编译

二、基于colmap的三维重建

2.1 数据准备

基于colmap开源框架进行多视图三维重建,使用Sceaux Castle数据集提供的图片👇

图1. Sceaux Castle数据集

我们将图片组织为colmap的工程格式:

/path/to/project/...
+── images
│   +── image1.jpg
│   +── image2.jpg
│   +── ...
│   +── imageN.jpg
图2. colmap工程组织格式

工作目录中包含一个images文件夹,images中即为待重建的图片。

2.2 开始重建

以下所有命令均可在COLMAP官方说明文档中查阅。
colmap提供了自动重建的命令,我们这里还是逐步进行重建,以观察每一步的输入输出结果。

2.2.1 特征提取(feature_extractor)
./colmap feature_extractor \
   --database_path $DATASET_PATH/database.db \  # 输出:特征点保存至数据库database.db
   --image_path $DATASET_PATH/images            # 输入:多视图图像
2.2.2 特征点匹配(exhaustive_matcher)
./colmap exhaustive_matcher \
   --database_path $DATASET_PATH/database.db    # 输入输出:数据库文件database.db
2.2.3 稀疏重建(SfM, Structure-from-Motion)(mapper)
mkdir $DATASET_PATH/sparse    # 新建sparse文件夹
./colmap mapper \
    --database_path $DATASET_PATH/database.db \    # 输入:数据库文件database.db
    --image_path $DATASET_PATH/images \            # 输入:多视图图像
    --output_path $DATASET_PATH/sparse             # 输出:`sparse`文件夹

输出结果sparse文件夹如下所示👇

└── sparse        # 稀疏重建结果
    └── 0
        ├── cameras.bin        # 相机内参
        ├── images.bin         # 相机位姿
        ├── points3D.bin       # 稀疏3D点
        └── project.ini
2.2.4 图像去畸变(image_undistorter)
mkdir $DATASET_PATH/dense    # 新建dense文件夹
./colmap image_undistorter \
    --image_path $DATASET_PATH/images \          # 输入:多视图图像
    --input_path $DATASET_PATH/sparse/0 \        # 输入:sparse文件夹
    --output_path $DATASET_PATH/dense \          # 输出:dense文件夹
    --output_type COLMAP \                       # 参数:输出格式
    --max_image_size 2000                        # 参数:最大图像尺寸

输出结果dense文件夹如下所示👇

└── dense
    ├── images
    │   ├── 100_7100.JPG
    │   ├── 100_7101.JPG
    │   ├── ...
    │   └── 100_7110.JPG
    ├── run-colmap-geometric.sh
    ├── run-colmap-photometric.sh
    ├── sparse
    │   ├── cameras.bin
    │   ├── images.bin
    │   └── points3D.bin
    └── stereo
        ├── consistency_graphs
        ├── depth_maps
        ├── fusion.cfg
        ├── normal_maps
        └── patch-match.cfg
2.2.5 稠密重建
./colmap patch_match_stereo \
    --workspace_path $DATASET_PATH/dense \        # 输入输出:dense文件夹
    --workspace_format COLMAP \                   # 参数:工作区格式
    --PatchMatchStereo.geom_consistency true      

稠密重建的结果:为每张图像估计depth_mapnormal_map

└── dense
    ├── images                        # resize之后的图像
    │   ├── 100_7100.JPG
    │   ├── 100_7101.JPG
    │   ├── ...
    │   └── 100_7110.JPG
    ├── run-colmap-geometric.sh
    ├── run-colmap-photometric.sh
    ├── sparse
    │   ├── cameras.bin
    │   ├── images.bin
    │   └── points3D.bin
    └── stereo
        ├── consistency_graphs
        ├── depth_maps
        │   ├── 100_7100.JPG.geometric.bin
        │   ├── 100_7100.JPG.photometric.bin
        │   ├── ...
        │   ├── ...
        │   ├── 100_7110.JPG.geometric.bin
        │   └── 100_7110.JPG.photometric.bin
		├── fusion.cfg
        ├── normal_maps
        │   ├── 100_7100.JPG.geometric.bin
        │   ├── 100_7100.JPG.photometric.bin
        │   ├── ...
        │   ├── ...
        │   ├── 100_7110.JPG.geometric.bin
        │   └── 100_7110.JPG.photometric.bin
        └── patch-match.cfg
2.2.6 融合
./colmap stereo_fusion \
    --workspace_path $DATASET_PATH/dense \             # 输入:dense文件夹
    --workspace_format COLMAP \                        # 参数:工作区格式
    --input_type geometric \                           # 参数:输入类型
    --output_path $DATASET_PATH/dense/fused.ply        # 输出:fused.ply文件

3.3 重建结果可视化

3.3.1 稀疏重建结果可视化
./colmap model_converter \
    --input_path $DATASET_PATH/dense/sparse \
    --output_path $DATASET_PATH/dense/sparse \
    --output_type TXT
图3. 稀疏重建结果 && 相机位姿可视化
3.3.2 深度图、法向图可视化

图4. 从左到右:100_7104原图,重建深度图,重建法向图
3.3.3 稠密重建结果可视化

图5. 稠密重建结果

4 备注

4.1 Castle场景的重建结果见百度网盘
链接:https://pan.baidu.com/s/1l0JP2f5RqTzZiMaqhC-qGw 提取码:jgou

4.2 colmap三维重建的Shell脚本colmap_3d_recon.sh,修改其中的可执行文件路径EXE_PATH和数据路径DATASET_PATH即可对自己的数据进行三维重建。

4.3 相机位姿可视化:https://github.com/demul/extrinsic2pyramid

4.4 SceauxCastle:https://en.wikipedia.org/wiki/Château_de_Sceaux

4.5 fused.ply.vis: https://github.com/colmap/colmap/issues/857

posted @ 2020-02-24 15:31  达可奈特  阅读(24034)  评论(0编辑  收藏  举报