Skip to content
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

Add libSGM into cudastereo #2772

Merged
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: 1 addition & 1 deletion modules/cudastereo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set(the_description "CUDA-accelerated Stereo Correspondence")

ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations -Wshadow)

ocv_define_module(cudastereo opencv_calib3d WRAP python)
ocv_define_module(cudastereo opencv_calib3d OPTIONAL opencv_cudev WRAP python)
10 changes: 10 additions & 0 deletions modules/cudastereo/doc/cudastereo.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@InProceedings{Spangenberg2013,
author = {Spangenberg, Robert and Langner, Tobias and Rojas, Ra{\'u}l},
title = {Weighted Semi-Global Matching and Center-Symmetric Census Transform for Robust Driver Assistance},
booktitle = {Computer Analysis of Images and Patterns},
year = {2013},
pages = {34--41},
publisher = {Springer Berlin Heidelberg},
abstract = {Automotive applications based on stereo vision require robust and fast matching algorithms, which makes semi-global matching (SGM) a popular method in this field. Typically the Census transform is used as a cost function, since it is advantageous for outdoor scenes. We propose an extension based on center-symmetric local binary patterns, which allows better efficiency and higher matching quality. Our second contribution exploits knowledge about the three-dimensional structure of the scene to selectively enforce the smoothness constraints of SGM. It is shown that information about surface normals can be easily integrated by weighing the paths according to the gradient of the disparity. The different approaches are evaluated on the KITTI benchmark, which provides real imagery with LIDAR ground truth. The results indicate improved performance compared to state-of-the-art SGM based algorithms.},
url = {https://www.mi.fu-berlin.de/inf/groups/ag-ki/publications/Semi-Global_Matching/caip2013rsp_fu.pdf}
}
47 changes: 47 additions & 0 deletions modules/cudastereo/include/opencv2/cudastereo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,53 @@ class CV_EXPORTS_W StereoConstantSpaceBP : public cuda::StereoBeliefPropagation
CV_EXPORTS_W Ptr<cuda::StereoConstantSpaceBP>
createStereoConstantSpaceBP(int ndisp = 128, int iters = 8, int levels = 4, int nr_plane = 4, int msg_type = CV_32F);

/////////////////////////////////////////
// StereoSGM

/** @brief The class implements the modified H. Hirschmuller algorithm @cite HH08.
Limitation and difference are as follows:

- By default, the algorithm uses only 4 directions which are horizontal and vertical path instead of 8.
Set mode=StereoSGM::MODE_HH in createStereoSGM to run the full variant of the algorithm.
- Mutual Information cost function is not implemented.
Instead, Center-Symmetric Census Transform with \f$9 \times 7\f$ window size from @cite Spangenberg2013
is used for robustness.

@sa cv::StereoSGBM
*/
class CV_EXPORTS_W StereoSGM : public cv::StereoSGBM
{
public:
/** @brief Computes disparity map for the specified stereo pair

@param left Left 8-bit or 16-bit unsigned single-channel image.
@param right Right image of the same size and the same type as the left one.
@param disparity Output disparity map. It has the same size as the input images.
StereoSGM computes 16-bit fixed-point disparity map (where each disparity value has 4 fractional bits).
*/
CV_WRAP virtual void compute(InputArray left, InputArray right, OutputArray disparity) CV_OVERRIDE = 0;

/** @brief Computes disparity map with specified CUDA Stream

@sa compute
*/
CV_WRAP_AS(compute_with_stream) virtual void compute(InputArray left, InputArray right, OutputArray disparity, Stream& stream) = 0;
};

/** @brief Creates StereoSGM object.

@param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
@param numDisparities Maximum disparity minus minimum disparity. The value must be 64, 128 or 256.
@param P1 The first parameter controlling the disparity smoothness.This parameter is used for the case of slanted surfaces (not fronto parallel).
@param P2 The second parameter controlling the disparity smoothness.This parameter is used for "solving" the depth discontinuities problem.
@param uniquenessRatio Margin in percentage by which the best (minimum) computed cost function
value should "win" the second best value to consider the found match correct. Normally, a value
within the 5-15 range is good enough.
@param mode Set it to StereoSGM::MODE_HH to run the full-scale two-pass dynamic programming algorithm.
It will consume O(W\*H\*numDisparities) bytes. By default, it is set to StereoSGM::MODE_HH4.
*/
CV_EXPORTS_W Ptr<cuda::StereoSGM> createStereoSGM(int minDisparity = 0, int numDisparities = 128, int P1 = 10, int P2 = 120, int uniquenessRatio = 5, int mode = cv::cuda::StereoSGM::MODE_HH4);

/////////////////////////////////////////
// DisparityBilateralFilter

Expand Down
34 changes: 34 additions & 0 deletions modules/cudastereo/perf/perf_stereo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,38 @@ PERF_TEST_P(Sz_Depth, DrawColorDisp,
}
}

//////////////////////////////////////////////////////////////////////
// StereoSGM

PERF_TEST_P(ImagePair, StereoSGM,
Values(pair_string("gpu/perf/aloe.png", "gpu/perf/aloeR.png")))
{
declare.time(300.0);

const cv::Mat imgLeft = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(imgLeft.empty());

const cv::Mat imgRight = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(imgRight.empty());

const int ndisp = 128;

if (PERF_RUN_CUDA())
{
cv::Ptr<cv::cuda::StereoSGM> d_sgm = cv::cuda::createStereoSGM(0, ndisp);

const cv::cuda::GpuMat d_imgLeft(imgLeft);
const cv::cuda::GpuMat d_imgRight(imgRight);
cv::cuda::GpuMat dst;

TEST_CYCLE() d_sgm->compute(d_imgLeft, d_imgRight, dst);

CUDA_SANITY_CHECK(dst);
}
else
{
FAIL_NO_CPU();
}
}

}} // namespace
Loading