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

Resolve "Masking of invalid areas"

parent c2344689
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,7 @@ class StereoVideoSource : public RGBDSource { ...@@ -42,6 +42,7 @@ class StereoVideoSource : public RGBDSource {
bool ready_; bool ready_;
cv::Mat left_; cv::Mat left_;
cv::Mat right_; cv::Mat right_;
cv::Mat mask_l_;
}; };
} }
......
...@@ -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) { void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp, const cv::Mat &mask_l) {
Mat left_disp; Mat left_disp;
Mat right_disp; Mat right_disp;
...@@ -43,6 +43,7 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) { ...@@ -43,6 +43,7 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) {
// 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;
...@@ -57,3 +58,8 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) { ...@@ -57,3 +58,8 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) {
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) {
// todo: allow using without mask
LOG(FATAL) << "libSGM: not using mask (required)!";
}
...@@ -25,8 +25,9 @@ class FixstarsSGM : public ftl::Disparity { ...@@ -25,8 +25,9 @@ class FixstarsSGM : public ftl::Disparity {
public: public:
explicit FixstarsSGM(nlohmann::json &config); explicit FixstarsSGM(nlohmann::json &config);
void compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp); 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;
/* Factory creator */ /* Factory creator */
static inline Disparity *create(nlohmann::json &config) { static inline Disparity *create(nlohmann::json &config) {
return new FixstarsSGM(config); return new FixstarsSGM(config);
......
...@@ -492,6 +492,11 @@ bool Calibrate::_recalibrate(vector<vector<Point2f>> *imagePoints, ...@@ -492,6 +492,11 @@ bool Calibrate::_recalibrate(vector<vector<Point2f>> *imagePoints,
return true; return true;
} }
void Calibrate::rectifyStereo(cv::Mat &l, cv::Mat &r) {
remap(l, l, map1_[0], map2_[0], INTER_LINEAR);
remap(r, r, map1_[1], map2_[1], INTER_LINEAR);
}
bool Calibrate::undistort(cv::Mat &l, cv::Mat &r) { bool Calibrate::undistort(cv::Mat &l, cv::Mat &r) {
Mat l_tmp, r_tmp; Mat l_tmp, r_tmp;
local_->get(l_tmp, r_tmp); local_->get(l_tmp, r_tmp);
......
...@@ -101,6 +101,11 @@ class Calibrate { ...@@ -101,6 +101,11 @@ class Calibrate {
*/ */
bool rectified(cv::Mat &l, cv::Mat &r); bool rectified(cv::Mat &l, cv::Mat &r);
/**
* Rectify and remove distortions from from images l and r using cv::remap()
*/
void rectifyStereo(cv::Mat &l, cv::Mat &r);
bool isCalibrated(); bool isCalibrated();
/** /**
......
...@@ -28,7 +28,10 @@ class Disparity { ...@@ -28,7 +28,10 @@ class Disparity {
* 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.
*/ */
......
...@@ -58,7 +58,14 @@ StereoVideoSource::StereoVideoSource(nlohmann::json &config, const string &file) ...@@ -58,7 +58,14 @@ StereoVideoSource::StereoVideoSource(nlohmann::json &config, const string &file)
0.0f, // 0m min 0.0f, // 0m min
15.0f // 15m max 15.0f // 15m max
}; };
// left and right masks (areas outside rectified images)
// only left mask used
cv::Mat mask_r(lsrc_->height(), lsrc_->width(), CV_8U, 255);
cv::Mat mask_l(lsrc_->height(), lsrc_->width(), CV_8U, 255);
calib_->rectifyStereo(mask_l, mask_r);
mask_l_ = (mask_l == 0);
disp_ = Disparity::create(config["disparity"]); disp_ = Disparity::create(config["disparity"]);
if (!disp_) LOG(FATAL) << "Unknown disparity algorithm : " << config["disparity"]; if (!disp_) LOG(FATAL) << "Unknown disparity algorithm : " << config["disparity"];
...@@ -105,7 +112,7 @@ static void disparityToDepth(const cv::Mat &disparity, cv::Mat &depth, const cv: ...@@ -105,7 +112,7 @@ static void disparityToDepth(const cv::Mat &disparity, cv::Mat &depth, const cv:
void StereoVideoSource::getRGBD(cv::Mat &rgb, cv::Mat &depth) { void StereoVideoSource::getRGBD(cv::Mat &rgb, cv::Mat &depth) {
cv::Mat disp; cv::Mat disp;
disp_->compute(left_, right_, disp); disp_->compute(left_, right_, disp, mask_l_);
rgb = left_; rgb = left_;
disparityToDepth(disp, depth, calib_->getQ()); disparityToDepth(disp, depth, calib_->getQ());
//calib_->distort(rgb,depth); //calib_->distort(rgb,depth);
......
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