4 #define CVUI_IMPLEMENTATION
7 const char * WINDOW_NAME =
"DisparityModule Parameters";
22 void GUI::initializeGUI(
int &minDisparity,
int &numberOfDisparities,
int &SADWindowSize,
23 int &disp12MaxDiff,
int &preFilterCap,
int &uniquenessRatio,
24 int &speckleWindowSize,
int &speckleRange,
double &sigmaColorBLF,
25 double &sigmaSpaceBLF,
double &wls_lambda,
double &wls_sigma,
26 SM_BLF_FILTER &BLFfiltering, SM_WLS_FILTER &WLSfiltering,
27 SM_MATCHING_ALG &stereo_matching)
29 this->params.minDisparity = minDisparity;
30 this->params.numberOfDisparities = numberOfDisparities;
31 this->params.SADWindowSize = SADWindowSize;
32 this->params.disp12MaxDiff = disp12MaxDiff;
33 this->params.preFilterCap = preFilterCap;
34 this->params.uniquenessRatio = uniquenessRatio;
35 this->params.speckleWindowSize = speckleWindowSize;
36 this->params.speckleRange = speckleRange;
37 this->params.sigmaColorBLF = sigmaColorBLF;
38 this->params.sigmaSpaceBLF = sigmaSpaceBLF;
39 this->params.wls_lambda = wls_lambda;
40 this->params.wls_sigma = wls_sigma;
41 this->params.BLFfiltering = BLFfiltering;
42 this->params.WLSfiltering = WLSfiltering;
43 this->params.stereo_matching = stereo_matching;
47 this->convertEnumToID();
48 this->initializeGUI();
52 void GUI::initializeGUI()
62 frame = cv::Mat(cv::Size(gui_width, cvuiw::estimateHeight(12,4,2)), CV_8UC3);
63 cvui::init(WINDOW_NAME, 3);
78 if(cv::getWindowProperty(WINDOW_NAME, 0) < 0)
86 frame = cv::Scalar(20, 22, 23);
92 this->updated =
false;
98 this->updated |= cvuiw::trackbar<int>(
"refineTh", frame, &(this->refine_th), 0, 50, 1,
"%1.Lf", cvui::TRACKBAR_HIDE_LABELS);
99 this->updated |= cvuiw::trackbar<int>(
"minDisparity", frame, &(this->params.minDisparity), 0, 20, 1,
"%1.Lf", cvui::TRACKBAR_HIDE_LABELS);
100 this->updated |= cvuiw::trackbar<int>(
"SADWindowSize", frame, &(this->params.SADWindowSize), 3, 31, 1,
"%1.Lf", cvui::TRACKBAR_HIDE_LABELS);
101 this->updated |= cvuiw::trackbar<int>(
"disp12MaxDiff", frame, &(this->params.disp12MaxDiff), 0, 30, 1,
"%1.Lf", cvui::TRACKBAR_HIDE_LABELS);
102 this->updated |= cvuiw::trackbar<int>(
"preFilterCap", frame, &(this->params.preFilterCap), 0, 100, 1,
"%1.Lf", cvui::TRACKBAR_HIDE_LABELS);
103 this->updated |= cvuiw::trackbar<int>(
"uniquenessRatio", frame, &(this->params.uniquenessRatio), 5, 20, 1,
"%1.Lf", cvui::TRACKBAR_HIDE_LABELS);
104 this->updated |= cvuiw::trackbar<int>(
"speckleWindowSize", frame, &(this->params.speckleWindowSize), 0, 200, 1,
"%1.Lf", cvui::TRACKBAR_HIDE_LABELS);
105 this->updated |= cvuiw::trackbar<int>(
"speckleRange", frame, &(this->params.speckleRange), 1, 16, 1,
"%1.Lf", cvui::TRACKBAR_HIDE_LABELS);
106 this->updated |= cvuiw::trackbar<double>(
"sigmaColorBLF", frame, &(this->params.sigmaColorBLF), 1.0, 30.0, 1,
"%.1Lf", cvui::TRACKBAR_HIDE_LABELS);
107 this->updated |= cvuiw::trackbar<double>(
"sigmaSpaceBLF", frame, &(this->params.sigmaSpaceBLF), 1.0, 30.0, 1,
"%.1Lf", cvui::TRACKBAR_HIDE_LABELS);
108 this->updated |= cvuiw::trackbar<double>(
"WLS lambda", frame, &(this->params.wls_lambda), 500.0, 30000.0, 1,
"%1.Lf", cvui::TRACKBAR_HIDE_LABELS | cvui::TRACKBAR_DISCRETE, 500.0);
109 this->updated |= cvuiw::trackbar<double>(
"WLS sigma", frame, &(this->params.wls_sigma), 0.1, 10.0, 1,
"%.1Lf", cvui::TRACKBAR_HIDE_LABELS);
113 this->updated |= cvuiw::radioButtons(frame,
"Num. of Disparities:", {
"32",
"64",
"96",
"128"}, {20, 65, 110, 155}, this->num_disparities_id);
114 this->updated |= cvuiw::radioButtons(frame,
"Stereo Matching Alg.:", {
"SGBM",
"SGBM_CUDA",
"LibElas"}, {20, 90, 190}, this->stereo_matching_id);
115 this->updated |= cvuiw::radioButtons(frame,
"Bilateral Filtering:", {
"No BLF",
"Original BLF",
"CUDA BLF"}, {20, 90, 190}, this->BLFfiltering_id);
116 this->updated |= cvuiw::radioButtons(frame,
"Weigthed LS Filtering:", {
"No WLS",
"WLS",
"WLS w/ lr cons."}, {20, 100, 155}, this->WLSfiltering_id);
120 this->recalibrate = cvuiw::button(frame,
"&Recalibrate", 10, 0);
121 this->updated |= this->recalibrate;
125 this->save_calibration = cvuiw::button(frame,
"&Save Calibration", 130, 0);
126 this->updated |= this->save_calibration;
130 if(cvuiw::button(frame,
"&Quit", 282, 0))
133 cv::destroyWindow(WINDOW_NAME);
139 this->load_parameters = cvuiw::button(frame,
"&Default Param.", 10, 1);
140 this->updated |= this->load_parameters;
144 this->save_parameters = cvuiw::button(frame,
"Save &Parameters", 155, 1);
145 this->updated |= this->save_parameters;
149 this->num_disparities_id = cvuiw::getRadioIndex(0);
150 this->stereo_matching_id = cvuiw::getRadioIndex(1);
151 this->BLFfiltering_id = cvuiw::getRadioIndex(2);
152 this->WLSfiltering_id = cvuiw::getRadioIndex(3);
156 this->convertIDToEnum();
164 cv::imshow(WINDOW_NAME, frame);
170 void GUI::convertIDToEnum()
172 switch(this->stereo_matching_id)
175 this->params.stereo_matching = SM_MATCHING_ALG::SGBM_OPENCV;
178 this->params.stereo_matching = SM_MATCHING_ALG::SGBM_CUDA;
181 this->params.stereo_matching = SM_MATCHING_ALG::LIBELAS;
185 switch(this->BLFfiltering_id)
188 this->params.BLFfiltering = SM_BLF_FILTER::BLF_DISABLED;
191 this->params.BLFfiltering = SM_BLF_FILTER::BLF_ORIGINAL;
194 this->params.BLFfiltering = SM_BLF_FILTER::BLF_CUDA;
198 switch(this->WLSfiltering_id)
201 this->params.WLSfiltering = SM_WLS_FILTER::WLS_DISABLED;
204 this->params.WLSfiltering = SM_WLS_FILTER::WLS_ENABLED;
207 this->params.WLSfiltering = SM_WLS_FILTER::WLS_LRCHECK;
211 this->params.numberOfDisparities = 32 * (this->num_disparities_id+1);
215 void GUI::convertEnumToID()
217 switch(this->params.stereo_matching)
219 case SM_MATCHING_ALG::SGBM_OPENCV:
220 this->stereo_matching_id = 0;
222 case SM_MATCHING_ALG::SGBM_CUDA:
223 this->stereo_matching_id = 1;
225 case SM_MATCHING_ALG::LIBELAS:
226 this->stereo_matching_id = 2;
231 switch(this->params.BLFfiltering)
233 case SM_BLF_FILTER::BLF_DISABLED:
234 this->BLFfiltering_id = 0;
236 case SM_BLF_FILTER::BLF_ORIGINAL:
237 this->BLFfiltering_id = 1;
239 case SM_BLF_FILTER::BLF_CUDA:
240 this->BLFfiltering_id = 2;
245 switch(this->params.WLSfiltering)
247 case SM_WLS_FILTER::WLS_DISABLED:
248 this->WLSfiltering_id = 0;
250 case SM_WLS_FILTER::WLS_ENABLED:
251 this->WLSfiltering_id = 1;
253 case SM_WLS_FILTER::WLS_LRCHECK:
254 this->WLSfiltering_id = 2;
259 this->num_disparities_id = (this->params.numberOfDisparities/32)-1;
263 void GUI::getParameters(
int& minDisparity,
int& numberOfDisparities,
int& SADWindowSize,
264 int& disp12MaxDiff,
int& preFilterCap,
int& uniquenessRatio,
265 int& speckleWindowSize,
int& speckleRange,
double& sigmaColorBLF,
266 double& sigmaSpaceBLF,
double& wls_lambda,
double& wls_sigma,
267 SM_BLF_FILTER& BLFfiltering, SM_WLS_FILTER& WLSfiltering,
268 SM_MATCHING_ALG& stereo_matching)
270 minDisparity = this->params.minDisparity;
271 numberOfDisparities = this->params.numberOfDisparities;
272 SADWindowSize = this->params.SADWindowSize;
273 disp12MaxDiff = this->params.disp12MaxDiff;
274 preFilterCap = this->params.preFilterCap;
275 uniquenessRatio = this->params.uniquenessRatio;
276 speckleWindowSize = this->params.speckleWindowSize;
277 speckleRange = this->params.speckleRange;
278 sigmaColorBLF = this->params.sigmaColorBLF;
279 sigmaSpaceBLF = this->params.sigmaSpaceBLF;
280 wls_lambda = this->params.wls_lambda;
281 wls_sigma = this->params.wls_sigma;
282 BLFfiltering = this->params.BLFfiltering;
283 WLSfiltering = this->params.WLSfiltering;
284 stereo_matching = this->params.stereo_matching;
288 void GUI::setParameters(
int& minDisparity,
int& numberOfDisparities,
int& SADWindowSize,
289 int& disp12MaxDiff,
int& preFilterCap,
int& uniquenessRatio,
290 int& speckleWindowSize,
int& speckleRange,
double& sigmaColorBLF,
291 double& sigmaSpaceBLF,
double& wls_lambda,
double& wls_sigma,
292 SM_BLF_FILTER& BLFfiltering, SM_WLS_FILTER& WLSfiltering,
293 SM_MATCHING_ALG& stereo_matching)
295 this->params.minDisparity = minDisparity;
296 this->params.numberOfDisparities = numberOfDisparities;
297 this->params.SADWindowSize = SADWindowSize;
298 this->params.disp12MaxDiff = disp12MaxDiff;
299 this->params.preFilterCap = preFilterCap;
300 this->params.uniquenessRatio = uniquenessRatio;
301 this->params.speckleWindowSize = speckleWindowSize;
302 this->params.speckleRange = speckleRange;
303 this->params.sigmaColorBLF = sigmaColorBLF;
304 this->params.sigmaSpaceBLF = sigmaSpaceBLF;
305 this->params.wls_lambda = wls_lambda;
306 this->params.wls_sigma = wls_sigma;
307 this->params.BLFfiltering = BLFfiltering;
308 this->params.WLSfiltering = WLSfiltering;
309 this->params.stereo_matching = stereo_matching;
325 bool GUI::toRecalibrate()
327 return this->recalibrate;
331 bool GUI::toSaveCalibration()
333 return this->save_calibration;
337 bool GUI::toLoadParameters()
339 return this->load_parameters;
343 bool GUI::toSaveParameters()
345 return this->save_parameters;
349 void GUI::resetState()
352 this->updated =
false;
353 this->recalibrate =
false;
354 this->save_calibration =
false;
355 this->load_parameters =
false;
356 this->save_parameters =
false;
360 int GUI::getRefineTh()
368 return refine_th > 0;