目录
1. 安装环境
本地环境: Ubuntu20.04 没有cuda
1.1 安装OpenMVS
安装指南(官网):https://github.com/cdcseacave/openMVS#build
安装eigen3.4
git clone https://gitlab.com/libeigen/eigen.git --branch 3.4
cd eigen
mkdir build
cd build
cmake .. #make #eigen只有头文件,不用编译
sudo make install #安装(即复制)到/usr/include/eigen3目录下
安装vcg:
git clone -b devel https://github.com/cnr-isti-vclab/vcglib.git #vcg只有头文件,不用编译
# 但要修改一处代码: HETYPE ht=*this; ==》 MTTYPE ht=*this;
遇到一处编译错误,更改代码即可:HETYPE ht=*this; ==》 MTTYPE ht=*this;
安装glfw3 (可选)
sudo apt‐get install freeglut3‐dev libglew‐dev libglfw3‐dev
下载、编译openMVS
git clone https://github.com/cdcseacave/openMVS
mkdir openMVS_build
cd openMVS_build
#Cmake 配置下
cmake . ../openMVS -DCMAKE_BUILD_TYPE=Release -DVCG_ROOT=../vcglib/
#make编译下:
make -j4
1.2 安装OpenMVG
安装指南(官网): https://github.com/openMVG/openMVG/blob/develop/BUILD.md#linux
#下载依赖项
$ sudo apt-get install libpng-dev libjpeg-dev libtiff-dev libxxf86vm1 libxxf86vm-dev libxi-dev libxrandr-dev
#If you want see the view graph svg logs, install Graphviz.
$ sudo apt-get install graphviz
#Checkout OpenMVG.
$ git clone --recursive https://github.com/openMVG/openMVG.git
$ mkdir openMVG_Build && cd openMVG_Build
#Configure and build
$ cmake -DCMAKE_BUILD_TYPE=RELEASE ../openMVG/src/
$ cmake --build . --target install
-
遇到问题1:cannot import name 'soft_unicode' from 'markupsafe'
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/anaconda3/lib/python3.9/site-packages/markupsafe/__init__.py)
解决方法: python -m pip install markupsafe==2.0.1 # https://blog.csdn.net/weixin_45438997/article/details/124261720
-
遇到问题2:libQt5Core.so undefined reference to `std::__exception_ptr::exception_ptr::_M_release()@CXXABI_1.3.13
原因及解决方法:libstdc++.so.6.0.28 的 strings 中 没有CXXABI_1.3.13
复制一个libstdc++.so.6.0.29 到对应的目录即可, (该方法可能会导致系统不稳定无法正常启动)
参考: https://blog.csdn.net/weixin_39643007/article/details/120533472
其他解决方法: TODO
OpenMVG安装目录:
/usr/local/include/openMVG/...
/usr/local/include/openMVG_dependencies/nonFree/sift/. ...
/usr/local/lib/libopenMVG_features.a ...
/usr/local/lib/openMVG/webgl ...
/usr/local/bin/openMVG_main_SfM ...
2. 测试
2.1 下载数据
数据地址:https://github.com/openMVG/ImageDataset_SceauxCastle
下载的文本包含 images文件夹 和 Readme.txt文件
2.2 进行三维重建
整体流程梳理如下:
2.2.1 OpenMVG提取稀疏点云
cd path-to/ImageDataset_SceauxCastle-master
mkdir output/matches -p #递归建立文件夹
#生成 sfm_data.json 文件列表文件
openMVG_main_SfMInit_ImageListing -i ./images -o output/matches -f 3399
# “-f 3399” : 第一个命令-f 后面跟的是拍摄照片时的焦距与照片长边像素个数的乘积
# 这里 2832 * 1.2 =3398.4 ≈ 3399
#计算图像特征点和描述子 生成这样100_7100.desc 100_7100.feat 的文件
openMVG_main_ComputeFeatures -i output/matches/sfm_data.json -o output/matches/
#计算匹配关系
openMVG_main_ComputeMatches -i output/matches/sfm_data.json -o output/matches/matches.txt
#生成稀疏点云
openMVG_main_SfM -i output/matches/sfm_data.json -o output/matches/ --match_file output/matches/matches.txt
#提取矫正后的图像(可选)
openMVG_main_ExportUndistortedImages -i output/matches/sfm_data.json -o output/matches/image
#转换成mvs的格式,同时在当前目录下生成undistorted_images文件夹并存储了矫正后的图像
openMVG_main_openMVG2openMVS -i output/matches/sfm_data.bin -o output/scene.mvs
重建的稀疏点云结果:
![]() | ![]() |
2.2.2 OpenMVS稠密化点云/网格化/纹理贴图
######使用OpenMVS (mkdir openMVS_build 然后编译) ########
# 1 切换到OpenMVS目录
cd path-to/openMVS_build/bin
# 2 将 undistorted_images 复制到 openMVS_build 目录下
cp path-to/ImageDataset_SceauxCastle-master/undistorted_images ../ -r
# 3 稠密化稀疏点云scene.mvs,生成scene_dense.mvs
./DensifyPointCloud path-to/ImageDataset_SceauxCastle-master/output/scene.mvs
# 4 使用稠密点云scene_dense.mvs,网格重建,生成scene_dense_mesh.mvs
./ReconstructMesh path-to/ImageDataset_SceauxCastle-master/output/scene_dense.mvs
# 5 网格优化,生成scene_dense_mesh_refine.mvs
./RefineMesh path-to/ImageDataset_SceauxCastle-master/output/scene_dense_mesh.mvs
# 6 纹理贴图
./TextureMesh path-to/ImageDataset_SceauxCastle-master/output/scene_dense_mesh_refine.mvs
# 7 显示结果
./Viewer path-to-/ImageDataset_SceauxCastle-master/output/scene_dense_mesh_refine_texture.mvs
三维重建效果:
3. 运行遇到问题记录
问题1:DepthMap.cpp:730 ASSERT(ISEQUAL(norm(normalMap0(nx)), 1.f))
执行: ./DensifyPointCloud path-to/ImageDataset_SceauxCastle-master/output/scene.mvs 报错: DensifyPointCloud: /home/path-to/openMVS/libs/MVS/DepthMap.cpp:730: void MVS::DepthEstimator::ProcessPixel(SEACAVE::IDX): Assertion `ISEQUAL(norm(normalMap0(nx)), 1.f)' failed. 已放弃 (核心已转储)
解决方法: 注销掉,重新编译openMVS
// ASSERT(ISEQUAL(norm(normalMap0(nx)), 1.f)); //JOHN_delete