ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
Public Member Functions | Public Attributes | List of all members
sl_oc::tools::StereoSgbmPar Class Reference

The StereoSgbmPar class is used to store/retrieve the stereo matching parameters. More...

#include <stereo.hpp>

Public Member Functions

 StereoSgbmPar ()
 Default constructor. More...
 
bool load ()
 load stereo matching parameters More...
 
bool save ()
 save stereo matching parameters More...
 
void setDefaultValues ()
 set default stereo matching parameters More...
 
void print ()
 print the current stereo matching parameters on standard output More...
 

Public Attributes

int blockSize
 [default: 3] Matched block size. It must be an odd number >=1 . Normally, it should be somewhere in the 3..11 range. More...
 
int minDisparity
 [default: 0] Minimum possible disparity value. Normally, it is zero but sometimes rectification algorithms can shift images, so this parameter needs to be adjusted accordingly. More...
 
int numDisparities
 [default: 96] Maximum disparity minus minimum disparity. The value is always greater than zero. In the current implementation, this parameter must be divisible by 16. More...
 
int mode
 Set it to StereoSGBM::MODE_HH to run the full-scale two-pass dynamic programming algorithm. It will consume O(W*H*numDisparities) bytes, which is large for 640x480 stereo and huge for HD-size pictures. By default, it is set to cv::StereoSGBM::MODE_SGBM_3WAY. More...
 
int P1
 [default: 24*blockSize*blockSize] The first parameter controlling the disparity smoothness. See below. More...
 
int P2
 [default: 4*PI]The second parameter controlling the disparity smoothness. The larger the values are, the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1 between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor pixels. The algorithm requires P2 > P1 . See stereo_match.cpp sample where some reasonably good P1 and P2 values are shown (like 8*number_of_image_channels*blockSize*blockSize and 32*number_of_image_channels*blockSize*blockSize , respectively). More...
 
int disp12MaxDiff
 [default: 96] Maximum allowed difference (in integer pixel units) in the left-right disparity check. Set it to a non-positive value to disable the check. More...
 
int preFilterCap
 [default: 63] Truncation value for the prefiltered image pixels. The algorithm first computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval. The result values are passed to the Birchfield-Tomasi pixel cost function. More...
 
int uniquenessRatio
 [default: 5] 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. More...
 
int speckleWindowSize
 [default: 255] Maximum size of smooth disparity regions to consider their noise speckles and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the 50-200 range. More...
 
int speckleRange
 [default: 1] Maximum disparity variation within each connected component. If you do speckle filtering, set the parameter to a positive value, it will be implicitly multiplied by 16. Normally, 1 or 2 is good enough. More...
 
double minDepth_mm
 [default: 300] Minimum value of depth for the extracted depth map More...
 
double maxDepth_mm
 [default: 10000] Maximum value of depth for the extracted depth map More...
 

Detailed Description

The StereoSgbmPar class is used to store/retrieve the stereo matching parameters.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 19 of file stereo.hpp.

Constructor & Destructor Documentation

◆ StereoSgbmPar()

sl_oc::tools::StereoSgbmPar::StereoSgbmPar ( )
inline

Default constructor.

Definition at line 25 of file stereo.hpp.

26  {
28  }
void setDefaultValues()
set default stereo matching parameters
Definition: stereo.hpp:69

References setDefaultValues().

Member Function Documentation

◆ load()

bool sl_oc::tools::StereoSgbmPar::load ( )

load stereo matching parameters

Returns
true if a configuration file exists
Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 87 of file stereo.hpp.

88 {
89  std::string path = getHiddenDir();
90  std::string par_file = path + STEREO_PAR_FILENAME;
91 
92  cv::FileStorage fs;
93  if(!fs.open(par_file, cv::FileStorage::READ))
94  {
95  std::cerr << "Error opening stereo parameters file. Using default values." << std::endl << std::endl;
97  return false;
98  }
99 
100  fs["blockSize"] >> blockSize;
101  fs["minDisparity"] >> minDisparity;
102  fs["numDisparities"] >> numDisparities;
103  fs["mode"] >> mode;
104  fs["disp12MaxDiff"] >> disp12MaxDiff;
105  fs["preFilterCap"] >> preFilterCap;
106  fs["uniquenessRatio"] >> uniquenessRatio;
107  fs["speckleWindowSize"] >> speckleWindowSize;
108  fs["speckleRange"] >> speckleRange;
109  P1 = 24*blockSize*blockSize;
110  P2 = 96*blockSize*blockSize;
111 
112  fs["minDepth_mm"] >> minDepth_mm;
113  fs["maxDepth_mm"] >> maxDepth_mm;
114 
115  std::cout << "Stereo parameters load done: " << par_file << std::endl << std::endl;
116 
117  return true;
118 }
int P1
[default: 24*blockSize*blockSize] The first parameter controlling the disparity smoothness....
Definition: stereo.hpp:57
int disp12MaxDiff
[default: 96] Maximum allowed difference (in integer pixel units) in the left-right disparity check....
Definition: stereo.hpp:59
int speckleWindowSize
[default: 255] Maximum size of smooth disparity regions to consider their noise speckles and invalida...
Definition: stereo.hpp:62
int uniquenessRatio
[default: 5] Margin in percentage by which the best (minimum) computed cost function value should "wi...
Definition: stereo.hpp:61
double minDepth_mm
[default: 300] Minimum value of depth for the extracted depth map
Definition: stereo.hpp:65
int minDisparity
[default: 0] Minimum possible disparity value. Normally, it is zero but sometimes rectification algor...
Definition: stereo.hpp:54
int numDisparities
[default: 96] Maximum disparity minus minimum disparity. The value is always greater than zero....
Definition: stereo.hpp:55
int mode
Set it to StereoSGBM::MODE_HH to run the full-scale two-pass dynamic programming algorithm....
Definition: stereo.hpp:56
int speckleRange
[default: 1] Maximum disparity variation within each connected component. If you do speckle filtering...
Definition: stereo.hpp:63
int blockSize
[default: 3] Matched block size. It must be an odd number >=1 . Normally, it should be somewhere in t...
Definition: stereo.hpp:53
double maxDepth_mm
[default: 10000] Maximum value of depth for the extracted depth map
Definition: stereo.hpp:66
int preFilterCap
[default: 63] Truncation value for the prefiltered image pixels. The algorithm first computes x-deriv...
Definition: stereo.hpp:60
int P2
[default: 4*PI]The second parameter controlling the disparity smoothness. The larger the values are,...
Definition: stereo.hpp:58
const std::string STEREO_PAR_FILENAME
STEREO_PAR_FILENAME default stereo parameter configuration file.
Definition: stereo.hpp:14

References blockSize, disp12MaxDiff, maxDepth_mm, minDepth_mm, minDisparity, mode, numDisparities, P1, P2, preFilterCap, setDefaultValues(), speckleRange, speckleWindowSize, sl_oc::tools::STEREO_PAR_FILENAME, and uniquenessRatio.

Referenced by main().

◆ print()

void sl_oc::tools::StereoSgbmPar::print ( )

print the current stereo matching parameters on standard output

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 150 of file stereo.hpp.

151 {
152  std::cout << "Stereo SGBM parameters:" << std::endl;
153  std::cout << "------------------------------------------" << std::endl;
154  std::cout << "blockSize:\t\t" << blockSize << std::endl;
155  std::cout << "minDisparity:\t" << minDisparity << std::endl;
156  std::cout << "numDisparities:\t" << numDisparities << std::endl;
157  std::cout << "mode:\t\t" << mode << std::endl;
158  std::cout << "disp12MaxDiff:\t" << disp12MaxDiff << std::endl;
159  std::cout << "preFilterCap:\t" << preFilterCap << std::endl;
160  std::cout << "uniquenessRatio:\t" << uniquenessRatio << std::endl;
161  std::cout << "speckleWindowSize:\t" << speckleWindowSize << std::endl;
162  std::cout << "speckleRange:\t" << speckleRange << std::endl;
163  std::cout << "P1:\t\t" << P1 << " [Calculated]" << std::endl;
164  std::cout << "P2:\t\t" << P2 << " [Calculated]" << std::endl;
165 
166  std::cout << "minDepth_mm:\t" << minDepth_mm << std::endl;
167  std::cout << "maxDepth_mm:\t" << maxDepth_mm << std::endl;
168  std::cout << "------------------------------------------" << std::endl << std::endl;
169 }

References blockSize, disp12MaxDiff, maxDepth_mm, minDepth_mm, minDisparity, mode, numDisparities, P1, P2, preFilterCap, speckleRange, speckleWindowSize, and uniquenessRatio.

Referenced by main().

◆ save()

bool sl_oc::tools::StereoSgbmPar::save ( )

save stereo matching parameters

Returns
true if a configuration file has been correctly created
Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 120 of file stereo.hpp.

121 {
122  std::string path = getHiddenDir();
123  std::string par_file = path + STEREO_PAR_FILENAME;
124 
125  cv::FileStorage fs;
126  if(!fs.open(par_file, cv::FileStorage::WRITE))
127  {
128  std::cerr << "Error saving stereo parameters. Cannot open file for writing: " << par_file << std::endl << std::endl;
129  return false;
130  }
131 
132  fs << "blockSize" << blockSize;
133  fs << "minDisparity" << minDisparity;
134  fs << "numDisparities" << numDisparities;
135  fs << "mode" << mode;
136  fs << "disp12MaxDiff" << disp12MaxDiff;
137  fs << "preFilterCap" << preFilterCap;
138  fs << "uniquenessRatio" << uniquenessRatio;
139  fs << "speckleWindowSize" << speckleWindowSize;
140  fs << "speckleRange" << speckleRange;
141 
142  fs << "minDepth_mm" << minDepth_mm;
143  fs << "maxDepth_mm" << maxDepth_mm;
144 
145  std::cout << "Stereo parameters write done: " << par_file << std::endl << std::endl;
146 
147  return true;
148 }

References blockSize, disp12MaxDiff, maxDepth_mm, minDepth_mm, minDisparity, mode, numDisparities, preFilterCap, speckleRange, speckleWindowSize, sl_oc::tools::STEREO_PAR_FILENAME, and uniquenessRatio.

Referenced by main().

◆ setDefaultValues()

void sl_oc::tools::StereoSgbmPar::setDefaultValues ( )

set default stereo matching parameters

Examples
zed_oc_tune_stereo_sgbm.cpp.

Definition at line 69 of file stereo.hpp.

70 {
71  blockSize = 3;
72  minDisparity = 0;
73  numDisparities = 96;
74  mode = cv::StereoSGBM::MODE_SGBM_3WAY; // MODE_SGBM = 0, MODE_HH = 1, MODE_SGBM_3WAY = 2, MODE_HH4 = 3
75  P1 = 24*blockSize*blockSize;
76  P2 = 4*P1;
77  disp12MaxDiff = 96;
78  preFilterCap = 63;
79  uniquenessRatio = 5;
80  speckleWindowSize = 255;
81  speckleRange = 1;
82 
83  minDepth_mm = 300.;
84  maxDepth_mm = 10000.;
85 }

References blockSize, disp12MaxDiff, maxDepth_mm, minDepth_mm, minDisparity, mode, numDisparities, P1, P2, preFilterCap, speckleRange, speckleWindowSize, and uniquenessRatio.

Referenced by load(), main(), and StereoSgbmPar().

Member Data Documentation

◆ blockSize

int sl_oc::tools::StereoSgbmPar::blockSize

[default: 3] Matched block size. It must be an odd number >=1 . Normally, it should be somewhere in the 3..11 range.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 53 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), on_trackbar_block_size(), print(), save(), and setDefaultValues().

◆ disp12MaxDiff

int sl_oc::tools::StereoSgbmPar::disp12MaxDiff

[default: 96] Maximum allowed difference (in integer pixel units) in the left-right disparity check. Set it to a non-positive value to disable the check.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 59 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), on_trackbar_disp12MaxDiff(), print(), save(), and setDefaultValues().

◆ maxDepth_mm

double sl_oc::tools::StereoSgbmPar::maxDepth_mm

[default: 10000] Maximum value of depth for the extracted depth map

Examples
zed_oc_depth_example.cpp.

Definition at line 66 of file stereo.hpp.

Referenced by load(), main(), print(), save(), and setDefaultValues().

◆ minDepth_mm

double sl_oc::tools::StereoSgbmPar::minDepth_mm

[default: 300] Minimum value of depth for the extracted depth map

Examples
zed_oc_depth_example.cpp.

Definition at line 65 of file stereo.hpp.

Referenced by load(), main(), print(), save(), and setDefaultValues().

◆ minDisparity

int sl_oc::tools::StereoSgbmPar::minDisparity

[default: 0] Minimum possible disparity value. Normally, it is zero but sometimes rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 54 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), on_trackbar_min_disparities(), on_trackbar_num_disparities(), print(), save(), and setDefaultValues().

◆ mode

int sl_oc::tools::StereoSgbmPar::mode

Set it to StereoSGBM::MODE_HH to run the full-scale two-pass dynamic programming algorithm. It will consume O(W*H*numDisparities) bytes, which is large for 640x480 stereo and huge for HD-size pictures. By default, it is set to cv::StereoSGBM::MODE_SGBM_3WAY.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 56 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), on_trackbar_mode(), print(), save(), and setDefaultValues().

◆ numDisparities

int sl_oc::tools::StereoSgbmPar::numDisparities

[default: 96] Maximum disparity minus minimum disparity. The value is always greater than zero. In the current implementation, this parameter must be divisible by 16.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 55 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), on_trackbar_min_disparities(), on_trackbar_num_disparities(), print(), save(), and setDefaultValues().

◆ P1

int sl_oc::tools::StereoSgbmPar::P1

[default: 24*blockSize*blockSize] The first parameter controlling the disparity smoothness. See below.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 57 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), on_trackbar_block_size(), print(), and setDefaultValues().

◆ P2

int sl_oc::tools::StereoSgbmPar::P2

[default: 4*PI]The second parameter controlling the disparity smoothness. The larger the values are, the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1 between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor pixels. The algorithm requires P2 > P1 . See stereo_match.cpp sample where some reasonably good P1 and P2 values are shown (like 8*number_of_image_channels*blockSize*blockSize and 32*number_of_image_channels*blockSize*blockSize , respectively).

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 58 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), print(), and setDefaultValues().

◆ preFilterCap

int sl_oc::tools::StereoSgbmPar::preFilterCap

[default: 63] Truncation value for the prefiltered image pixels. The algorithm first computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval. The result values are passed to the Birchfield-Tomasi pixel cost function.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 60 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), on_trackbar_preFilterCap(), print(), save(), and setDefaultValues().

◆ speckleRange

int sl_oc::tools::StereoSgbmPar::speckleRange

[default: 1] Maximum disparity variation within each connected component. If you do speckle filtering, set the parameter to a positive value, it will be implicitly multiplied by 16. Normally, 1 or 2 is good enough.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 63 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), on_trackbar_speckleRange(), print(), save(), and setDefaultValues().

◆ speckleWindowSize

int sl_oc::tools::StereoSgbmPar::speckleWindowSize

[default: 255] Maximum size of smooth disparity regions to consider their noise speckles and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the 50-200 range.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 62 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), on_trackbar_speckleWindowSize(), print(), save(), and setDefaultValues().

◆ uniquenessRatio

int sl_oc::tools::StereoSgbmPar::uniquenessRatio

[default: 5] 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.

Examples
zed_oc_depth_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 61 of file stereo.hpp.

Referenced by applyStereoMatching(), load(), main(), on_trackbar_uniquenessRatio(), print(), save(), and setDefaultValues().


The documentation for this class was generated from the following file: