一、安装
1.安装Linux LTS(如已有Ubutnu环境,跳过该步骤)
Linux安装教程,注意该方法只适应于18.04 开启xrdp服务: sudo service xrdp restart
2.配置镜像站(如已配置过镜像源,跳过该步骤)
2.1 修改镜像源文件
详情可参考此处链接的(二.更换源),此处不做详细说明,仅列出相关指令
查看Ubuntu版本号
lsb_release -a
备份源文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
打开源文件
sudo vim /etc/apt/sources.list
进入编辑后,按下“i”键开始编辑
使用“#”注释掉源文件中的所有行
将2.2任意源复制到文档的最后末尾处
按“ESC”退出编辑模式,输入 “:wq” 保存并退出文本
输入以下指令更新源
sudo apt update
sudo apt upgrade -y
2.2 镜像源
更多版本清华镜像,点击这里
2.2.1 Ubuntu 18.04-清华镜像源
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
2.2.2 Ubuntu 20.04-阿里镜像源
#ubuntu 20.04 LTS的阿里源镜像
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
2.2.3 Ubuntu 20.04-清华镜像源
ubuntu 20.04 LTS的清华源镜像
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
3.安装OpenMVS,OpenMVG
3.1 OpenMVG安装
OpenMVG官网安装指南 需要环境:
CMake 可通过指令安装: sudo apt install cmake
Git 系统常自带
C/C++ compiler (GCC, Visual Studio or Clang) 系统常自带GCC
- Visual Studio >= 2015 (recommended)
- GCC >= 4.8.1
(sudo update-alternatives --config gcc 可切换gcc版本)
- Clang >= 3.3
非必要
QT version >= v5.4
部分安装需要权限,输入:sudo -s 可在当前路径获取权限
由于QT编译原因,导致的报错,可以通过关闭DOpenMVG_BUILD_GUI_SOFTWARES方式通过编译 cmake -DCMAKE_BUILD_TYPE=RELEASE -DOpenMVG_BUILD_GUI_SOFTWARES=OFF …/openMVG/src/
3.2OpenMVS安装
- 需要注意的是,该软件仅支持Eigen 3.2,因此如果之前有安装过其他版本,需要重新安装
(可选)由于工作需要此处修改了部分源码,代码文件的替换步骤在以下步骤处,在查看教程时,可根据需要进行修改。
……………
……………
……………
#OpenMVS
git clone https://github.com/cdcseacave/openMVS.git openMVS
**************************************************************
**本项目替换了 /home/lgn/openMVS/libs/MVS/SceneDensify.cpp 文件**
**************************************************************
mkdir openMVS_build && cd openMVS_build
cmake . ../openMVS -DCMAKE_BUILD_TYPE=Release -DVCG_ROOT="$main_path/vcglib"
#If you want to use OpenMVS as shared library, add to the CMake command:
-DBUILD_SHARED_LIBS=ON
#Install OpenMVS library (optional):
make -j2 && sudo make install
二、运行
1. OPenMVG
[可选]此处为官方提供的测试指令,可能会出现报错,可跳过该步骤
cd openMVG_Build/software/SfM/
python SfM_SequentialPipeline.py /home/lgnzgxl/Test/Image/ /home/lgnzgxl/Test/Result/
python SfM_GlobalPipeline.py /home/lgnzgxl/Test/Image/ /home/lgnzgxl/Test/Result/
正式使用
- 实验的数据图片放在以下路径下: /home/lgnzgxl/Test/Image/
- 计算结果存储在目录下:/home/lgnzgxl/Test/Result2/
- focal参数相机焦距,在不知道得情况下,可通过Max(width,height)*1.2 得到一个初始值, 如图片:宽度4000,高度3200,则取值4000 * 1.2=4800
dataset=/home/lgnzgxl/Test/Image
dataset_out=/home/lgnzgxl/Test/Result2
focal=4800
openMVG_main_SfMInit_ImageListing -i $dataset -f $focal -o $dataset_out
openMVG_main_ComputeFeatures -i $dataset_out/sfm_data.json -o $dataset_out
openMVG_main_ComputeMatches -i $dataset_out/sfm_data.json -o $dataset_out
openMVG_main_IncrementalSfM -i $dataset_out/sfm_data.json -m $dataset_out -o $dataset_out/reconstruction
openMVG_main_ComputeSfM_DataColor -i $dataset_out/reconstruction/sfm_data.bin -o $dataset_out/colored.ply
openMVG_main_openMVG2MVSTEXTURING -i $dataset_out/reconstruction/sfm_data.bin -o $dataset_out/camera
openMVG_main_openMVG2openMVS -i $dataset_out/reconstruction/sfm_data.bin -o $dataset_out/scene.mvs -d $dataset_out/scene_undistorted_images
[可选]此命令产生的 robust.bin 似乎可以直接用sfm_data.bin取代
openMVG_main_ComputeStructureFromKnownPoses -i $dataset_out/reconstruction/sfm_data.bin -m $dataset_out -o $dataset_out/reconstruction/robust.bin -f $dataset_out/matches.f.bin
openMVG_main_openMVG2openMVS -i $dataset_out/reconstruction/robust.bin -o $dataset_out/reconstruction/scene.mvs
[可选]全景影像的应用
dataset=/home/lgnzgxl/Test/PanoFlat/OpenMVG/Image/
dataset_out=/home/lgnzgxl/Test/PanoFlat/OpenMVG/
openMVG_main_SfMInit_ImageListing -i $dataset -o $dataset_out/matches -f 1 -c 7
openMVG_main_ComputeFeatures -i $dataset_out/matches/sfm_data.json -o $dataset_out/matches
openMVG_main_ComputeMatches -i $dataset_out/matches/sfm_data.json -o $dataset_out/matches -g a
openMVG_main_IncrementalSfM -i $dataset_out/matches/sfm_data.json -m $dataset_out/matches -o $dataset_out/reconstruction
openMVG_main_openMVGSpherical2Cubic -i $dataset_out/reconstruction/sfm_data.bin -o $dataset_out/reconstruction/cubic
openMVG_main_openMVG2openMVS -i $dataset_out/reconstruction/cubic/sfm_data_perspective.bin -o $dataset_out/reconstruction/cubic/scene.mvs -d $dataset_out/reconstruction/cubic/openmvs_images
DensifyPointCloud $dataset_out/reconstruction/cubic/scene.mvs
2.OpenMVS
- 安装OpenMVS后,可能会出现相关指令无法找到的情况,此时需要把编译后的~/openMVS_build/bin下若干文件,拷贝到根目录/user/bin文件夹下
- 执行前,需要调整当前的工作路径(使用cd 命令调整),并保证当前路径下包含undistorted_images目录,内部包含纠正后的图片 即工作目录下包含 scene.mvs
文件 和 undistorted_images 图像 - 若不指定 -o 参数(输出位置),默认输出结果与输入路径一致
生成稠密点云
DensifyPointCloud scene.mvs
生成Mesh
ReconstructMesh -d 4 scene_dense.mvs
构建精细化Mesh
RefineMesh --resolution-level=4 scene_dense_mesh.mvs
贴图纹理
TextureMesh scene_dense_mesh_refine.mvs
3.OpenMVG与OpenMVS(可选)
当各个模块都没有问题后,可直接修改三个参数后
- dataset
- dataset_out
- focal
直接复制全部指令进行执行所有OpoenMVS与OpenMVG的操作。
dataset=/home/lgnzgxl/Test/Image
dataset_out=/home/lgnzgxl/Test/Result2
focal=4800
openMVG_main_SfMInit_ImageListing -i $dataset -f $focal -o $dataset_out
openMVG_main_ComputeFeatures -i $dataset_out/sfm_data.json -o $dataset_out
openMVG_main_ComputeMatches -i $dataset_out/sfm_data.json -o $dataset_out
openMVG_main_IncrementalSfM -i $dataset_out/sfm_data.json -m $dataset_out -o $dataset_out/reconstruction
openMVG_main_ComputeSfM_DataColor -i $dataset_out/reconstruction/sfm_data.bin -o $dataset_out/colored.ply
openMVG_main_openMVG2MVSTEXTURING -i $dataset_out/reconstruction/sfm_data.bin -o $dataset_out/camera
openMVG_main_openMVG2openMVS -i $dataset_out/reconstruction/sfm_data.bin -o $dataset_out/scene.mvs -d $dataset_out/scene_undistorted_images
mkdir $dataset_out/OpenMVS
cp -r $dataset_out/scene.mvs $dataset_out/OpenMVS
cp -r $dataset_out/scene_undistorted_images $dataset_out/OpenMVS
mv $dataset_out/OpenMVS/scene_undistorted_images $dataset_out/OpenMVS/undistorted_images
cd $dataset_out/OpenMVS
DensifyPointCloud scene.mvs
ReconstructMesh -d 4 scene_dense.mvs
RefineMesh --resolution-level=4 scene_dense_mesh.mvs
TextureMesh scene_dense_mesh_refine.mvs
针对全景直接复制全部指令进行执行所有OpoenMVS与OpenMVG的操作。
dataset=/home/lgnzgxl/Test/PanoFlat/OpenMVG/Image/
dataset_out=/home/lgnzgxl/Test/PanoFlat/OpenMVG/
openMVG_main_SfMInit_ImageListing -i $dataset -o $dataset_out/matches -f 1 -c 7
openMVG_main_ComputeFeatures -i $dataset_out/matches/sfm_data.json -o $dataset_out/matches
openMVG_main_ComputeMatches -i $dataset_out/matches/sfm_data.json -o $dataset_out/matches -g a
openMVG_main_IncrementalSfM -i $dataset_out/matches/sfm_data.json -m $dataset_out/matches -o $dataset_out/reconstruction
openMVG_main_openMVGSpherical2Cubic -i $dataset_out/reconstruction/sfm_data.bin -o $dataset_out/reconstruction/cubic
openMVG_main_openMVG2openMVS -i $dataset_out/reconstruction/cubic/sfm_data_perspective.bin -o $dataset_out/reconstruction/cubic/scene.mvs -d $dataset_out/reconstruction/cubic/openmvs_images
mkdir $dataset_out/OpenMVS
cp -r $dataset_out/reconstruction/cubic/scene.mvs $dataset_out/OpenMVS
cp -r $dataset_out/reconstruction/cubic/openmvs_images $dataset_out/OpenMVS
mv $dataset_out/OpenMVS/openmvs_images $dataset_out/OpenMVS/undistorted_images
cd $dataset_out/OpenMVS
DensifyPointCloud scene.mvs
ReconstructMesh -d 4 scene_dense.mvs
RefineMesh --resolution-level=4 scene_dense_mesh.mvs
TextureMesh scene_dense_mesh_refine.mvs
三 其他参考(随笔记录)
1. OpenMVS与OpenMVG的其他参考
2.文件授权
授予文件权限
sudo chmod -R 777 某一目录
文件的拷贝mt的文件路径 将数据拷贝到windows
cp -r /home/lgnzgxl/Test/MyTest/scene_dense.ply /mnt/e