Skip to content
Snippets Groups Projects
Commit e14a409d authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

SGM: cost_min_all for uncertainty estimation

parent 7593c8d4
No related branches found
No related tags found
No related merge requests found
Pipeline #24397 failed
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define _FTL_LIBSTEREO_AGGREGATIONS_STANDARD_HPP_ #define _FTL_LIBSTEREO_AGGREGATIONS_STANDARD_HPP_
#include "../dsi.hpp" #include "../dsi.hpp"
#include "../array2d.hpp"
namespace ftl { namespace ftl {
namespace stereo { namespace stereo {
...@@ -14,6 +15,8 @@ struct StandardSGM { ...@@ -14,6 +15,8 @@ struct StandardSGM {
// Provided externally // Provided externally
const DSIIN in; const DSIIN in;
typename Array2D<costtype_t>::Data min_cost_all;
const int P1; const int P1;
const int P2; const int P2;
...@@ -102,9 +105,12 @@ struct StandardSGM { ...@@ -102,9 +105,12 @@ struct StandardSGM {
// Each thread then obtains thread global minimum // Each thread then obtains thread global minimum
#ifdef __CUDA_ARCH__ #ifdef __CUDA_ARCH__
min_cost = warpMin(min_cost); min_cost = warpMin(min_cost);
#else
// add assert
#endif #endif
data.previous_cost_min = min_cost; data.previous_cost_min = min_cost;
min_cost_all(pixel.y,pixel.x) += min_cost; // atomic?
// Swap current and previous cost buffers // Swap current and previous cost buffers
costtype_t *tmp_ptr = const_cast<costtype_t *>(data.previous); costtype_t *tmp_ptr = const_cast<costtype_t *>(data.previous);
......
...@@ -47,9 +47,6 @@ using cv::Mat; ...@@ -47,9 +47,6 @@ using cv::Mat;
using cv::Size; using cv::Size;
using ftl::stereo::aggregations::StandardSGM; using ftl::stereo::aggregations::StandardSGM;
static int ct_windows_w = 9;
static int ct_windows_h = 7;
struct StereoADCensusSgm::Impl { struct StereoADCensusSgm::Impl {
DisparitySpaceImage<unsigned short> dsi; DisparitySpaceImage<unsigned short> dsi;
AbsDiffBT ad_cost; AbsDiffBT ad_cost;
...@@ -108,7 +105,7 @@ void StereoADCensusSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputAr ...@@ -108,7 +105,7 @@ void StereoADCensusSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputAr
if (params.debug) { timer_print("census transform"); } if (params.debug) { timer_print("census transform"); }
// cost aggregation // cost aggregation
StandardSGM<DualCosts<AbsDiffBT,CensusMatchingCost>::DataType> func = {impl_->cost.data(), params.P1, params.P2}; StandardSGM<DualCosts<AbsDiffBT,CensusMatchingCost>::DataType> func = {impl_->cost.data(), impl_->cost_min_paths.data(), params.P1, params.P2};
auto &out = impl_->aggr(func, params.paths); auto &out = impl_->aggr(func, params.paths);
cudaSafeCall(cudaDeviceSynchronize()); cudaSafeCall(cudaDeviceSynchronize());
......
...@@ -45,9 +45,6 @@ using cv::Mat; ...@@ -45,9 +45,6 @@ using cv::Mat;
using cv::Size; using cv::Size;
using ftl::stereo::aggregations::StandardSGM; using ftl::stereo::aggregations::StandardSGM;
static int ct_windows_w = 9;
static int ct_windows_h = 7;
struct StereoADSgm::Impl { struct StereoADSgm::Impl {
DisparitySpaceImage<unsigned short> dsi; DisparitySpaceImage<unsigned short> dsi;
AbsDiffBT cost; AbsDiffBT cost;
...@@ -99,7 +96,7 @@ void StereoADSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArray di ...@@ -99,7 +96,7 @@ void StereoADSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArray di
if (params.debug) { timer_print("census transform"); } if (params.debug) { timer_print("census transform"); }
// cost aggregation // cost aggregation
StandardSGM<AbsDiffBT::DataType> func = {impl_->cost.data(), params.P1, params.P2}; StandardSGM<AbsDiffBT::DataType> func = {impl_->cost.data(), impl_->cost_min_paths.data(), params.P1, params.P2};
auto &out = impl_->aggr(func, params.paths); auto &out = impl_->aggr(func, params.paths);
cudaSafeCall(cudaDeviceSynchronize()); cudaSafeCall(cudaDeviceSynchronize());
......
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp> #include <opencv2/imgproc.hpp>
#include <opencv2/core/cuda/common.hpp> #include <opencv2/core/cuda/common.hpp>
#include <opencv2/cudaarithm.hpp>
#include "stereo.hpp" #include "stereo.hpp"
...@@ -47,15 +49,11 @@ using cv::Mat; ...@@ -47,15 +49,11 @@ using cv::Mat;
using cv::Size; using cv::Size;
using ftl::stereo::aggregations::StandardSGM; using ftl::stereo::aggregations::StandardSGM;
static int ct_windows_w = 9;
static int ct_windows_h = 7;
struct StereoCensusSgm::Impl { struct StereoCensusSgm::Impl {
//DisparitySpaceImage<unsigned short> dsi; //DisparitySpaceImage<unsigned short> dsi;
CensusMatchingCost cost; CensusMatchingCost cost;
Array2D<unsigned short> cost_min; Array2D<unsigned short> cost_min;
Array2D<unsigned short> cost_min_paths; Array2D<unsigned short> cost_min_paths;
Array2D<unsigned short> uncertainty;
Array2D<float> confidence; Array2D<float> confidence;
Array2D<float> disparity_r; Array2D<float> disparity_r;
Array2D<uchar> l; Array2D<uchar> l;
...@@ -68,7 +66,6 @@ struct StereoCensusSgm::Impl { ...@@ -68,7 +66,6 @@ struct StereoCensusSgm::Impl {
cost(width, height, min_disp, max_disp), cost(width, height, min_disp, max_disp),
cost_min(width, height), cost_min(width, height),
cost_min_paths(width, height), cost_min_paths(width, height),
uncertainty(width, height),
confidence(width, height), confidence(width, height),
disparity_r(width, height), l(width, height), r(width, height) {} disparity_r(width, height), l(width, height), r(width, height) {}
...@@ -86,9 +83,6 @@ void StereoCensusSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArra ...@@ -86,9 +83,6 @@ void StereoCensusSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArra
impl_ = new Impl(l.cols(), l.rows(), params.d_min, params.d_max); impl_ = new Impl(l.cols(), l.rows(), params.d_min, params.d_max);
} }
//impl_->dsi.clear();
impl_->uncertainty.toMat().setTo(0);
mat2gray(l, impl_->l); mat2gray(l, impl_->l);
mat2gray(r, impl_->r); mat2gray(r, impl_->r);
timer_set(); timer_set();
...@@ -100,7 +94,7 @@ void StereoCensusSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArra ...@@ -100,7 +94,7 @@ void StereoCensusSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArra
if (params.debug) { timer_print("census transform"); } if (params.debug) { timer_print("census transform"); }
// cost aggregation // cost aggregation
StandardSGM<CensusMatchingCost::DataType> func = {impl_->cost.data(), params.P1, params.P2}; StandardSGM<CensusMatchingCost::DataType> func = {impl_->cost.data(), impl_->cost_min_paths.data(), params.P1, params.P2};
auto &out = impl_->aggr(func, params.paths); auto &out = impl_->aggr(func, params.paths);
cudaSafeCall(cudaDeviceSynchronize()); cudaSafeCall(cudaDeviceSynchronize());
...@@ -120,11 +114,14 @@ void StereoCensusSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArra ...@@ -120,11 +114,14 @@ void StereoCensusSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArra
// message passing. Lecture Notes in Computer Science (Including Subseries // message passing. Lecture Notes in Computer Science (Including Subseries
// Lecture Notes in Artificial Intelligence and Lecture Notes in // Lecture Notes in Artificial Intelligence and Lecture Notes in
// Bioinformatics). https://doi.org/10.1007/978-3-319-11752-2_4 // Bioinformatics). https://doi.org/10.1007/978-3-319-11752-2_4
//cv::Mat uncertainty;
//uncertainty = impl_->cost_min.toMat() - impl_->cost_min_paths.toMat(); if (disparity.isGpuMat()) {
// confidence threshold // TODO: extract cost_min in WTA
// TODO: estimate confidence from uncertainty and plot ROC curve. cv::cuda::GpuMat uncertainty;
//disparity.setTo(0.0f, uncertainty > params.uniqueness); cv::cuda::subtract(impl_->cost_min.toGpuMat(), impl_->cost_min_paths.toGpuMat(), uncertainty);
cv::cuda::compare(uncertainty, params.uniqueness, uncertainty, cv::CMP_GT);
disparity.getGpuMatRef().setTo(0, uncertainty);
}
} }
StereoCensusSgm::~StereoCensusSgm() { StereoCensusSgm::~StereoCensusSgm() {
......
...@@ -45,9 +45,6 @@ using cv::Mat; ...@@ -45,9 +45,6 @@ using cv::Mat;
using cv::Size; using cv::Size;
using ftl::stereo::aggregations::StandardSGM; using ftl::stereo::aggregations::StandardSGM;
static int ct_windows_w = 9;
static int ct_windows_h = 7;
struct StereoGradientStree::Impl { struct StereoGradientStree::Impl {
GradientMatchingCostL2 cost; GradientMatchingCostL2 cost;
Array2D<unsigned short> cost_min; Array2D<unsigned short> cost_min;
...@@ -95,13 +92,13 @@ void StereoGradientStree::compute(cv::InputArray l, cv::InputArray r, cv::Output ...@@ -95,13 +92,13 @@ void StereoGradientStree::compute(cv::InputArray l, cv::InputArray r, cv::Output
cudaSafeCall(cudaDeviceSynchronize()); cudaSafeCall(cudaDeviceSynchronize());
//AggregationParameters aggr_params = {impl_->cost_min_paths.data(), params}; //AggregationParameters aggr_params = {impl_->cost_min_paths.data(), params};
StandardSGM<GradientMatchingCostL2::DataType> func1 = {impl_->cost.data(), params.P1, params.P2}; StandardSGM<GradientMatchingCostL2::DataType> func1 = {impl_->cost.data(), impl_->cost_min_paths.data(), params.P1, params.P2};
auto &out1 = impl_->aggr1(func1, AggregationDirections::HORIZONTAL); auto &out1 = impl_->aggr1(func1, AggregationDirections::HORIZONTAL);
cudaSafeCall(cudaDeviceSynchronize()); cudaSafeCall(cudaDeviceSynchronize());
if (params.debug) { timer_print("Aggregation 1"); } if (params.debug) { timer_print("Aggregation 1"); }
StandardSGM<DisparitySpaceImage<unsigned short>::DataType> func2 = { out1.data(), params.P1, params.P2}; StandardSGM<DisparitySpaceImage<unsigned short>::DataType> func2 = {out1.data(), impl_->cost_min_paths.data(), params.P1, params.P2};
auto &out2 = impl_->aggr2(func2, AggregationDirections::VERTICAL); auto &out2 = impl_->aggr2(func2, AggregationDirections::VERTICAL);
cudaSafeCall(cudaDeviceSynchronize()); cudaSafeCall(cudaDeviceSynchronize());
......
...@@ -122,7 +122,7 @@ void StereoMiSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArray di ...@@ -122,7 +122,7 @@ void StereoMiSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArray di
cudaSafeCall(cudaDeviceSynchronize()); cudaSafeCall(cudaDeviceSynchronize());
// cost aggregation // cost aggregation
//AggregationParameters aggr_params = {impl_->cost_min_paths.data(), params}; //AggregationParameters aggr_params = {impl_->cost_min_paths.data(), params};
StandardSGM<MutualInformationMatchingCost::DataType> func = {impl_->cost.data(), params.P1, params.P2}; StandardSGM<MutualInformationMatchingCost::DataType> func = {impl_->cost.data(), impl_->cost_min_paths.data(), params.P1, params.P2};
auto &out = impl_->aggr(func, AggregationDirections::ALL); // params.paths auto &out = impl_->aggr(func, AggregationDirections::ALL); // params.paths
cudaSafeCall(cudaDeviceSynchronize()); cudaSafeCall(cudaDeviceSynchronize());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment