StereoSGBM.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
30 #include <opencv2/calib3d/calib3d.hpp>
31 #include <opencv2/imgproc/imgproc.hpp>
32 #include <opencv2/imgproc/types_c.h>
33 
34 namespace rtabmap {
35 
37  StereoDense(parameters),
38  blockSize_(Parameters::defaultStereoSGBMBlockSize()),
39  minDisparity_(Parameters::defaultStereoSGBMMinDisparity()),
40  numDisparities_(Parameters::defaultStereoSGBMNumDisparities()),
41  preFilterCap_(Parameters::defaultStereoSGBMPreFilterCap()),
42  uniquenessRatio_(Parameters::defaultStereoSGBMUniquenessRatio()),
43  speckleWindowSize_(Parameters::defaultStereoSGBMSpeckleWindowSize()),
44  speckleRange_(Parameters::defaultStereoSGBMSpeckleRange()),
45  P1_(Parameters::defaultStereoSGBMP1()),
46  P2_(Parameters::defaultStereoSGBMP2()),
47  disp12MaxDiff_(Parameters::defaultStereoSGBMDisp12MaxDiff()),
48  mode_(Parameters::defaultStereoSGBMMode())
49 {
50  this->parseParameters(parameters);
51 }
52 
54 {
55  Parameters::parse(parameters, Parameters::kStereoSGBMBlockSize(), blockSize_);
56  Parameters::parse(parameters, Parameters::kStereoSGBMMinDisparity(), minDisparity_);
57  Parameters::parse(parameters, Parameters::kStereoSGBMNumDisparities(), numDisparities_);
58  Parameters::parse(parameters, Parameters::kStereoSGBMPreFilterCap(), preFilterCap_);
59  Parameters::parse(parameters, Parameters::kStereoSGBMUniquenessRatio(), uniquenessRatio_);
60  Parameters::parse(parameters, Parameters::kStereoSGBMSpeckleWindowSize(), speckleWindowSize_);
61  Parameters::parse(parameters, Parameters::kStereoSGBMSpeckleRange(), speckleRange_);
62  Parameters::parse(parameters, Parameters::kStereoSGBMP1(), P1_);
63  Parameters::parse(parameters, Parameters::kStereoSGBMP2(), P2_);
64  Parameters::parse(parameters, Parameters::kStereoSGBMDisp12MaxDiff(), disp12MaxDiff_);
65  Parameters::parse(parameters, Parameters::kStereoSGBMMode(), mode_);
66 }
67 
69  const cv::Mat & leftImage,
70  const cv::Mat & rightImage) const
71 {
72  UASSERT(!leftImage.empty() && !rightImage.empty());
73  UASSERT(leftImage.cols == rightImage.cols && leftImage.rows == rightImage.rows);
74  UASSERT((leftImage.type() == CV_8UC1 || leftImage.type() == CV_8UC3) && rightImage.type() == CV_8UC1);
75 
76  cv::Mat leftMono;
77  if(leftImage.channels() == 3)
78  {
79  cv::cvtColor(leftImage, leftMono, CV_BGR2GRAY);
80  }
81  else
82  {
83  leftMono = leftImage;
84  }
85 
86  cv::Mat disparity;
87 #if CV_MAJOR_VERSION < 3
88  cv::StereoSGBM stereo(
91  blockSize_,
92  P1_,
93  P2_,
99  mode_==1);
100  stereo(leftMono, rightImage, disparity);
101 #else
102  cv::Ptr<cv::StereoSGBM> stereo = cv::StereoSGBM::create(
105  blockSize_,
106  P1_,
107  P2_,
113  mode_);
114  stereo->compute(leftMono, rightImage, disparity);
115 #endif
116  return disparity;
117 }
118 
119 } /* namespace rtabmap */
static bool parse(const ParametersMap &parameters, const std::string &key, bool &value)
Definition: Parameters.cpp:497
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
#define UASSERT(condition)
virtual void parseParameters(const ParametersMap &parameters)
Definition: StereoSGBM.cpp:53
virtual cv::Mat computeDisparity(const cv::Mat &leftImage, const cv::Mat &rightImage) const
Definition: StereoSGBM.cpp:68
StereoSGBM(const ParametersMap &parameters=ParametersMap())
Definition: StereoSGBM.cpp:36
ULogger class and convenient macros.


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:38:57