From 4ab114b7ffdbcb67fb6287296c3eda21a89013ad Mon Sep 17 00:00:00 2001 From: Sebastian Hahta <joseha@utu.fi> Date: Thu, 16 Jul 2020 20:51:44 +0300 Subject: [PATCH] move fs --- .../gui2/src/modules/calibration/stereo.cpp | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/applications/gui2/src/modules/calibration/stereo.cpp b/applications/gui2/src/modules/calibration/stereo.cpp index 6d3b117ad..29fd3a9ea 100644 --- a/applications/gui2/src/modules/calibration/stereo.cpp +++ b/applications/gui2/src/modules/calibration/stereo.cpp @@ -52,6 +52,8 @@ StereoCalibration::~StereoCalibration() { if(future_.valid()) { future_.wait(); } + fs_current_.reset(); + fs_update_.reset(); } void StereoCalibration::reset() { @@ -89,12 +91,12 @@ void StereoCalibration::start(ftl::data::FrameID id) { view->onClose([filter, this](){ // if state_->calib caches images, also reset() here! filter->remove(); - if (state_->fs_current) { - setCalibrationMode(state_->fs_current->frames[state_->id.source()], true); + if (fs_current_) { + setCalibrationMode(fs_current_->frames[state_->id.source()], true); } reset(); - state_->fs_current.reset(); - state_->fs_updated.reset(); + fs_current_.reset(); + fs_update_.reset(); }); screen->setView(view); @@ -127,7 +129,7 @@ void StereoCalibration::start(ftl::data::FrameID id) { bool StereoCalibration::onFrame_(const ftl::data::FrameSetPtr& fs) { - std::atomic_store(&state_->fs_updated, fs); + std::atomic_store(&fs_update_, fs); screen->redraw(); auto& frame = fs->frames[state_->id.source()]; @@ -211,18 +213,18 @@ void StereoCalibration::run() { auto K2 = calib_l.intrinsic.matrix(); auto distCoeffs2 = calib_r.intrinsic.distCoeffs.Mat(); cv::Mat R, T, E, F; - int flags = 0; - cv::stereoCalibrate(state_->points_object, state_->points_l, + state_->reprojection_error = cv::stereoCalibrate( + state_->points_object, state_->points_l, state_->points_r, K1, distCoeffs1, K2, distCoeffs2, - state_->imsize, R, T, E, F, flags); - + state_->imsize, R, T, E, F, state_->flags); + state_->calib.get(Channel::Left).intrinsic = CalibrationData::Intrinsic(K1, distCoeffs1, state_->imsize); state_->calib.get(Channel::Right).intrinsic = CalibrationData::Intrinsic(K2, distCoeffs2, state_->imsize); state_->calib.get(Channel::Right).extrinsic = CalibrationData::Extrinsic(R, T); - auto fs = std::atomic_load(&(state_->fs_current)); + auto fs = std::atomic_load(&(fs_current_)); setCalibration((*fs)[state_->id.source()], state_->calib); } catch (std::exception &e) { @@ -238,8 +240,8 @@ void StereoCalibration::run() { bool StereoCalibration::hasFrame() { auto cleft = state_->highres ? Channel::LeftHighRes : Channel::Left; auto cright = state_->highres ? Channel::RightHighRes : Channel::Right; - return (std::atomic_load(&state_->fs_updated).get() != nullptr) - && state_->fs_updated->frames[state_->id.source()].hasAll({cleft, cright}); + return (std::atomic_load(&fs_update_).get() != nullptr) + && fs_update_->frames[state_->id.source()].hasAll({cleft, cright}); }; Channel StereoCalibration::channelLeft_() { @@ -251,20 +253,20 @@ Channel StereoCalibration::channelRight_() { } cv::cuda::GpuMat StereoCalibration::getLeft() { - if (std::atomic_load(&state_->fs_updated)) { - state_->fs_current = state_->fs_updated; - std::atomic_store(&state_->fs_updated, {}); + if (std::atomic_load(&fs_update_)) { + fs_current_ = fs_update_; + std::atomic_store(&fs_update_, {}); } - auto& frame = (*state_->fs_current)[state_->id.source()].cast<ftl::rgbd::Frame>(); + auto& frame = (*fs_current_)[state_->id.source()].cast<ftl::rgbd::Frame>(); return getGpuMat(frame ,channelLeft_()); } cv::cuda::GpuMat StereoCalibration::getRight() { - if (std::atomic_load(&state_->fs_updated)) { - state_->fs_current = state_->fs_updated; - std::atomic_store(&state_->fs_updated, {}); + if (std::atomic_load(&fs_update_)) { + fs_current_ = fs_update_; + std::atomic_store(&fs_update_, {}); } - auto& frame = (*state_->fs_current)[state_->id.source()].cast<ftl::rgbd::Frame>(); + auto& frame = (*fs_current_)[state_->id.source()].cast<ftl::rgbd::Frame>(); return getGpuMat(frame ,channelRight_()); } @@ -276,8 +278,8 @@ cv::cuda::GpuMat StereoCalibration::getRightRectify() { } bool StereoCalibration::hasChannel(Channel c) { - if (state_->fs_current) { - return (*state_->fs_current)[state_->id.source()].hasChannel(c); + if (fs_current_) { + return (*fs_current_)[state_->id.source()].hasChannel(c); } return false; } -- GitLab