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

input parameters for census and mi costs

parent 44519911
No related branches found
No related tags found
No related merge requests found
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
~StereoMiSgm(); ~StereoMiSgm();
void compute(cv::InputArray l, cv::InputArray r, cv::OutputArray disparity); void compute(cv::InputArray l, cv::InputArray r, cv::OutputArray disparity);
void setPrior(const cv::Mat &disp); void setPrior(cv::InputArray disp);
struct Parameters { struct Parameters {
int d_min = 0; int d_min = 0;
...@@ -109,6 +109,36 @@ private: ...@@ -109,6 +109,36 @@ private:
}; };
class StereoMiSgm2 {
public:
StereoMiSgm2();
~StereoMiSgm2();
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 = 2;
unsigned short P2 = 8;
float uniqueness = std::numeric_limits<short>::max();
int subpixel = 1; // subpixel interpolation method
int paths = AggregationDirections::HORIZONTAL |
AggregationDirections::VERTICAL |
AggregationDirections::DIAGONAL;
bool debug = false;
float w1 = 1.0;
float w2 = 1.0;
};
Parameters params;
private:
struct Impl;
Impl *impl_;
};
/** /**
* Census + SGM + prior * Census + SGM + prior
* *
......
...@@ -46,3 +46,24 @@ void CensusMatchingCost::set(const Array2D<uchar> &l, const Array2D<uchar> &r) { ...@@ -46,3 +46,24 @@ void CensusMatchingCost::set(const Array2D<uchar> &l, const Array2D<uchar> &r) {
parallel2D<algorithms::CensusTransform<9,7>>({l.data(), ct_l_.data()}, l.width, l.height); parallel2D<algorithms::CensusTransform<9,7>>({l.data(), ct_l_.data()}, l.width, l.height);
parallel2D<algorithms::CensusTransform<9,7>>({r.data(), ct_r_.data()}, r.width, r.height); parallel2D<algorithms::CensusTransform<9,7>>({r.data(), ct_r_.data()}, r.width, r.height);
} }
void CensusMatchingCost::set(cv::InputArray l, cv::InputArray r) {
if (l.type() != CV_8UC1 || r.type() != CV_8UC1) { throw std::exception(); }
if (l.rows() != r.rows() || l.cols() != r.cols() || l.rows() != height() || l.cols() != width()) {
throw std::exception();
}
if (l.isGpuMat() && r.isGpuMat()) {
auto ml = l.getGpuMat();
auto mr = r.getGpuMat();
set(Array2D<uchar>(ml), Array2D<uchar>(mr));
}
else if (l.isMat() && r.isMat()) {
auto ml = l.getMat();
auto mr = r.getMat();
set(Array2D<uchar>(ml), Array2D<uchar>(mr));
}
else {
throw std::exception();
}
}
...@@ -39,17 +39,17 @@ public: ...@@ -39,17 +39,17 @@ public:
typedef unsigned short Type; typedef unsigned short Type;
CensusMatchingCost() : DSBase<DataType>(0, 0, 0, 0) {}; CensusMatchingCost() : DSBase<DataType>(0, 0, 0, 0) {};
CensusMatchingCost(int width, int height, int disp_min, int disp_max, int wwidth, int wheight) CensusMatchingCost(int width, int height, int disp_min, int disp_max)
: DSBase<DataType>(width, height, disp_min, disp_max), : DSBase<DataType>(width, height, disp_min, disp_max),
ct_l_(width, height), ct_r_(width,height), ct_l_(width, height), ct_r_(width,height),
//cost_max(wwidth * wheight), //cost_max(wwidth * wheight),
ww_(wwidth), wh_(wheight) ww_(9), wh_(7)
{ {
if (wwidth != 9 || wheight != 7) { if (ww_ != 9 || wh_ != 7) {
// TODO: window size paramters (hardcoded) in matching_cost.cpp // TODO: window size paramters (hardcoded) in matching_cost.cpp
throw std::exception(); throw std::exception();
} }
if (wwidth*wheight > 64) { if (ww_*wh_ > 64) {
throw std::exception(); // todo: dynamic size throw std::exception(); // todo: dynamic size
} }
...@@ -57,6 +57,7 @@ public: ...@@ -57,6 +57,7 @@ public:
data().ct_r = ct_r_.data(); data().ct_r = ct_r_.data();
} }
void set(cv::InputArray l, cv::InputArray r);
void set(const Array2D<uchar>& l, const Array2D<uchar>& r); void set(const Array2D<uchar>& l, const Array2D<uchar>& r);
static constexpr short COST_MAX = 9*7; // TODO: window size paramters (hardcoded) in matching_cost.cpp static constexpr short COST_MAX = 9*7; // TODO: window size paramters (hardcoded) in matching_cost.cpp
......
...@@ -69,7 +69,7 @@ struct StereoADCensusSgm::Impl { ...@@ -69,7 +69,7 @@ struct StereoADCensusSgm::Impl {
Impl(int width, int height, int min_disp, int max_disp) : Impl(int width, int height, int min_disp, int max_disp) :
dsi(width, height, min_disp, max_disp), dsi(width, height, min_disp, max_disp),
ad_cost(width, height, min_disp, max_disp), ad_cost(width, height, min_disp, max_disp),
census_cost(width, height, min_disp, max_disp, 9, 7), census_cost(width, height, min_disp, max_disp),
cost(width, height, min_disp, max_disp, ad_cost, census_cost), cost(width, height, min_disp, max_disp, ad_cost, census_cost),
cost_min(width, height), cost_min(width, height),
cost_min_paths(width, height), cost_min_paths(width, height),
......
...@@ -63,8 +63,7 @@ struct StereoCensusSgm::Impl { ...@@ -63,8 +63,7 @@ struct StereoCensusSgm::Impl {
WinnerTakesAll<DSImage16U,float> wta; WinnerTakesAll<DSImage16U,float> wta;
Impl(int width, int height, int min_disp, int max_disp) : Impl(int width, int height, int min_disp, int max_disp) :
//dsi(width, height, min_disp, max_disp), cost(width, height, min_disp, max_disp),
cost(width, height, min_disp, max_disp, ct_windows_w, ct_windows_h),
cost_min(width, height), cost_min(width, height),
cost_min_paths(width, height), cost_min_paths(width, height),
uncertainty(width, height), uncertainty(width, height),
......
...@@ -47,6 +47,7 @@ using ftl::stereo::aggregations::StandardSGM; ...@@ -47,6 +47,7 @@ using ftl::stereo::aggregations::StandardSGM;
struct StereoMiSgm::Impl { struct StereoMiSgm::Impl {
MutualInformationMatchingCost cost; MutualInformationMatchingCost 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<unsigned short> uncertainty;
...@@ -74,8 +75,16 @@ StereoMiSgm::StereoMiSgm() : impl_(nullptr) { ...@@ -74,8 +75,16 @@ StereoMiSgm::StereoMiSgm() : impl_(nullptr) {
impl_ = new Impl(0, 0, 0, 0); impl_ = new Impl(0, 0, 0, 0);
} }
void StereoMiSgm::setPrior(const cv::Mat &prior) { void StereoMiSgm::setPrior(cv::InputArray prior) {
prior.copyTo(impl_->prior); if (prior.rows() != impl_->cost.height() || prior.cols() != impl_->cost.width()) {
return;
}
if (prior.isGpuMat()) {
prior.getGpuMat().download(impl_->prior);
}
else {
prior.getMat().copyTo(impl_->prior);
}
} }
......
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