Skip to content
Snippets Groups Projects
Commit b980cb11 authored by Sebastian Hahta's avatar Sebastian Hahta Committed by Nicolas Pope
Browse files

Feature/libsgm mask

parent 4866b0b4
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ FixstarsSGM::FixstarsSGM(nlohmann::json &config) : Disparity(config) { ...@@ -17,7 +17,7 @@ FixstarsSGM::FixstarsSGM(nlohmann::json &config) : Disparity(config) {
filter_ = cv::cuda::createDisparityBilateralFilter(max_disp_ << 4, config.value("filter_radius", 25), config.value("filter_iter", 1)); filter_ = cv::cuda::createDisparityBilateralFilter(max_disp_ << 4, config.value("filter_radius", 25), config.value("filter_iter", 1));
} }
void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp, const cv::Mat &mask_l) { void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) {
Mat left_disp; Mat left_disp;
Mat right_disp; Mat right_disp;
...@@ -25,7 +25,7 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp, con ...@@ -25,7 +25,7 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp, con
cv::cvtColor(l, lbw, cv::COLOR_BGR2GRAY); cv::cvtColor(l, lbw, cv::COLOR_BGR2GRAY);
cv::cvtColor(r, rbw, cv::COLOR_BGR2GRAY); cv::cvtColor(r, rbw, cv::COLOR_BGR2GRAY);
if (!ssgm_) { if (!ssgm_) { // todo: move to constructor
ssgm_ = new sgm::StereoSGM(l.cols, l.rows, max_disp_, 8, 16, ssgm_ = new sgm::StereoSGM(l.cols, l.rows, max_disp_, 8, 16,
sgm::EXECUTE_INOUT_HOST2HOST, sgm::EXECUTE_INOUT_HOST2HOST,
sgm::StereoSGM::Parameters(10,120,0.95f,true)); sgm::StereoSGM::Parameters(10,120,0.95f,true));
...@@ -43,7 +43,6 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp, con ...@@ -43,7 +43,6 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp, con
// disparity values set to (256 << 5) in libSGM consistency check // disparity values set to (256 << 5) in libSGM consistency check
Mat bad_pixels = (disp == (256 << 5)); Mat bad_pixels = (disp == (256 << 5));
disp.setTo(0, bad_pixels); disp.setTo(0, bad_pixels);
disp.setTo(0, mask_l);
if (use_filter_) { if (use_filter_) {
cv::cuda::GpuMat l_gpu, disp_gpu, disp_gpu_out; cv::cuda::GpuMat l_gpu, disp_gpu, disp_gpu_out;
...@@ -59,7 +58,15 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp, con ...@@ -59,7 +58,15 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp, con
disp.convertTo(disp, CV_32F, 1.0f/16.0f); disp.convertTo(disp, CV_32F, 1.0f/16.0f);
} }
void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) { void FixstarsSGM::setMask(Mat &mask) {
// todo: allow using without mask LOG_ASSERT(mask.type() == CV_8UC1) << "mask type must be CV_8U";
LOG(FATAL) << "libSGM: not using mask (required)!";
if (!ssgm_) { // todo: move to constructor
ssgm_ = new sgm::StereoSGM(mask.cols, mask.rows, max_disp_, 8, 16,
sgm::EXECUTE_INOUT_HOST2HOST,
sgm::StereoSGM::Parameters(10,120,0.95f,true));
}
mask_l_ = mask;
ssgm_->setMask((uint8_t*) mask.data, mask.cols);
} }
\ No newline at end of file
...@@ -27,7 +27,7 @@ class FixstarsSGM : public ftl::Disparity { ...@@ -27,7 +27,7 @@ class FixstarsSGM : public ftl::Disparity {
explicit FixstarsSGM(nlohmann::json &config); explicit FixstarsSGM(nlohmann::json &config);
void compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) override; void compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) override;
void compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp, const cv::Mat &mask_l) override; void setMask(cv::Mat &mask) override;
/* Factory creator */ /* Factory creator */
static inline Disparity *create(ftl::Configurable *p, const std::string &name) { static inline Disparity *create(ftl::Configurable *p, const std::string &name) {
......
...@@ -24,14 +24,13 @@ class Disparity : public ftl::Configurable { ...@@ -24,14 +24,13 @@ class Disparity : public ftl::Configurable {
virtual void setMinDisparity(size_t min) { min_disp_ = min; } virtual void setMinDisparity(size_t min) { min_disp_ = min; }
virtual void setMaxDisparity(size_t max) { max_disp_ = max; } virtual void setMaxDisparity(size_t max) { max_disp_ = max; }
virtual void setMask(cv::Mat &mask) { mask_l_ = mask; }
/** /**
* Pure virtual function representing the actual computation of * Pure virtual function representing the actual computation of
* disparity from left and right images to be implemented. * disparity from left and right images to be implemented.
*/ */
virtual void compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp)=0; virtual void compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp)=0;
virtual void compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp, const cv::Mat &mask_l) {
compute(l, r, disp);
}
/** /**
* Factory registration class. * Factory registration class.
...@@ -56,6 +55,7 @@ class Disparity : public ftl::Configurable { ...@@ -56,6 +55,7 @@ class Disparity : public ftl::Configurable {
//nlohmann::json &config_; //nlohmann::json &config_;
size_t min_disp_; size_t min_disp_;
size_t max_disp_; size_t max_disp_;
cv::Mat mask_l_;
private: private:
static std::map<std::string,std::function<Disparity*(ftl::Configurable *, const std::string &)>> *algorithms__; static std::map<std::string,std::function<Disparity*(ftl::Configurable *, const std::string &)>> *algorithms__;
......
...@@ -76,6 +76,7 @@ StereoVideoSource::StereoVideoSource(nlohmann::json &config, const string &file) ...@@ -76,6 +76,7 @@ StereoVideoSource::StereoVideoSource(nlohmann::json &config, const string &file)
disp_ = Disparity::create(this, "disparity"); disp_ = Disparity::create(this, "disparity");
if (!disp_) LOG(FATAL) << "Unknown disparity algorithm : " << *get<ftl::config::json_t>("disparity"); if (!disp_) LOG(FATAL) << "Unknown disparity algorithm : " << *get<ftl::config::json_t>("disparity");
disp_->setMask(mask_l_);
LOG(INFO) << "StereoVideo source ready..."; LOG(INFO) << "StereoVideo source ready...";
ready_ = true; ready_ = true;
...@@ -114,7 +115,7 @@ void StereoVideoSource::grab() { ...@@ -114,7 +115,7 @@ void StereoVideoSource::grab() {
calib_->rectified(left_, right_); calib_->rectified(left_, right_);
cv::Mat disp; cv::Mat disp;
disp_->compute(left_, right_, disp, mask_l_); disp_->compute(left_, right_, disp);
unique_lock<mutex> lk(mutex_); unique_lock<mutex> lk(mutex_);
left_.copyTo(rgb_); left_.copyTo(rgb_);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment