Skip to content

Commit 2efda94

Browse files
Add sources
0 parents  commit 2efda94

26 files changed

+3675
-0
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.18)
2+
3+
project(CudaMultiViewStereo)
4+
5+
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
6+
set(CMAKE_CUDA_ARCHITECTURES "52;61;72;75;86")
7+
endif()
8+
9+
add_subdirectory(modules)
10+
add_subdirectory(samples)

README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# cuda-multi-view-stereo
2+
3+
C++/CUDA library for Multi-View Stereo
4+
5+
---
6+
7+
## Description
8+
cuda-multi-view-stereo (CUMVS) is a C++/CUDA library for Multi-View Stereo. This project currently supports depth map estimation using PatchMatch algorithms.
9+
10+
## Features
11+
12+
### Implementation of recent PatchMatch algorithms
13+
14+
This project aims to incorporate the essence of recent PatchMatch algorithms such as [ACMM](https://github.com/GhiXu/ACMM) while simplifying the implementation as much as possible.
15+
16+
### Performance optimization using GPU and CPU
17+
18+
The performance of CUDA kernels for propagation is optimized using shared memory, texture fetching, projective transformation approximations, etc. In addition, the performance of some processes performed on the CPU is optimized using multi-core parallelization and reduced disk access.
19+
20+
<div align="center">
21+
<img src="https://github.com/fixstars/cuda-multi-view-stereo/wiki/images/runtime.png" width=1024>
22+
</div>
23+
24+
### Support for debugging and visualization
25+
26+
The debug callback function allows you to check the status of the propagation during execution. In addition, you can instantly check the 3D reconstruction results using OpenCV's Viz module. Please check the [sample code](./samples/app_patch_match_mvs.cpp) for usage.
27+
28+
<div align="center">
29+
<img src="https://github.com/fixstars/cuda-multi-view-stereo/wiki/images/demo.gif" width=1024><br/>
30+
Visualization of propagation using debug callback (from left: reference image, depth map, normal map, cost map)
31+
</div>
32+
33+
---
34+
35+
## Performance
36+
37+
### Settings
38+
|Key|Value|
39+
|---|---|
40+
|CPU|Intel Core i7-13700K|
41+
|GPU|NVIDIA GeForce RTX 3080|
42+
|Maximum image size|3200 pixels for each dimension|
43+
44+
### Results on ETH3D High-res multi-view training dataset [2cm]
45+
46+
| method | Mean | courtyard | delivery_area | electro | facade | kicker | meadow | office | pipes | playground | relief | relief_2 | terrace | terrains |
47+
|--------|------|-----------|---------------|---------|--------|--------|--------|--------|-------|------------|--------|----------|---------|----------|
48+
| ACMM | 78.9 | 87.5 | 83.7 | 86.8 | 70.8 | 77.5 | 66.4 | 64.9 | 70.1 | 72.1 | 85.4 | 84.9 | 89.9 | 85.5 |
49+
| CUMVS | 81.8 | 86.4 | 86.1 | 86.3 | 69.2 | 86.9 | 76.1 | 75.2 | 73 | 74.6 | 85.8 | 84.2 | 89.8 | 90.2 |
50+
51+
### Runtime (in second) on ETH3D High-res multi-view training dataset
52+
53+
| SCENE | Total | courtyard | delivery_area | electro | facade | kicker | meadow | office | pipes | playground | relief | relief_2 | terrace | terrains |
54+
|-------|---------|-----------|---------------|---------|--------|--------|--------|--------|-------|------------|--------|----------|---------|----------|
55+
| ACMM | 12277.7 | 1051.8 | 1014 | 1173.1 | 2471.1 | 908.6 | 337.2 | 595.7 | 233.5 | 1093.3 | 855.6 | 813.4 | 520.2 | 1210.2 |
56+
| CUMVS | 2140.4 | 174.1 | 189.2 | 190.2 | 382.4 | 154.5 | 49.8 | 95.8 | 42.4 | 152.3 | 208.5 | 185.4 | 103.1 | 212.7 |
57+
58+
---
59+
60+
## Requirements
61+
|Package Name|Minimum Requirements|Note|
62+
|---|---|---|
63+
|CMake|version >= 3.18||
64+
|CUDA Toolkit|compute capability >= 6.0|
65+
|OpenCV|version >= 4.6.0||
66+
|OpenCV CUDA module|version >= 4.6.0|included in [opencv/opencv_contrib](https://github.com/opencv/opencv_contrib)|
67+
|OpenCV Viz module|version >= 4.6.0|included in [opencv/opencv_contrib](https://github.com/opencv/opencv_contrib)|
68+
|VTK|version >= 9.0|needed for OpenCV Viz module|
69+
70+
---
71+
72+
## How to build
73+
```bash
74+
$ git clone https://github.com/fixstars/cuda-multi-view-stereo.git
75+
$ cd cuda-multi-view-stereo
76+
$ mkdir build
77+
$ cd build
78+
$ cmake .. # specify CUDA architecture if necessary (e.g. -DCMAKE_CUDA_ARCHITECTURES=86)
79+
$ make
80+
```
81+
82+
### CMake options
83+
|Option|Description|Default|
84+
|---|---|---|
85+
|CMAKE_CUDA_ARCHITECTURES|List of architectures to generate device code for|`52;61;72;75;86`|
86+
87+
## How to run
88+
### samples
89+
90+
|Command|Description|
91+
|---|---|
92+
|`./samples/app_initialize_ETH3D scene-directory [options]`|Input data preparation for ETD3D dataset|
93+
|`./samples/app_patch_match_mvs input-directory [options]`|Depth map estimation and 3D reconstruction|
94+
95+
Use the `--help` or `-h` option for detailed information.
96+
97+
### Example of running CUMVS on ETH3D High-res multi-view data
98+
99+
Here we will use the "pipes" scene as an example.
100+
Download `pipes_dslr_undistorted.7z` from [ETH3D datasets](https://www.eth3d.net/datasets) and unzip it.
101+
102+
Create input data using `app_initialize_ETH3D`.
103+
104+
```bash
105+
./samples/app_initialize_ETH3D /path_to_eth3d/pipes_dslr_undistorted/pipes --output-directory=inputs/pipes
106+
```
107+
108+
Test `app_patch_match_mvs`.
109+
The default image size is large and time consuming, so we recommend trying a smaller size first.
110+
The option `-d` specifies debug display.
111+
112+
```bash
113+
./samples/app_patch_match_mvs inputs/pipes --max-image-size=800 -d
114+
```
115+
116+
If there are no problems, run the application with your preferred options.
117+
After execution, a point cloud file `output/point_cloud_dense.ply` will be generated.
118+
119+
---
120+
121+
## Future work
122+
- Improving depth estimation accuracy using plane prior and adaptive patch deformation
123+
- Speeding up [ETH3D Multi-View Evaluation Program](https://github.com/ETH3D/multi-view-evaluation) and incorporate it into this project
124+
- Implementing processes after mesh reconstruction
125+
126+
---
127+
128+
## Author
129+
The "adaskit Team"
130+
131+
The adaskit is an open-source project created by [Fixstars Corporation](https://www.fixstars.com/) and its subsidiary companies including [Fixstars Autonomous Technologies](https://at.fixstars.com/), aimed at contributing to the ADAS industry by developing high-performance implementations for algorithms with high computational cost.
132+
133+
---
134+
135+
## License
136+
Apache License 2.0

modules/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(cuda_multi_view_stereo)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.18)
2+
3+
set(PROJECT_NAME cuda_multi_view_stereo)
4+
set(INTERFACE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
5+
set(INTERNAL_INCLUDE_DIR ${INTERFACE_INCLUDE_DIR})
6+
7+
# create project
8+
project(${PROJECT_NAME} LANGUAGES CXX CUDA)
9+
10+
# dependent packages
11+
find_package(OpenCV REQUIRED core cudev)
12+
find_package(OpenMP REQUIRED)
13+
find_package(CUDAToolkit REQUIRED)
14+
15+
# target configuration
16+
file(GLOB SRCS src/*.cpp src/*.cu src/*.h* ${INTERNAL_INCLUDE_DIR}/*.h*)
17+
add_library(${PROJECT_NAME})
18+
target_sources(${PROJECT_NAME} PRIVATE ${SRCS})
19+
target_include_directories(${PROJECT_NAME} PRIVATE ${INTERNAL_INCLUDE_DIR} ${OpenCV_INCLUDE_DIRS})
20+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
21+
target_link_libraries(${PROJECT_NAME} PUBLIC ${OpenCV_LIBS} OpenMP::OpenMP_CXX CUDA::cudart)
22+
set_target_properties(${PROJECT_NAME} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INTERFACE_INCLUDE_DIR})
23+
24+
target_compile_options(${PROJECT_NAME} PRIVATE
25+
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wall -O3>
26+
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-Wall -O3>
27+
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/wd4819>
28+
$<$<COMPILE_LANGUAGE:CUDA>:-lineinfo>
29+
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CXX_COMPILER_ID:MSVC>>:-lineinfo -Xcompiler="\"/wd4819 /wd4244\"">
30+
)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
Copyright 2025 Fixstars Corporation
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http ://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#ifndef __CUDA_MULTI_VIEW_STEREO_H__
18+
#define __CUDA_MULTI_VIEW_STEREO_H__
19+
20+
#include <opencv2/core.hpp>
21+
22+
namespace cv
23+
{
24+
namespace cuda
25+
{
26+
27+
/** @brief The PatchMatch methods
28+
*/
29+
enum PatchMatchMethod
30+
{
31+
GIPUMA_FAST, //!< Gipuma, fast settings
32+
ACMH, //!< Adaptive Checkerboard sampling and Multi-Hypothesis joint view selection
33+
};
34+
35+
/** @brief The class implements PatchMatch-based multi-view stereo.
36+
*/
37+
class PatchMatchMVS
38+
{
39+
public:
40+
41+
/** @brief The callback function for debugging and visualization
42+
*/
43+
using DebugCallBack = void(*)(InputArray image, InputArray depths, InputArray normals, InputArray costs, const String& title);
44+
45+
/** @brief The PatchMatchMVS constructor
46+
@param method PatchMatch method, see #PatchMatchMethod.
47+
@param pmIters Number of innier PatchMatch iterations.
48+
@param gcIters Number of outer PatchMatch iterations performed with geometric consistency.
49+
@param multiScale If true, the algorithm uses multi-scale method
50+
*/
51+
static Ptr<PatchMatchMVS> create(PatchMatchMethod method = ACMH, int pmIters = 3, int gcIters = 0, bool multiScale = false);
52+
53+
/** @brief The destructor
54+
*/
55+
virtual ~PatchMatchMVS();
56+
57+
/** @brief Computes depth maps for the given images and reprojects to 3D space.
58+
@param images Input array of color images.
59+
@param cameras Input array of camera matrices.
60+
@param rotations Input array of 3x3 rotation matrices.
61+
@param translations Input array of 3D translation vectors.
62+
@param viewIdSets Input array of "viewIdSet"s,
63+
a viewIdSet consists of [ reference view index, neighbor view index #1, neighbor view index #2, ... ]
64+
@param initialObjectPoints Iutput array of sparse 3D points in object coordinates.
65+
@param objectPoints Output array of densified 3D points in object coordinates.
66+
@param objectColors Output array of colors of the same size with objectPoints.
67+
@param objectNormals Output array of normals of the same size with objectPoints.
68+
@param depths Output array of depth maps.
69+
*/
70+
virtual void compute(InputArrayOfArrays images, InputArrayOfArrays cameras, InputArrayOfArrays rotations,
71+
InputArrayOfArrays translations, InputArrayOfArrays viewIdSets, InputArray initialObjectPoints,
72+
OutputArray objectPoints, OutputArray objectColors, OutputArray objectNormals,
73+
OutputArrayOfArrays depths = noArray()) = 0;
74+
75+
virtual void setPatchMatchMethod(PatchMatchMethod method) = 0;
76+
virtual void setPatchMatchIters(int pmIters) = 0;
77+
virtual void setGeometricConsistencyIters(int gcIters) = 0;
78+
virtual void setMultiScale(bool multiScale) = 0;
79+
virtual void setDebugCallBack(DebugCallBack callBack) = 0;
80+
};
81+
82+
} // namespace cuda
83+
} // namespace cv
84+
85+
#endif // !__CUDA_MULTI_VIEW_STEREO_H__
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2025 Fixstars Corporation
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http ://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#ifndef __CUDA_MACRO_H__
18+
#define __CUDA_MACRO_H__
19+
20+
#include <cstdio>
21+
#include <cuda.h>
22+
23+
#define CUDA_CHECK(err) \
24+
do {\
25+
if (err != cudaSuccess) { \
26+
printf("[CUDA Error] %s (code: %d) at %s:%d\n", cudaGetErrorString(err), err, __FILE__, __LINE__); \
27+
} \
28+
} while (0)
29+
30+
#endif // !__CUDA_MACRO_H__

0 commit comments

Comments
 (0)