From 43da563ad20a8b5500f4a7593c2b7fd683a49685 Mon Sep 17 00:00:00 2001 From: Sebastian Hahta <joseha@utu.fi> Date: Thu, 27 Feb 2020 15:50:15 +0200 Subject: [PATCH] disparity offset scaling --- .../src/sources/stereovideo/calibrate.cpp | 8 ++++++++ .../src/sources/stereovideo/calibrate.hpp | 13 ++++++++++++- .../src/sources/stereovideo/stereovideo.cpp | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/components/rgbd-sources/src/sources/stereovideo/calibrate.cpp b/components/rgbd-sources/src/sources/stereovideo/calibrate.cpp index 7851fb154..c4200e0c3 100644 --- a/components/rgbd-sources/src/sources/stereovideo/calibrate.cpp +++ b/components/rgbd-sources/src/sources/stereovideo/calibrate.cpp @@ -76,6 +76,14 @@ double Calibrate::getBaseline() const { return cv::norm(t_); } +double Calibrate::getDoff() const { + return -(Q_.at<double>(3,3) * getBaseline()); +} + +double Calibrate::getDoff(const Size& size) const { + return getDoff() * ((double) size.width / (double) img_size_.width); +} + Mat Calibrate::getCameraMatrixLeft(const cv::Size res) { if (rectify_) { return ftl::calibration::scaleCameraMatrix(Mat(P1_, cv::Rect(0, 0, 3, 3)), res, img_size_); diff --git a/components/rgbd-sources/src/sources/stereovideo/calibrate.hpp b/components/rgbd-sources/src/sources/stereovideo/calibrate.hpp index 06a129b7f..967d84676 100644 --- a/components/rgbd-sources/src/sources/stereovideo/calibrate.hpp +++ b/components/rgbd-sources/src/sources/stereovideo/calibrate.hpp @@ -53,12 +53,14 @@ class Calibrate : public ftl::Configurable { /** * @brief Get disparity to depth matrix - * + * @note Disparity offset is in image_size (scale) + * * 2020/01/15: StereoVideoSource creates a Camera object which is used to * calculate depth from disparity (disp2depth.cu). Seems to be * used only in StereoVideoSource to get doff and baseline * parameter values in updateParameters() */ + [[deprecated]] const cv::Mat &getQ() const { return Q_; } /** @@ -66,6 +68,15 @@ class Calibrate : public ftl::Configurable { */ double getBaseline() const; + /** + * @brief Get camera pair disparity offset + * @param size (optional) scale to given resolution. + * + * Returns disparity offset for image_size resolution if size not provided. + */ + double getDoff() const; + double getDoff(const cv::Size& size) const; + /** * @brief Get intrinsic paramters. If rectification is enabled, returns * rectified intrinsic parameters, otherwise returns values from diff --git a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp index 94854624e..5c4b67772 100644 --- a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp +++ b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp @@ -202,7 +202,7 @@ void StereoVideoSource::updateParameters() { // same for left and right float baseline = static_cast<float>(calib_->getBaseline()); - float doff = static_cast<float>(-calib_->getQ().at<double>(3,3) * baseline); + float doff = calib_->getDoff(color_size_); double d_resolution = this->host_->getConfig().value<double>("depth_resolution", 0.0); float min_depth = this->host_->getConfig().value<double>("min_depth", 0.45); -- GitLab