3D reconstruction_Using OpenMVG/OpenMVS to reconstruct the scene_Environment configuration/testing

Table of Contents

1. Installation environment

1.1 Install OpenMVS

1.2 Install OpenMVG

2. Test

2.1 Download data

2.2 Perform three-dimensional reconstruction

2.2.1 OpenMVG extracts sparse point clouds

2.2.2 OpenMVS dense point cloud/grid/texture mapping

3. Records of problems encountered during operation

4. Reference


1. Installation environment

Local environment: Ubuntu20.04 without cuda

1.1 Install OpenMVS

Installation guide (official website): https://github.com/cdcseacave/openMVS#build

Install eigen3.4

git clone https://gitlab.com/libeigen/eigen.git --branch 3.4
cd eigen
mkdir build
cd build
cmake .. #make #eigen only has header files, no compilation required
sudo make install #Install (i.e. copy) to the /usr/include/eigen3 directory

Install vcg:

git clone -b devel https://github.com/cnr-isti-vclab/vcglib.git #vcg only has header files, no compilation required

# But you need to modify one code: HETYPE ht=*this; ==》 MTTYPE ht=*this;

If you encounter a compilation error, just change the code: HETYPE ht=*this; ==》 MTTYPE ht=*this;

Install glfw3 (optional)

sudo apt‐get install freeglut3‐dev libglew‐dev libglfw3‐dev

Download and compile openMVS

git clone https://github.com/cdcseacave/openMVS
mkdir openMVS_build
cd openMVS_build
#Cmake configuration
cmake . ../openMVS -DCMAKE_BUILD_TYPE=Release -DVCG_ROOT=../vcglib/
#make compile:
make -j4

1.2 Install OpenMVG

Installation guide (official website): https://github.com/openMVG/openMVG/blob/develop/BUILD.md#linux

#Download dependencies
$ sudo apt-get install libpng-dev libjpeg-dev libtiff-dev libxxf86vm1 libxxf86vm-dev libxi-dev libxrandr-dev
#If you want to 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 & amp; & amp; cd openMVG_Build

#Configure and build
$ cmake -DCMAKE_BUILD_TYPE=RELEASE ../openMVG/src/
$ cmake --build . --target install
  • Encountered problem 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)

    • Solution: python -m pip install markupsafe==2.0.1 # https://blog.csdn.net/weixin_45438997/article/details/124261720

  • Encountered problem 2: libQt5Core.so undefined reference to `std::__exception_ptr::exception_ptr::_M_release()@CXXABI_1.3.13

  • Cause and solution: There is no CXXABI_1.3.13 in the strings of libstdc + + .so.6.0.28

  • Copy a libstdc + + .so.6.0.29 to the corresponding directory (this method may cause the system to be unstable and unable to start normally)

  • Reference: https://blog.csdn.net/weixin_39643007/article/details/120533472

Other solutions: TODO

OpenMVG installation directory:

/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. Test

2.1 Download data

Data address: https://github.com/openMVG/ImageDataset_SceauxCastle

The downloaded text contains the images folder and the Readme.txt file

2.2 Perform three-dimensional reconstruction

The overall process is summarized as follows:

2.2.1 OpenMVG extracts sparse point cloud

cd path-to/ImageDataset_SceauxCastle-master
mkdir output/matches -p #Create folders recursively

#Generate sfm_data.json file list file
openMVG_main_SfMInit_ImageListing -i ./images -o output/matches -f 3399
# “-f 3399”: The first command -f is followed by the product of the focal length when taking the photo and the number of pixels on the long side of the photo
# Here 2832 * 1.2 =3398.4 ≈ 3399

#Calculate image feature points and descriptors to generate files like 100_7100.desc 100_7100.feat
openMVG_main_ComputeFeatures -i output/matches/sfm_data.json -o output/matches/
#Calculate matching relationship
openMVG_main_ComputeMatches -i output/matches/sfm_data.json -o output/matches/matches.txt

#Generate sparse point cloud
openMVG_main_SfM -i output/matches/sfm_data.json -o output/matches/ --match_file output/matches/matches.txt

#Extract the corrected image (optional)
openMVG_main_ExportUndistortedImages -i output/matches/sfm_data.json -o output/matches/image

#Convert to mvs format, and generate the undistorted_images folder in the current directory and store the corrected images
openMVG_main_openMVG2openMVS -i output/matches/sfm_data.bin -o output/scene.mvs
 

Reconstructed sparse point cloud results:

2.2.2 OpenMVS densified point cloud/grid/texture map

######Use OpenMVS (mkdir openMVS_build then compile) ########
# 1 Switch to the OpenMVS directory
cd path-to/openMVS_build/bin
# 2 Copy undistorted_images to the openMVS_build directory
cp path-to/ImageDataset_SceauxCastle-master/undistorted_images ../ -r
# 3 Densify the sparse point cloud scene.mvs and generate scene_dense.mvs
./DensifyPointCloud path-to/ImageDataset_SceauxCastle-master/output/scene.mvs
# 4 Use dense point cloud scene_dense.mvs, mesh reconstruction, generate scene_dense_mesh.mvs
./ReconstructMesh path-to/ImageDataset_SceauxCastle-master/output/scene_dense.mvs
# 5 Mesh optimization, generate scene_dense_mesh_refine.mvs
./RefineMesh path-to/ImageDataset_SceauxCastle-master/output/scene_dense_mesh.mvs
#6 Texture Map
./TextureMesh path-to/ImageDataset_SceauxCastle-master/output/scene_dense_mesh_refine.mvs
# 7 show results
./Viewer path-to-/ImageDataset_SceauxCastle-master/output/scene_dense_mesh_refine_texture.mvs

3D reconstruction effect:

3. Record of problems encountered during operation

Question 1: DepthMap.cpp:730 ASSERT(ISEQUAL(norm(normalMap0(nx)), 1.f))

Execution: ./DensifyPointCloud path-to/ImageDataset_SceauxCastle-master/output/scene.mvs Error: DensifyPointCloud: /home/path-to/openMVS/libs/ MVS/DepthMap.cpp:730: void MVS::DepthEstimator::ProcessPixel(SEACAVE::IDX): Assertion `ISEQUAL(norm(normalMap0(nx)), 1.f)' failed. Abandoned (core dumped )

Solution: Log out and recompile openMVS

// ASSERT(ISEQUAL(norm(normalMap0(nx)), 1.f)); //JOHN_delete

4. Reference

  • UBUNTU16.04 + OPENMVG + OPENMVS (3): Realize three-dimensional reconstruction of your own data

  • Install and use OpenMVG and OpenMVS in Ubuntu (nanny-level tutorial)_Wahaha347’s Blog-CSDN Blog

  • Visual 3D reconstruction using OpenMVG + PMVS_wx5d23599e462fa’s technical blog_51CTO blog

  • Ubuntu Learning Tip 4: Qt multi-version replacement and updating to higher versions of qt_How to update qt version code-CSDN Blog

  • https://github.com/openMVG/openMVG/issues/1973

  • Installing meshlab on ubuntu is very simple_R-G-B’s blog-CSDN blog