puzzlepaint / surfelmeshing

Real-time surfel-based mesh reconstruction from RGB-D video.
BSD 3-Clause "New" or "Revised" License
420 stars 83 forks source link
3d-reconstruction

SurfelMeshing

Screenshot

Overview

SurfelMeshing is an approach for real-time surfel-based mesh reconstruction from RGB-D video, described in the following article:

T. Schöps, T. Sattler, M. Pollefeys, "SurfelMeshing: Online Surfel-Based Mesh Reconstruction", PAMI 2019. [pdf][video]

If you use the SurfelMeshing code for research, please cite this paper.

Compared to the version of the code used to run the experiments for the paper, we removed the loop closure handling component for the open source version in this repository. This is because this component was written with the help of proprietary-licensed code, which we wanted to avoid. If you would like to add your own loop closure handling, see the corresponding section below.

The repository contains the SurfelMeshing application and the library it is based on, libvis. The library is work-in-progress and it is not recommended to use it for other projects at this point.

The application and library code is licensed under the BSD license, but please also notice the licenses of the included or externally used third-party components.

Building

Building has been tested on Ubuntu 14.04 only. It is expected that later versions of Ubuntu also work with little effort.

The following external dependencies are required (the versions in brackets are known to work):

After obtaining all dependencies, the application can be built with CMake, for example as follows:

mkdir build_RelWithDebInfo
cd build_RelWithDebInfo
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CUDA_FLAGS="-arch=sm_61" ..
make -j SurfelMeshing

Make sure to specify suitable CUDA architecture(s) in CMAKE_CUDA_FLAGS. Common settings would either be the CUDA architecture of your graphics card only (in case you only intend to run the compiled application on the system it was compiled on), or a range of virtual architectures (in case the compiled application is intended for distribution). See the corresponding CUDA documentation.

Running

The program supports datasets in the format of the TUM RGB-D benchmark with two small additions:

Without specifying any optional parameters, SurfelMeshing can be run as follows:

./build_RelWithDebInfo/applications/surfel_meshing/SurfelMeshing <dataset> <trajectory>

Here, <dataset> is the path to the dataset folder, and <trajectory> is the filename of the trajectory file within this folder (excluding the rest of the file's path). The groundtruth.txt files provided with the TUM RGB-D benchmark can be used for testing (but keep in mind that for some datasets, parts of the ground truth trajectory are missing, which might lead to issues).

For example, to run the reconstruction with the ground truth trajectory (and use a freely movable camera):

./build_RelWithDebInfo/applications/surfel_meshing/SurfelMeshing /path/to/some_tum_rgbd_dataset groundtruth.txt --follow_input_camera false

Notice that the first time the program runs on a dataset, the performance is usually limited by the time it takes to read the image files from the hard disk (unless the dataset is on an SSD, or is already cached because the files were written recently). Subsequent runs should be faster as long as the files remain cached.

In case you encounter issues with insufficient GPU memory, try decreasing the maximum surfel count with the --max_surfel_count option (default: 20000000). However, the program will abort once this surfel count is exceeded.

In case you encounter the issue "Cuda Error: too many resources requested for launch", you likely need to reduce the CUDA kernel block sizes in applications/surfel_meshing/src/surfel_meshing/cuda_surfel_reconstruction.cu. See this GitHub issue.

3D window controls

By default, the 3D window view is fixed to the input camera's trajectory. Use --follow_input_camera false to get a freely movable camera, which can be controlled as follows:

Furthermore, the following keys can be used to alter the 3D display:

Terminal controls

These controls can be used in the terminal after the dataset processing finished or if the --step_by_step_playback option is used (i.e., when the reconstruction is not running).

Adding loop closure handling

As mentioned above, the loop closure component was removed from this version of the code to avoid license issues. If you would like to add your own loop closure handling, you could start by adding the call to it at main.cc:1162 (line "// ### Loop closures ###"). You would need to write a CUDA kernel analogously to the existing ones in cuda_surfel_reconstruction.cu and modify the following surfel attributes:

surfels(kSurfelX, surfel_index) += position_offset.x;
surfels(kSurfelY, surfel_index) += position_offset.y;
surfels(kSurfelZ, surfel_index) += position_offset.z;
surfels(kSurfelSmoothX, surfel_index) += position_offset.x;
surfels(kSurfelSmoothY, surfel_index) += position_offset.y;
surfels(kSurfelSmoothZ, surfel_index) += position_offset.z;
surfels(kSurfelNormalX, surfel_index) = new_normal.x;
surfels(kSurfelNormalY, surfel_index) = new_normal.y;
surfels(kSurfelNormalZ, surfel_index) = new_normal.z;

The timestamp for old surfels which shall be activated for measurement integration again can be updated as follows:

*reinterpret_cast<u32*>(&surfels(kSurfelLastUpdateStamp, surfel_index)) = frame_index;

Program arguments

A list of optional program arguments follows, grouped by category:

Dataset playback

Surfel reconstruction

Meshing

Depth preprocessing

Octree

File export

Visualization

Debug and evaluation