Skip to content

GSoC 2017: dynamicfusion #1349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ $ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -D BUILD_opencv_<r

- **dpm**: Deformable Part Model -- Felzenszwalb's Cascade with deformable parts object recognition code.

- **dynamicfusion** 3D reconstruction with dynamic scenes -- RGB-D SLAM system that can reconstruct 3D models of scenes with non-rigit deformations.

- **face**: Face Recognition -- Face recognition techniques: Eigen, Fisher and Local Binary Pattern Histograms LBPH methods.

- **fuzzy**: Fuzzy Logic in Vision -- Fuzzy logic image transform and inverse; Fuzzy image processing.
Expand Down
34 changes: 34 additions & 0 deletions modules/dynamicfusion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
set(the_description "Non-rigid 3D reconstruction")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DFORCE_INLINERS -D_MWAITXINTRIN_H_INCLUDED")

include(cmake/Utils.cmake)
include(cmake/Targets.cmake)

ocv_define_module(dynamicfusion opencv_core opencv_viz opencv_imgproc)

ocv_warnings_disable(CMAKE_CXX_FLAGS
-Wundef
-Wshadow
-Wsign-compare
-Wmissing-declarations
-Wunused-but-set-variable
-Wunused-parameter
-Wunused-function
)

find_package(Ceres QUIET)

if (NOT Ceres_FOUND)
message(STATUS "${the_module} has been disabled because Ceres library has not been found")
ocv_module_disable(${the_module})
else()
include_directories(${CERES_INCLUDE_DIRS})
ocv_target_link_libraries(${the_module} ${CERES_LIBRARIES})
endif()
if(NOT HAVE_CUDA)
message(STATUS "${the_module} currently requires CUDA to run")
ocv_module_disable(${the_module})
else()
include_directories(${CUDA_INCLUDE_DIRS})
ocv_target_link_libraries(${the_module} ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY})
endif()
27 changes: 27 additions & 0 deletions modules/dynamicfusion/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2012, Anatoly Baksheev
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
134 changes: 134 additions & 0 deletions modules/dynamicfusion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
DynamicFusion
============
Implementation of [Newcombe et al. 2015 DynamicFusion paper](http://grail.cs.washington.edu/projects/dynamicfusion/papers/DynamicFusion.pdf).

The code is based on this [KinectFusion implemenation](https://github.com/Nerei/kinfu_remake)

Dependencies:
* CUDA 5.0 or higher
* OpenCV 2.4.8 or higher (modules opencv_core, opencv_highgui, opencv_calib3d, opencv_imgproc, opencv_viz). Make sure that WITH_VTK flag is enabled in CMake during OpenCV configuration.
* Nanoflann (included in the repository)
* Boost (libraries system, filesystem and program options. Only used in the demo. Tested with [1.64.0](http://www.boost.org/users/history/version_1_64_0.html))
* Ceres solver (Tested with version [1.13.0](http://ceres-solver.org/ceres-solver-1.13.0.tar.gz))

Implicit dependency (needed by opencv_viz):
* VTK 5.8.0 or higher
* SuiteSparse, BLAS and LAPACK for ceres
Optional dependencies:
* GTest for testing
* Doxygen for documentation
* OpenNI v1.5.4 for getting input straight from a kinect device.

## Building instructions:

### Linux
Install NVIDIA drivers.A good tutorial with some common issues covered can be found [here](
https://askubuntu.com/a/61433/167689).

Download and install CUDA from the [NVIDIA website](https://developer.nvidia.com/cuda-downloads).

Install VTK, SuiteSparse, BLAS and LAPACK
```
sudo apt-get install libvtk5-dev libsuitesparse-dev liblapack-dev libblas-dev
```

Clone Ceres Solver `git clone https://ceres-solver.googlesource.com/ceres-solver`, then build and install using `cmake` and `make`.

Clone and install opencv. The project should work with any version above 2.4.8
```
git clone https://github.com/opencv/opencv
cd opencv
git checkout 3.2.0
mkdir build
cd build
cmake .. -DWITH_VTK=ON -DBUILD_opencv_calib3d=ON BUILD_opencv_imgproc=ON
make -j4
sudo make install
```
Get [Boost 1.64.0](http://www.boost.org/users/download/) or above. Don't install it through apt-get as it sometimes results in linking errors on Ubuntu 16.04.

Optionals:
Doxygen can be installed through apt-get: `sudo apt-get install doxygen`.
Clone and install [GTest](https://github.com/google/googletest)
Clone and install [OpenNI](https://github.com/OpenNI/OpenNI)

Now clone the repository and build:
```
git clone https://github.com/mihaibujanca/dynamicfusion
mkdir build
cd build
cmake ..
make -j4
```

If you want to build the tests as well, make sure you pass `-DBUILD_TESTS=ON` to the cmake command.

To build documentation, go to the project root directory and execute
```
doxygen -g
doxygen Doxyfile
```
### Windows
* [Install NVIDIA drivers](https://www.geforce.com/drivers) and [CUDA](https://developer.nvidia.com/cuda-downloads)
* [Install LAPACK](http://icl.cs.utk.edu/lapack-for-windows/lapack/).
* [Install VTK](http://www.vtk.org/download/) (download and build from source)
* [Install OpenCV](http://docs.opencv.org/3.2.0/d3/d52/tutorial_windows_install.html).
* [Install Boost](http://www.boost.org/users/download/)


Optionals:
* [Doxygen](http://www.stack.nl/~dimitri/doxygen/download.html)
* [GTest](https://github.com/google/googletest)
* [OpenNI]( http://pointclouds.org/downloads/windows.html)



## Run instructions
### Unix
Download an example dataset using `./download_data`.
To run the project, use `./build/bin/dynamicfusion <project_root>/data/umbrella`

### Windows
[Download the dataset](http://lgdv.cs.fau.de/uploads/publications/data/innmann2016deform/umbrella_data.zip).\
Create a `data` folder inside the project root directory. \
Unzip the archive into `data` and remove any files that are not .png. \
Inside `data`, create directories `color` and `depth`, and move color and depth frames to their corresponding folders.



To use with .oni captures or straight from a kinect device, use `./build/bin/dynamicfusion_kinect <path-to-oni>` or `./build/bin/dynamicfusion_kinect <device_id>`

---
Note: currently, the frame rate is too low (5-6fps) to be able to cope with live inputs, so it is advisable that you capture your input first.

## References
[DynamicFusion project page](http://grail.cs.washington.edu/projects/dynamicfusion/)

```
@InProceedings{Newcombe_2015_CVPR,
author = {Newcombe, Richard A. and Fox, Dieter and Seitz, Steven M.},
title = {DynamicFusion: Reconstruction and Tracking of Non-Rigid Scenes in Real-Time},
booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {June},
year = {2015}
}
```

The example dataset is taken from the [VolumeDeform project](http://lgdv.cs.fau.de/publications/publication/Pub.2016.tech.IMMD.IMMD9.volume_6/).
```
@inbook{innmann2016volume,
author = "Innmann, Matthias and Zollh{\"o}fer, Michael and Nie{\ss}ner, Matthias and Theobalt, Christian
and Stamminger, Marc",
editor = "Leibe, Bastian and Matas, Jiri and Sebe, Nicu and Welling, Max",
title = "VolumeDeform: Real-Time Volumetric Non-rigid Reconstruction",
bookTitle = "Computer Vision -- ECCV 2016: 14th European Conference, Amsterdam, The Netherlands,
October 11-14, 2016, Proceedings, Part VIII",
year = "2016",
publisher = "Springer International Publishing",
address = "Cham",
pages = "362--379",
isbn = "978-3-319-46484-8",
doi = "10.1007/978-3-319-46484-8_22",
url = "http://dx.doi.org/10.1007/978-3-319-46484-8_22"
}
```
131 changes: 131 additions & 0 deletions modules/dynamicfusion/cmake/Targets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
################################################################################################
# short command to setup source group
function(kf_source_group group)
cmake_parse_arguments(VW_SOURCE_GROUP "" "" "GLOB" ${ARGN})
file(GLOB srcs ${VW_SOURCE_GROUP_GLOB})
#list(LENGTH ${srcs} ___size)
#if (___size GREATER 0)
source_group(${group} FILES ${srcs})
#endif()
endfunction()


################################################################################################
# short command getting sources from standard directores
macro(pickup_std_sources)
kf_source_group("Include" GLOB "include/${module_name}/*.h*")
kf_source_group("Include\\cuda" GLOB "include/${module_name}/cuda/*.h*")
kf_source_group("Source" GLOB "src/*.cpp" "src/*.h*")
kf_source_group("Source\\utils" GLOB "src/utils/*.cpp" "src/utils/*.h*")
kf_source_group("Source\\cuda" GLOB "src/cuda/*.c*" "src/cuda/*.h*")
FILE(GLOB_RECURSE sources include/${module_name}/*.h* src/*.cpp src/*.h* src/cuda/*.h* src/cuda/*.c*)
endmacro()


################################################################################################
# short command for declaring includes from other modules
macro(declare_deps_includes)
foreach(__arg ${ARGN})
get_filename_component(___path "${CMAKE_SOURCE_DIR}/modules/${__arg}/include" ABSOLUTE)
if (EXISTS ${___path})
include_directories(${___path})
endif()
endforeach()

unset(___path)
unset(__arg)
endmacro()


################################################################################################
# short command for setting defeault target properties
function(default_properties target)
set_target_properties(${target} PROPERTIES
DEBUG_POSTFIX "d"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

if (NOT ${target} MATCHES "^test_")
install(TARGETS ${the_target} RUNTIME DESTINATION ".")
endif()
endfunction()

function(test_props target)
#os_project_label(${target} "[test]")
if(USE_PROJECT_FOLDERS)
set_target_properties(${target} PROPERTIES FOLDER "Tests")
endif()
endfunction()

function(app_props target)
#os_project_label(${target} "[app]")
if(USE_PROJECT_FOLDERS)
set_target_properties(${target} PROPERTIES FOLDER "Apps")
endif()
endfunction()


################################################################################################
# short command for setting defeault target properties
function(default_properties target)
set_target_properties(${target} PROPERTIES
DEBUG_POSTFIX "d"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

if (NOT ${target} MATCHES "^test_")
install(TARGETS ${the_target} RUNTIME DESTINATION ".")
endif()
endfunction()


################################################################################################
# short command for adding library module
macro(add_module_library name)
set(module_name ${name})
pickup_std_sources()
include_directories(include src src/cuda src/utils)

set(__has_cuda OFF)
check_cuda(__has_cuda)

set(__lib_type STATIC)
if (${ARGV1} MATCHES "SHARED|STATIC")
set(__lib_type ${ARGV1})
endif()

if (__has_cuda)
cuda_add_library(${module_name} ${__lib_type} ${sources})
else()
add_library(${module_name} ${__lib_type} ${sources})
endif()

if(MSVC)
set_target_properties(${module_name} PROPERTIES DEFINE_SYMBOL KFUSION_API_EXPORTS)
else()
add_definitions(-DKFUSION_API_EXPORTS)
endif()

default_properties(${module_name})

if(USE_PROJECT_FOLDERS)
set_target_properties(${module_name} PROPERTIES FOLDER "Libraries")
endif()

set_target_properties(${module_name} PROPERTIES INSTALL_NAME_DIR lib)

install(TARGETS ${module_name}
RUNTIME DESTINATION bin COMPONENT main
LIBRARY DESTINATION lib COMPONENT main
ARCHIVE DESTINATION lib COMPONENT main)

install(DIRECTORY include/ DESTINATION include/ FILES_MATCHING PATTERN "*.h*")
endmacro()

################################################################################################
# short command for adding application module
macro(add_application target sources)
add_executable(${target} ${sources})
default_properties(${target})
app_props(${target})
endmacro()
Loading