Skip to content
Snippets Groups Projects
Commit 675b3f99 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Add a bilateral filtered reference pixel census

parent 901c14f3
No related branches found
No related tags found
2 merge requests!347Feature buckets experiment,!300Implement experimental SGM algorithms
Pipeline #25884 passed
...@@ -42,6 +42,7 @@ if (LIBSTEREO_SHARED) ...@@ -42,6 +42,7 @@ if (LIBSTEREO_SHARED)
src/algorithms/stablesgm.cu src/algorithms/stablesgm.cu
src/algorithms/tcensussgm.cu src/algorithms/tcensussgm.cu
src/algorithms/hcensussgm.cu src/algorithms/hcensussgm.cu
src/algorithms/brefcensussgm.cu
#src/stereo_hier_census.cu #src/stereo_hier_census.cu
src/stereo_wcensussgm.cu src/stereo_wcensussgm.cu
src/stereo_census_adaptive.cu src/stereo_census_adaptive.cu
...@@ -73,6 +74,7 @@ else() ...@@ -73,6 +74,7 @@ else()
src/algorithms/stablesgm.cu src/algorithms/stablesgm.cu
src/algorithms/tcensussgm.cu src/algorithms/tcensussgm.cu
src/algorithms/hcensussgm.cu src/algorithms/hcensussgm.cu
src/algorithms/brefcensussgm.cu
#src/stereo_hier_census.cu #src/stereo_hier_census.cu
src/stereo_wcensussgm.cu src/stereo_wcensussgm.cu
src/stereo_census_adaptive.cu src/stereo_census_adaptive.cu
......
...@@ -85,6 +85,37 @@ private: ...@@ -85,6 +85,37 @@ private:
Impl *impl_; Impl *impl_;
}; };
/**
* Bilateral filtering for reference pixel. Doesn't make things better
*/
class StereoBRefCensusSgm {
public:
StereoBRefCensusSgm();
~StereoBRefCensusSgm();
void compute(cv::InputArray l, cv::InputArray r, cv::OutputArray disparity);
void setPrior(cv::InputArray disp) {};
struct Parameters {
int d_min = 0;
int d_max = 0;
unsigned short P1 = 5;
unsigned short P2 = 25;
float uniqueness = std::numeric_limits<unsigned short>::max();
int subpixel = 1; // subpixel interpolation method
bool lr_consistency = true;
int paths = AggregationDirections::HORIZONTAL |
AggregationDirections::VERTICAL |
AggregationDirections::DIAGONAL;
bool debug = false;
};
Parameters params;
private:
struct Impl;
Impl *impl_;
};
/** /**
* STABLE Binary descriptor. This is a general implementation. * STABLE Binary descriptor. This is a general implementation.
* *
......
...@@ -27,6 +27,19 @@ static void run_censussgm(MiddleburyData &data, cv::Mat &disparity) { ...@@ -27,6 +27,19 @@ static void run_censussgm(MiddleburyData &data, cv::Mat &disparity) {
stereo.compute(data.imL, data.imR, disparity); stereo.compute(data.imL, data.imR, disparity);
} }
static void run_brefcensussgm(MiddleburyData &data, cv::Mat &disparity) {
auto stereo = StereoBRefCensusSgm();
stereo.params.P1 = 12;
stereo.params.P2 = 32;
stereo.params.d_min = data.calib.vmin;
stereo.params.d_max = data.calib.vmax;
stereo.params.subpixel = 1;
stereo.params.lr_consistency = true;
stereo.params.debug = false;
stereo.compute(data.imL, data.imR, disparity);
}
static void run_stablesgm(MiddleburyData &data, cv::Mat &disparity) { static void run_stablesgm(MiddleburyData &data, cv::Mat &disparity) {
auto stereo = StereoStableSgm(); auto stereo = StereoStableSgm();
stereo.params.P1 = 8; stereo.params.P1 = 8;
...@@ -179,6 +192,7 @@ static const std::map<std::string, std::function<void(MiddleburyData&, cv::Mat&) ...@@ -179,6 +192,7 @@ static const std::map<std::string, std::function<void(MiddleburyData&, cv::Mat&)
{ "tcensussgm", run_tcensussgm }, { "tcensussgm", run_tcensussgm },
{ "hcensussgm", run_hcensussgm }, { "hcensussgm", run_hcensussgm },
{ "wcensussgm", run_wcensussgm }, { "wcensussgm", run_wcensussgm },
{ "brefcensus", run_brefcensussgm },
//{ "misgm", run_misgm }, //{ "misgm", run_misgm },
{ "varcensus", run_varcensus }, { "varcensus", run_varcensus },
{ "stablesgm", run_stablesgm }, { "stablesgm", run_stablesgm },
......
#include "stereo.hpp"
#include "stereosgm.hpp"
#include "../costs/census.hpp"
#include <opencv2/cudaimgproc.hpp>
#include <opencv2/highgui.hpp>
struct StereoBRefCensusSgm::Impl : public StereoSgm<CensusMatchingCost, StereoBRefCensusSgm::Parameters> {
Array2D<uchar> l;
Array2D<uchar> r;
Array2D<uchar> bl;
Array2D<uchar> br;
Impl(StereoBRefCensusSgm::Parameters &params, int width, int height, int dmin, int dmax) :
StereoSgm(params, width, height, dmin, dmax), l(width, height), r(width, height),
bl(width, height), br(width, height) {}
};
StereoBRefCensusSgm::StereoBRefCensusSgm() : impl_(nullptr) {
impl_ = new Impl(params, 0, 0, 0, 0);
}
void StereoBRefCensusSgm::compute(cv::InputArray l, cv::InputArray r, cv::OutputArray disparity) {
cudaSetDevice(0);
if (l.rows() != impl_->cost.height() || r.cols() != impl_->cost.width()) {
delete impl_; impl_ = nullptr;
impl_ = new Impl(params, l.cols(), l.rows(), params.d_min, params.d_max);
}
mat2gray(l, impl_->l);
mat2gray(r, impl_->r);
cv::cuda::bilateralFilter(impl_->l.toGpuMat(), impl_->bl.toGpuMat(), 5, 50, 100);
cv::cuda::bilateralFilter(impl_->r.toGpuMat(), impl_->br.toGpuMat(), 5, 50, 100);
impl_->cost.set(impl_->bl, impl_->br, impl_->l, impl_->r);
cudaSafeCall(cudaDeviceSynchronize());
impl_->compute(disparity);
}
StereoBRefCensusSgm::~StereoBRefCensusSgm() {
if (impl_) {
delete impl_;
impl_ = nullptr;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment