stereo-vision
All Data Structures Namespaces Functions Modules Pages
StereoMatcher.h
1 
2 #ifndef _STEREO_MATCHER_NEW_H_
3 #define _STEREO_MATCHER_NEW_H_
4 
5 #include <yarp/os/all.h>
6 
7 #include <iCub/stereoVision/elasWrapper.h>
8 #include <iCub/stereoVision/stereoCamera.h>
9 
10 #include "common.h"
11 #include "sgbm_cuda_header.h"
12 
13 #include "opencv2/ximgproc/disparity_filter.hpp"
14 
22 Rect computeROI2(Size2i src_sz, Ptr<StereoMatcher> matcher_instance);
23 
24 
25 // enum to handle the different stereo matching algorithms available
26 
27 enum SM_MATCHING_ALG {
28  SGBM_OPENCV = 0,
29  SGBM_CUDA,
30  LIBELAS
31 };
32 
33 
34 // enum to handle the different bilateral filtering methods
35 
36 enum SM_BLF_FILTER {
37  BLF_DISABLED = 0,
38  BLF_ORIGINAL,
39  BLF_CUDA
40 };
41 
42 
43 // enum to handle the activation of the WLS filtering
44 
45 enum SM_WLS_FILTER {
46  WLS_DISABLED = 0,
47  WLS_ENABLED,
48  WLS_LRCHECK
49 };
50 
51 
52 // struct containing the parameters for the
53 // stereo matching and filtering algorithms
54 
55 typedef struct {
56 
57  int uniquenessRatio;
58  int speckleWindowSize;
59  int speckleRange;
60  int numberOfDisparities;
61  int SADWindowSize;
62  int minDisparity;
63  int preFilterCap;
64  int disp12MaxDiff;
65 
66  double sigmaColorBLF;
67  double sigmaSpaceBLF;
68  double wls_lambda;
69  double wls_sigma;
70 
71  SM_BLF_FILTER BLFfiltering;
72  SM_WLS_FILTER WLSfiltering;
73  SM_MATCHING_ALG stereo_matching;
74 
75 } Params;
76 
77 
78 // auxiliary struct meant to contain the disparity maps calculated
79 // NOTE: not used at the moment in the code
80 
81 typedef struct {
82 
83  cv::Mat disp;
84  cv::Mat disp16;
85 
86  cv::Mat disp_blf;
87  cv::Mat disp16_blf;
88 
89  cv::Mat disp_wls;
90  cv::Mat disp16_wls;
91 
92 } Disparities;
93 
94 
95 class StereoMatcherNew {
96 
97 private:
98 
99  // pointer to the StereoCamera object used
100 
101  StereoCamera * stereo;
102 
103  // base disparity
104 
105  cv::Mat disparity;
106  cv::Mat disparity16;
107 
108  // disparity after blf filtering
109 
110  cv::Mat disparity_blf;
111  cv::Mat disparity16_blf;
112 
113  // disparity after wls filtering
114 
115  cv::Mat disparity_wls;
116  cv::Mat disparity16_wls;
117 
118  // selections for the different methods
119  // used to carry out the processing
120 
121  SM_MATCHING_ALG stereo_matching;
122  SM_BLF_FILTER blf_filtering;
123  SM_WLS_FILTER wls_filtering;
124 
125  //
126 
127  // bool disp_wls_available, disp_blf_available;
128  Ptr<cv::ximgproc::DisparityWLSFilter> wls_filter;
129 
130  // fields used for the SGBM implementation in CUDA
131 
132  cv::cuda::GpuMat imageGpu, gpuDisp, filtGpu;
133  Ptr<cuda::DisparityBilateralFilter> pCudaBilFilter;
134  SGM_PARAMS cuda_params, params_right;
135 
136  // stereo matching parameters
137 
138  Params stereo_parameters;
139  bool useBestDisp;
140 
141  // different matching algorithms available
142 
143  void matchSGBM();
144  void matchLIBELAS();
145  void matchSGBMCUDA();
146 
147  // object wrapping the LibElas calls
148 
149  elasWrapper* elaswrap;
150 
151 public:
152 
158  void initELAS(yarp::os::ResourceFinder &rf);
159 
164  void initCUDAbilateralFilter();
165 
166 
171  void setParameters(int minDisparity, int numberOfDisparities, int SADWindowSize,
172  int disp12MaxDiff, int preFilterCap, int uniquenessRatio,
173  int speckleWindowSize, int speckleRange, double sigmaColorBLF,
174  double sigmaSpaceBLF, double wls_lambda, double wls_sigma,
175  SM_BLF_FILTER BLFfiltering, SM_WLS_FILTER WLSfiltering,
176  SM_MATCHING_ALG stereo_matching);
177 
182  void compute();
183 
189  void setAlgorithm(string name);
190 
197  cv::Mat getDisparity(string kind);
198 
205  cv::Mat getDisparity16(string kind);
206 
211  void updateCUDAParams();
212 
218  void filterBLF(string kind);
219 
225  void filterWLS(string kind);
226 
233  StereoMatcherNew(yarp::os::ResourceFinder &rf, StereoCamera * stereo);
234  ~StereoMatcherNew();
235 
236 
237 
238 };
239 
240 #endif // _STEREO_MATCHER_NEW
The base class defining stereo camera.
Definition: stereoCamera.h:92