From 98bec15bbd47602bf7e4cde9a59f8ca4c333ed08 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Fri, 14 Jun 2019 13:39:32 +0300 Subject: [PATCH] Lock after decode --- components/rgbd-sources/src/net.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/rgbd-sources/src/net.cpp b/components/rgbd-sources/src/net.cpp index 0ce3b1fa2..39e039854 100644 --- a/components/rgbd-sources/src/net.cpp +++ b/components/rgbd-sources/src/net.cpp @@ -62,13 +62,17 @@ NetSource::~NetSource() { } void NetSource::_recv(const vector<unsigned char> &jpg, const vector<unsigned char> &d) { - unique_lock<shared_mutex> lk(host_->mutex()); + cv::Mat tmp_rgb, tmp_depth; auto start = std::chrono::high_resolution_clock::now(); - cv::imdecode(jpg, cv::IMREAD_COLOR, &rgb_); + cv::imdecode(jpg, cv::IMREAD_COLOR, &tmp_rgb); //Mat(rgb_.size(), CV_16UC1); - cv::imdecode(d, cv::IMREAD_UNCHANGED, &depth_); - depth_.convertTo(depth_, CV_32FC1, 1.0f/(16.0f*100.0f)); + cv::imdecode(d, cv::IMREAD_UNCHANGED, &tmp_depth); + + unique_lock<shared_mutex> lk(host_->mutex()); + rgb_ = tmp_rgb; + tmp_depth.convertTo(depth_, CV_32FC1, 1.0f/(16.0f*100.0f)); + lk.unlock(); std::chrono::duration<double> elapsed = std::chrono::high_resolution_clock::now() - start; -- GitLab