RSLightFields
Disparity map estimator from 3D light fields
rslf_depth_computation.hpp
Go to the documentation of this file.
1 #ifndef _RSLF_DEPTH_COMPUTATION
2 #define _RSLF_DEPTH_COMPUTATION
3 
4 #include <rslf_plot.hpp>
6 
7 
14 namespace rslf
15 {
16 
17 /*
18  * *****************************************************************
19  * Depth1DComputer
20  * *****************************************************************
21  */
22 
26 template<typename DataType>
28 {
29 public:
31  (
32  const Mat& epi,
33  float dmin,
34  float dmax,
35  int dim_d,
36  int s_hat = -1, // default s_hat will be s_max / 2,
37  float epi_scale_factor = -1,
39  );
40 
44  void run();
45 
49  Mat get_coloured_epi(int a_cv_colormap = cv::COLORMAP_JET);
50 
51 private:
52  Mat m_epi;
53 
54  int m_dim_d;
55  Mat m_dmin_u;
56  Mat m_dmax_u;
57 
58  Mat m_edge_confidence_u;
59  Mat m_edge_confidence_mask_u;
60  Mat m_disp_confidence_u;
61  Mat m_rbar_u;
62  Mat m_best_depth_u;
63 
67  int m_s_hat;
68 
69  const Depth1DParameters<DataType>& m_parameters;
70 };
71 
72 
77 
82 
83 
84 /*
85  * *****************************************************************
86  * Depth1DComputer_pile
87  * *****************************************************************
88  */
89 
93 template<typename DataType>
95 {
96 public:
98  (
99  const Vec<Mat>& epis,
100  float dmin,
101  float dmax,
102  int dim_d,
103  int s_hat = -1, // default s_hat will be s_max / 2,
104  float epi_scale_factor = -1,
106  );
107 
111  void run();
112 
116  Mat get_coloured_epi(int a_v = -1, int a_cv_colormap = cv::COLORMAP_JET);
117 
121  Mat get_disparity_map(int a_cv_colormap = cv::COLORMAP_JET);
122  int get_s_hat() { return m_s_hat; }
123 
124 private:
125  Vec<Mat> m_epis;
126 
127  int m_dim_d;
128  Mat m_dmin_v_u;
129  Mat m_dmax_v_u;
130 
131  Mat m_edge_confidence_v_u;
132  Mat m_edge_confidence_mask_v_u;
133  Mat m_disp_confidence_v_u;
134  Mat m_rbar_v_u;
135  Mat m_best_depth_v_u;
136 
140  int m_s_hat;
141 
142  const Depth1DParameters<DataType>& m_parameters;
143 };
144 
145 
150 
155 
156 
157 /*
158  * *****************************************************************
159  * Depth2DComputer
160  * *****************************************************************
161  */
162 
166 template<typename DataType>
168 {
169 public:
171  (
172  const Vec<Mat>& epis,
173  float dmin,
174  float dmax,
175  int dim_d,
176  float epi_scale_factor = -1,
178  bool verbose = true
179  );
180 
184  void run();
185 
189  Mat get_coloured_epi(int a_v = -1, int a_cv_colormap = cv::COLORMAP_JET);
190 
194  Mat get_disparity_map(int a_s = -1, int a_cv_colormap = cv::COLORMAP_JET);
195 
196  const Vec<Mat>& get_depths_s_v_u()
197  {
198  return m_best_depth_s_v_u;
199  }
200 
201  const Vec<Mat>& get_valid_depths_mask_s_v_u()
202  {
203  Vec<Mat>* validity_maps = new Vec<Mat>();
204  for (int s=0; s<m_edge_confidence_s_v_u.size(); s++)
205  {
206  if (!m_accept_all)
207  {
208 #ifdef _USE_DISP_CONFIDENCE_SCORE
209  validity_maps->push_back(m_disp_confidence_s_v_u[s] > m_parameters.par_disp_score_threshold);
210 #else
211  validity_maps->push_back(m_edge_confidence_s_v_u[s] > m_parameters.par_edge_score_threshold);
212 #endif
213  }
214  else
215  {
216  validity_maps->push_back(m_edge_confidence_s_v_u[s] > -1);
217  }
218  }
219  return *validity_maps;
220  }
221 
222  const Vec<Mat>& get_epis()
223  {
224  return m_epis;
225  }
226 
227  Vec<Mat>& edit_dmin()
228  {
229  return m_dmin_s_v_u;
230  }
231 
232  Vec<Mat>& edit_dmax()
233  {
234  return m_dmax_s_v_u;
235  }
236 
237  void set_accept_all(bool b)
238  {
239  m_accept_all = b;
240  }
241 
242 private:
243  Vec<Mat> m_epis;
244 
245  int m_dim_d;
246  Vec<Mat> m_dmin_s_v_u;
247  Vec<Mat> m_dmax_s_v_u;
248 
249  Vec<Mat> m_edge_confidence_s_v_u;
250  Vec<Mat> m_edge_confidence_mask_s_v_u;
251  Vec<Mat> m_disp_confidence_s_v_u;
252  Vec<Mat> m_rbar_s_v_u;
253  Vec<Mat> m_best_depth_s_v_u;
254 
255  bool m_accept_all = false;
256 
257  const Depth1DParameters<DataType>& m_parameters;
258 
259  bool m_verbose;
260 };
261 
262 
267 
272 
273 
274 
277 
278 
279 
280 /*
281  * *****************************************************************
282  * IMPLEMENTATION
283  * Depth1DComputer
284  * *****************************************************************
285  */
286 
287 template<typename DataType>
289 (
290  const Mat& epi,
291  float dmin,
292  float dmax,
293  int dim_d,
294  int s_hat,
295  float epi_scale_factor,
296  const Depth1DParameters<DataType>& parameters
297 ) :
298  m_parameters(parameters)
299 {
300  // If the input epi is a uchar, scale uchar to 1.0
301  if (epi.depth() == CV_8U)
302  {
303  epi.convertTo(m_epi, CV_32F, 1.0/255.0);
304  }
305  else
306  {
307  // If provided scale factor is invalid, scale from max in all channels
308  if (epi_scale_factor < 0)
309  {
310  Vec<Mat> channels;
311  cv::split(epi, channels);
312  for (int c=0; c<channels.size(); c++)
313  {
314  double min, max;
315  cv::minMaxLoc(epi, &min, &max);
316  epi_scale_factor = std::max((float)max, epi_scale_factor);
317  }
318  }
319  epi.convertTo(m_epi, CV_32F, 1.0/epi_scale_factor);
320  }
321 
322 
323  // Dimensions
324  int dim_s = m_epi.rows;
325  int dim_u = m_epi.cols;
326 
327  // d's
328  m_dim_d = dim_d;
329  m_dmin_u = Mat(1, dim_u, CV_32FC1, cv::Scalar(dmin));
330  m_dmax_u = Mat(1, dim_u, CV_32FC1, cv::Scalar(dmax));
331 
332  // s_hat
333  if (s_hat < 0 || s_hat > dim_s - 1)
334  {
335  // Default: s_hat is the center horizontal line index of the epi
336  m_s_hat = (int) std::floor((0.0 + dim_s) / 2);
337  }
338  else
339  {
340  m_s_hat = s_hat;
341  }
342 
343  // Edge confidence
344  m_edge_confidence_u = cv::Mat::zeros(1, m_epi.cols, CV_32FC1);
345 
346  // Disparity confidence
347  m_disp_confidence_u = cv::Mat::zeros(1, m_epi.cols, CV_32FC1);
348 
349  // Scores and best scores & depths
350  m_best_depth_u = cv::Mat::zeros(1, dim_u, CV_32FC1);
351 
352  // rbar
353  m_rbar_u = cv::Mat::zeros(1, dim_u, m_epi.type());
354 }
355 
356 template<typename DataType>
358 {
359  // Dimension
360  int dim_s = m_epi.rows;
361  int dim_u = m_epi.cols;
362 
363  std::cout << "Max num of threads: " << omp_get_max_threads() << std::endl;
364  //~ omp_set_nested(1);
365 
366  // Empty mask -> no masked point
367  Mat mask;
368 
369  // Buffer
371  dim_s,
372  m_dim_d,
373  dim_u,
374  m_epi.type(),
375  m_parameters
376  );
377 
378  compute_1D_edge_confidence<DataType>(
379  m_epi,
380  m_s_hat,
381  m_edge_confidence_u,
382  m_edge_confidence_mask_u,
383  m_parameters,
384  buffer
385  );
386 
387  compute_1D_depth_epi<DataType>(
388  m_epi,
389  m_dmin_u,
390  m_dmax_u,
391  m_dim_d,
392  m_s_hat,
393  m_edge_confidence_u,
394  m_edge_confidence_mask_u,
395  m_disp_confidence_u,
396  m_best_depth_u,
397  m_rbar_u,
398  m_parameters,
399  buffer,
400  mask
401  );
402 }
403 
404 template<typename DataType>
406 
407  // Dimensions
408  int dim_s = m_epi.rows;
409  int dim_u = m_epi.cols;
410 
411  // Build a matrix of occlusions: each element is the max observed depth
412  Mat occlusion_map(dim_s, dim_u, CV_32FC1, -std::numeric_limits<float>::infinity());
413 
414  // Build a correspondance depth->color: scale to uchar and map to 3-channel matrix
415  Mat coloured_depth = rslf::copy_and_scale_uchar(m_best_depth_u);
416  cv::applyColorMap(coloured_depth.clone(), coloured_depth, a_cv_colormap);
417 
418  // Construct an EPI with overlay
419  Mat coloured_epi = cv::Mat::zeros(m_epi.rows, m_epi.cols, CV_8UC3);
420 
421  // For each column of the s_hat row, draw the line, taking overlays into account
422  for (int u=0; u<dim_u; u++)
423  {
424  // Only paint if the confidence threshold was high enough
425  if (m_edge_confidence_mask_u.at<uchar>(u))
426  {
427  float current_depth_value = m_best_depth_u.at<float>(u);
428  for (int s=0; s<dim_s; s++)
429  {
430 
431  int requested_index = u + (int)std::round(m_best_depth_u.at<float>(u) * (m_s_hat - s));
432  if
433  (
434  requested_index > 0 &&
435  requested_index < dim_u &&
436  occlusion_map.at<float>(s, requested_index) < current_depth_value // only draw if the current depth is higher
437  )
438  {
439  coloured_epi.at<cv::Vec3b>(s, requested_index) = coloured_depth.at<cv::Vec3b>(u);
440  occlusion_map.at<float>(s, requested_index) = current_depth_value;
441  }
442  }
443  }
444  }
445 
446  return coloured_epi;
447 }
448 
449 /*
450  * *****************************************************************
451  * IMPLEMENTATION
452  * Depth1DComputer_pile
453  * *****************************************************************
454  */
455 
456 template<typename DataType>
458 (
459  const Vec<Mat>& epis,
460  float dmin,
461  float dmax,
462  int dim_d,
463  int s_hat,
464  float epi_scale_factor,
465  const Depth1DParameters<DataType>& parameters
466 ) :
467  m_parameters(parameters)
468 {
469  m_epis = Vec<Mat>(epis.size(), Mat(epis[0].rows, epis[0].cols, epis[0].type()));
470 
471  // Look for the max and min values across all epis
472  // If provided scale factor is invalid, scale from max in all channels
473  if (epis[0].depth() != CV_8U && epi_scale_factor < 0)
474  {
475 #pragma omp parallel for
476  for (int v=0; v<epis.size(); v++)
477  {
478  Mat epi = epis[v];
479  Vec<Mat> channels;
480  cv::split(epi, channels);
481  for (int c=0; c<channels.size(); c++)
482  {
483  double min, max;
484  cv::minMaxLoc(epi, &min, &max);
485 #pragma omp critical
486 {
487  epi_scale_factor = std::max((float)max, epi_scale_factor);
488 }
489  }
490  }
491  }
492 
493  // If the input epi is a uchar, scale uchar to 1.0
494 #pragma omp parallel for
495  for (int v=0; v<epis.size(); v++)
496  {
497  Mat epi = epis[v];
498  Mat epi2;
499  if (epi.depth() == CV_8U)
500  {
501  epi.convertTo(epi2, CV_32F, 1.0/255.0);
502  }
503  else
504  {
505  epi.convertTo(epi2, CV_32F, 1.0/epi_scale_factor);
506  }
507  m_epis[v] = epi2;
508  }
509 
510  // Dimensions
511  int dim_s = m_epis[0].rows;
512  int dim_u = m_epis[0].cols;
513  int dim_v = m_epis.size();
514 
515  // d's
516  m_dim_d = dim_d;
517  m_dmin_v_u = Mat(dim_v, dim_u, CV_32FC1, cv::Scalar(dmin));
518  m_dmax_v_u = Mat(dim_v, dim_u, CV_32FC1, cv::Scalar(dmax));
519 
520  // s_hat
521  if (s_hat < 0 || s_hat > dim_s - 1)
522  {
523  // Default: s_hat is the center horizontal line index of the epi
524  m_s_hat = (int) std::floor((0.0 + dim_s) / 2);
525  }
526  else
527  {
528  m_s_hat = s_hat;
529  }
530 
531  // Edge confidence
532  m_edge_confidence_v_u = Mat(dim_v, dim_u, CV_32FC1);
533 
534  // Disparity confidence
535  m_disp_confidence_v_u = Mat(dim_v, dim_u, CV_32FC1);
536 
537  // Scores and best scores & depths
538  m_best_depth_v_u = cv::Mat::zeros(dim_v, dim_u, CV_32FC1);
539 
540  // rbar
541  m_rbar_v_u = cv::Mat::zeros(dim_v, dim_u, m_epis[0].type());
542 }
543 
544 template<typename DataType>
546 {
547  // No mask
548  Mat mask_v_u;
549 
550  // Dimension
551  int dim_s = m_epis[0].rows;
552  int dim_v = m_epis.size();
553  int dim_u = m_epis[0].cols;
554 
555  int thr_max = omp_get_max_threads();
556  std::cout << "Max num of threads: " << thr_max << std::endl;
557 
558  Vec<BufferDepth1D<DataType>*> buffers;
559  for (int t=0; t<thr_max; t++)
560  buffers.push_back(new BufferDepth1D<DataType>(
561  dim_s,
562  m_dim_d,
563  dim_u,
564  m_epis[0].type(),
565  m_parameters
566  )
567  );
568 
569  compute_1D_edge_confidence_pile<DataType>(
570  m_epis,
571  m_s_hat,
572  m_edge_confidence_v_u,
573  m_edge_confidence_mask_v_u,
574  m_parameters,
575  buffers
576  );
577 
578  compute_1D_depth_epi_pile<DataType>(
579  m_epis,
580  m_dmin_v_u,
581  m_dmax_v_u,
582  m_dim_d,
583  m_s_hat,
584  m_edge_confidence_v_u,
585  m_edge_confidence_mask_v_u,
586  m_disp_confidence_v_u,
587  m_best_depth_v_u,
588  m_rbar_v_u,
589  m_parameters,
590  buffers,
591  mask_v_u
592  );
593 
594  for (int t=0; t<thr_max; t++)
595  delete buffers[t];
596 }
597 
598 template<typename DataType>
600 
601  // Dimensions
602  int dim_s = m_epis[0].rows;
603  int dim_u = m_epis[0].cols;
604  int dim_v = m_epis.size();
605 
606  if (a_v < 0)
607  a_v = (int)std::floor(dim_v/2.0);
608 
609  Mat epi = m_epis[a_v];
610  Mat best_depth_u = m_best_depth_v_u.row(a_v);
611  Mat edge_confidence_u = m_edge_confidence_v_u.row(a_v);
612  Mat edge_confidence_mask_u = m_edge_confidence_mask_v_u.row(a_v);
613 
614  // Build a matrix of occlusions: each element is the max observed depth
615  Mat occlusion_map(dim_s, dim_u, CV_32FC1, -std::numeric_limits<float>::infinity());
616 
617  // Build a correspondance depth->color: scale to uchar and map to 3-channel matrix
618  Mat coloured_depth = rslf::copy_and_scale_uchar(best_depth_u);
619  cv::applyColorMap(coloured_depth.clone(), coloured_depth, a_cv_colormap);
620 
621  // Construct an EPI with overlay
622  Mat coloured_epi = cv::Mat::zeros(epi.rows, epi.cols, CV_8UC3);
623 
624  // For each column of the s_hat row, draw the line, taking overlays into account
625 #pragma omp parallel for
626  for (int u=0; u<dim_u; u++)
627  {
628  // Only paint if the confidence threshold was high enough
629  if (edge_confidence_mask_u.at<uchar>(u))
630  {
631  float current_depth_value = best_depth_u.at<float>(u);
632  for (int s=0; s<dim_s; s++)
633  {
634 
635  int requested_index = u + (int)std::round(best_depth_u.at<float>(u) * (m_s_hat - s));
636  if
637  (
638  requested_index > -1 &&
639  requested_index < dim_u &&
640  occlusion_map.at<float>(s, requested_index) < current_depth_value // only draw if the current depth is higher
641  )
642  {
643  coloured_epi.at<cv::Vec3b>(s, requested_index) = coloured_depth.at<cv::Vec3b>(u);
644  occlusion_map.at<float>(s, requested_index) = current_depth_value;
645  }
646  }
647  }
648  }
649 
650  return coloured_epi;
651 }
652 
653 template<typename DataType>
655 {
656  // Dimensions
657  int dim_s = m_epis[0].rows;
658  int dim_u = m_epis[0].cols;
659  int dim_v = m_epis.size();
660 
661  Mat disparity_map;
662 
663  disparity_map = rslf::copy_and_scale_uchar(m_best_depth_v_u);
664  cv::applyColorMap(disparity_map, disparity_map, a_cv_colormap);
665 
666  // Threshold scores
667  Mat disparity_map_with_scores = cv::Mat::zeros(dim_v, dim_u, disparity_map.type());
668 
669  cv::add(disparity_map, disparity_map_with_scores, disparity_map_with_scores, m_edge_confidence_mask_v_u);
670 
671  return disparity_map_with_scores;
672 }
673 
674 
675 /*
676  * *****************************************************************
677  * IMPLEMENTATION
678  * Depth2DComputer
679  * *****************************************************************
680  */
681 
682 template<typename DataType>
684 (
685  const Vec<Mat>& epis,
686  float dmin,
687  float dmax,
688  int dim_d,
689  float epi_scale_factor,
690  const Depth1DParameters<DataType>& parameters,
691  bool verbose
692 ) :
693  m_parameters(parameters),
694  m_verbose(verbose)
695 {
696  m_epis = Vec<Mat>(epis.size(), Mat(epis[0].rows, epis[0].cols, epis[0].type()));
697 
698  // Look for the max and min values across all epis
699  // If provided scale factor is invalid, scale from max in all channels
700  if (epis[0].depth() != CV_8U && epi_scale_factor < 0)
701  {
702 #pragma omp parallel for
703  for (int v=0; v<epis.size(); v++)
704  {
705  Mat epi = epis[v];
706  Vec<Mat> channels;
707  cv::split(epi, channels);
708  for (int c=0; c<channels.size(); c++)
709  {
710  double min, max;
711  cv::minMaxLoc(epi, &min, &max);
712 #pragma omp critical
713 {
714  epi_scale_factor = std::max((float)max, epi_scale_factor);
715 }
716  }
717  }
718  }
719 
720  // If the input epi is a uchar, scale uchar to 1.0
721 #pragma omp parallel for
722  for (int v=0; v<epis.size(); v++)
723  {
724  Mat epi = epis[v];
725  Mat epi2;
726  if (epi.depth() == CV_8U)
727  {
728  epi.convertTo(epi2, CV_32F, 1.0/255.0);
729  }
730  else
731  {
732  epi.convertTo(epi2, CV_32F, 1.0/epi_scale_factor);
733  }
734  m_epis[v] = epi2;
735  }
736 
737  // Dimensions
738  int dim_s = m_epis[0].rows;
739  int dim_u = m_epis[0].cols;
740  int dim_v = m_epis.size();
741 
742  // d's
743  m_dim_d = dim_d;
744  for (int s=0; s<dim_s; s++)
745  {
746  m_dmin_s_v_u.push_back(Mat(dim_v, dim_u, CV_32FC1, cv::Scalar(dmin)));
747  m_dmax_s_v_u.push_back(Mat(dim_v, dim_u, CV_32FC1, cv::Scalar(dmax)));
748  }
749 
750  m_edge_confidence_s_v_u = Vec<Mat>(dim_s);
751  m_disp_confidence_s_v_u = Vec<Mat>(dim_s);
752  m_best_depth_s_v_u = Vec<Mat>(dim_s);
753  m_rbar_s_v_u = Vec<Mat>(dim_s);
754 
755  for (int s=0; s<dim_s; s++)
756  {
757  // Edge confidence
758  m_edge_confidence_s_v_u[s] = Mat(dim_v, dim_u, CV_32FC1);
759 
760  // Disparity confidence
761  m_disp_confidence_s_v_u[s] = Mat(dim_v, dim_u, CV_32FC1);
762 
763  // Scores and best scores & depths
764  m_best_depth_s_v_u[s] = cv::Mat::zeros(dim_v, dim_u, CV_32FC1);
765 
766  // rbar
767  m_rbar_s_v_u[s] = cv::Mat::zeros(dim_v, dim_u, m_epis[0].type());
768  }
769 }
770 
771 template<typename DataType>
773 {
774  // Dimension
775  int dim_s = m_epis[0].rows;
776  int dim_v = m_epis.size();
777  int dim_u = m_epis[0].cols;
778 
779  int thr_max = omp_get_max_threads();
780 
781  if (m_verbose)
782  {
783  std::cout << "Max num of threads: " << thr_max << std::endl;
784  std::cout << "Slope factor: " << m_parameters.par_slope_factor << std::endl;
785  }
786 
787  Vec<BufferDepth1D<DataType>*> m_buffers_;
788  for (int t=0; t<thr_max; t++)
789  m_buffers_.push_back(new BufferDepth1D<DataType>(
790  dim_s,
791  m_dim_d,
792  dim_u,
793  m_epis[0].type(),
794  m_parameters
795  )
796  );
797 
798  compute_2D_edge_confidence<DataType>(
799  m_epis,
800  m_edge_confidence_s_v_u,
801  m_edge_confidence_mask_s_v_u,
802  m_parameters,
803  m_buffers_
804  );
805 
806  compute_2D_depth_epi<DataType>(
807  m_epis,
808  m_dmin_s_v_u,
809  m_dmax_s_v_u,
810  m_dim_d,
811  m_edge_confidence_s_v_u,
812  m_edge_confidence_mask_s_v_u,
813  m_disp_confidence_s_v_u,
814  m_best_depth_s_v_u,
815  m_rbar_s_v_u,
816  m_parameters,
817  m_buffers_,
818  m_verbose
819  );
820 
821  for (int t=0; t<thr_max; t++)
822  delete m_buffers_[t];
823 }
824 
825 template<typename DataType>
827 
828  // Dimensions
829  int dim_s = m_epis[0].rows;
830  int dim_u = m_epis[0].cols;
831  int dim_v = m_epis.size();
832 
833  if (a_v < 0)
834  a_v = (int)std::floor(dim_v/2.0);
835 
836  // Construct an EPI with overlay
837  Mat best_depth_s_u = cv::Mat::zeros(dim_s, dim_u, CV_32FC1);
838 
839  // For each column of the s_hat row, get the corresponding line
840 #pragma omp parallel for
841  for (int s=0; s<dim_s; s++)
842  {
843  m_best_depth_s_v_u[s].row(a_v).copyTo(best_depth_s_u.row(s));
844  }
845 
846  // Build a correspondance depth->color: scale to uchar and map to 3-channel matrix
847  Mat coloured_depth = rslf::copy_and_scale_uchar(best_depth_s_u);
848  cv::applyColorMap(coloured_depth.clone(), coloured_depth, a_cv_colormap);
849 
850  Mat coloured_epi = cv::Mat::zeros(dim_s, dim_u, CV_8UC3);
851  for (int s=0; s<dim_s; s++)
852  {
853  Mat edge_confidence_mask_u = m_edge_confidence_mask_s_v_u[s].row(a_v);
854  Mat disp_confidence_mask_u = m_disp_confidence_s_v_u[s].row(a_v) > m_parameters.par_disp_score_threshold;
855  for (int u=0; u<dim_u; u++)
856  {
857  // Only paint if the confidence threshold was high enough
858 #ifdef _USE_DISP_CONFIDENCE_SCORE
859  if (disp_confidence_mask_u.at<uchar>(u))
860 #else
861  if (edge_confidence_mask_u.at<uchar>(u))
862 #endif
863  {
864  coloured_epi.at<cv::Vec3b>(s, u) = coloured_depth.at<cv::Vec3b>(s, u);
865  }
866  }
867  }
868 
869  return coloured_epi;
870 }
871 
872 template<typename DataType>
874 {
875  // Dimensions
876  int dim_s = m_epis[0].rows;
877  int dim_u = m_epis[0].cols;
878  int dim_v = m_epis.size();
879 
880  if (a_s < 0)
881  a_s = (int)std::floor(dim_s/2.0);
882 
883  Mat disparity_map;
884  Mat best_depth_v_u = m_best_depth_s_v_u[a_s];
885  Mat edge_confidence_mask_v_u = m_edge_confidence_mask_s_v_u[a_s];
886  Mat disp_confidence_v_u = m_disp_confidence_s_v_u[a_s];
887  Mat disp_confidence_mask_v_u = disp_confidence_v_u > m_parameters.par_disp_score_threshold;
888 
889  disparity_map = rslf::copy_and_scale_uchar(best_depth_v_u);
890  cv::applyColorMap(disparity_map, disparity_map, a_cv_colormap);
891 
892  // Threshold scores
893  Mat disparity_map_with_scores = cv::Mat::zeros(dim_v, dim_u, disparity_map.type());
894 
895 #ifdef _USE_DISP_CONFIDENCE_SCORE
896  cv::add(disparity_map, disparity_map_with_scores, disparity_map_with_scores, disp_confidence_mask_v_u);
897 #else
898  cv::add(disparity_map, disparity_map_with_scores, disparity_map_with_scores, edge_confidence_mask_v_u);
899 #endif
900 
901  return disparity_map_with_scores;
902 }
903 
904 }
905 
906 
907 #endif
Impelment a structure containing all the algorithm parameters.
Definition: rslf_depth_computation_core.hpp:65
Implement a buffer containing re-usable temporary variables in order to avoid multiple unnecessary al...
Definition: rslf_depth_computation_core.hpp:145
std::vector< T > Vec
RSLF Vector class (std::vector)
Definition: rslf_types.hpp:32
Mat get_coloured_epi(int a_v=-1, int a_cv_colormap=cv::COLORMAP_JET)
Gets an EPI with colors corresponding to the computed slopes.
Definition: rslf_depth_computation.hpp:599
void run()
Runs the algorithm.
Definition: rslf_depth_computation.hpp:772
Definition: rslf_depth_computation.hpp:14
Implement functions to scale and plot matrices.
Definition: rslf_depth_computation.hpp:94
Mat copy_and_scale_uchar(Mat img)
Build a copy of the matrix scaled to uchar (0..255).
Definition: rslf_plot.cpp:41
Implement low-level depth computation functions.
void run()
Runs the algorithm.
Definition: rslf_depth_computation.hpp:357
Mat get_coloured_epi(int a_cv_colormap=cv::COLORMAP_JET)
Gets an EPI with colors corresponding to the computed slopes.
Definition: rslf_depth_computation.hpp:405
cv::Mat Mat
RSLF Matrix class (cv::Mat)
Definition: rslf_types.hpp:26
Mat get_coloured_epi(int a_v=-1, int a_cv_colormap=cv::COLORMAP_JET)
Gets an EPI with colors corresponding to the computed slopes.
Definition: rslf_depth_computation.hpp:826
Mat get_disparity_map(int a_cv_colormap=cv::COLORMAP_JET)
Gets a disparity map with colors corresponding to the computed disparity.
Definition: rslf_depth_computation.hpp:654
void run()
Runs the algorithm.
Definition: rslf_depth_computation.hpp:545
Mat get_disparity_map(int a_s=-1, int a_cv_colormap=cv::COLORMAP_JET)
Gets a disparity map with colors corresponding to the computed disparity.
Definition: rslf_depth_computation.hpp:873
Definition: rslf_depth_computation.hpp:167
Template class with depth computation using 1d slices of the EPI.
Definition: rslf_depth_computation.hpp:27