diff --git a/components/rgbd-sources/include/ftl/rgbd/frame.hpp b/components/rgbd-sources/include/ftl/rgbd/frame.hpp index a2ec2178987f1d2c0a3ec3a291318f9df34c9f13..aec1825035f7ecfab3daec8d1caea6ab09dd8708 100644 --- a/components/rgbd-sources/include/ftl/rgbd/frame.hpp +++ b/components/rgbd-sources/include/ftl/rgbd/frame.hpp @@ -56,6 +56,7 @@ public: /* @brief Method to get reference to the channel content * @param Channel type + * @param CUDA stream * @returns Const reference to channel data * * Result is valid only if hasChannel() is true. Host/Gpu transfer is @@ -63,10 +64,9 @@ public: * changed by calling setChannel(). Return value valid only if * hasChannel(channel) is true. */ - + template <typename T> const T& getChannel(const ftl::rgbd::channel_t& channel, cv::cuda::Stream& stream); template <typename T> const T& getChannel(const ftl::rgbd::channel_t& channel); - /* @brief Method to set/modify channel content * @param Channel type * @returns Reference to channel data @@ -113,9 +113,13 @@ private: std::vector<uint> available_; }; +template<> const cv::Mat& Frame::getChannel(const ftl::rgbd::channel_t& channel, cv::cuda::Stream& stream); +template<> const cv::cuda::GpuMat& Frame::getChannel(const ftl::rgbd::channel_t& channel, cv::cuda::Stream& stream); + template<> const cv::Mat& Frame::getChannel(const ftl::rgbd::channel_t& channel); -template<> cv::Mat& Frame::setChannel(const ftl::rgbd::channel_t& channel); template<> const cv::cuda::GpuMat& Frame::getChannel(const ftl::rgbd::channel_t& channel); + +template<> cv::Mat& Frame::setChannel(const ftl::rgbd::channel_t& channel); template<> cv::cuda::GpuMat& Frame::setChannel(const ftl::rgbd::channel_t& channel); } diff --git a/components/rgbd-sources/src/frame.cpp b/components/rgbd-sources/src/frame.cpp index ea6a94f4f98763dccf57299f606b9b9b53c8f17f..8145280cc83d24347d9bb2fc07a5a9546bbe5dd7 100644 --- a/components/rgbd-sources/src/frame.cpp +++ b/components/rgbd-sources/src/frame.cpp @@ -4,14 +4,14 @@ namespace ftl { namespace rgbd { -template<> const cv::Mat& Frame::getChannel(const ftl::rgbd::channel_t& channel) +template<> const cv::Mat& Frame::getChannel(const ftl::rgbd::channel_t& channel, cv::cuda::Stream &stream) { size_t idx = _channelIdx(channel); if (!(available_[idx] & mask_host)) { if (available_[idx] & mask_gpu) { - channels_gpu_[idx].download(channels_host_[idx]); + channels_gpu_[idx].download(channels_host_[idx], stream); available_[idx] |= mask_host; } } @@ -19,6 +19,14 @@ template<> const cv::Mat& Frame::getChannel(const ftl::rgbd::channel_t& channel) return channels_host_[idx]; } +template<> const cv::Mat& Frame::getChannel(const ftl::rgbd::channel_t& channel) +{ + auto &stream = cv::cuda::Stream::Null(); + auto &retval = getChannel<cv::Mat>(channel, stream); + stream.waitForCompletion(); + return retval; +} + template<> cv::Mat& Frame::setChannel(const ftl::rgbd::channel_t& channel) { size_t idx = _channelIdx(channel); @@ -26,14 +34,14 @@ template<> cv::Mat& Frame::setChannel(const ftl::rgbd::channel_t& channel) return channels_host_[idx]; } -template<> const cv::cuda::GpuMat& Frame::getChannel(const ftl::rgbd::channel_t& channel) +template<> const cv::cuda::GpuMat& Frame::getChannel(const ftl::rgbd::channel_t& channel, cv::cuda::Stream &stream) { size_t idx = _channelIdx(channel); if (!(available_[idx] & mask_gpu)) { if (available_[idx] & mask_host) { - channels_gpu_[idx].upload(channels_host_[idx]); + channels_gpu_[idx].upload(channels_host_[idx], stream); available_[idx] |= mask_gpu; } } @@ -41,6 +49,14 @@ template<> const cv::cuda::GpuMat& Frame::getChannel(const ftl::rgbd::channel_t& return channels_gpu_[idx]; } +template<> const cv::cuda::GpuMat& Frame::getChannel(const ftl::rgbd::channel_t& channel) +{ + auto &stream = cv::cuda::Stream::Null(); + auto &retval = getChannel<cv::cuda::GpuMat>(channel, stream); + stream.waitForCompletion(); + return retval; +} + template<> cv::cuda::GpuMat& Frame::setChannel(const ftl::rgbd::channel_t& channel) { size_t idx = _channelIdx(channel); diff --git a/components/rgbd-sources/src/offilter.cpp b/components/rgbd-sources/src/offilter.cpp index 913dc5ec506b794d8bc0cd35e35f4a74bbf1cd8e..03db4807a7f9fa045708d3cf17bf32556b7bf5b5 100644 --- a/components/rgbd-sources/src/offilter.cpp +++ b/components/rgbd-sources/src/offilter.cpp @@ -16,7 +16,8 @@ template<typename T> static bool inline isValidDisparity(T d) { return (0.0 < d) OFDisparityFilter::OFDisparityFilter(Size size, int n_frames, float threshold) : n_(0), n_max_(n_frames), threshold_(threshold), size_(size) { - disp_ = Mat::zeros(size, CV_64FC(n_frames)); + + disp_ = Mat::zeros(cv::Size(size.width * n_frames, size.height), CV_64FC1); gray_ = Mat::zeros(size, CV_8UC1); nvof_ = cv::cuda::NvidiaOpticalFlow_1_0::create(size.width, size.height, diff --git a/components/rgbd-sources/src/stereovideo.cpp b/components/rgbd-sources/src/stereovideo.cpp index 5a1ecfdb6a0319dc535e9e50e8ce8f6a102d1876..58ad0d923a6984ae75923bd2665e7db7909c8b54 100644 --- a/components/rgbd-sources/src/stereovideo.cpp +++ b/components/rgbd-sources/src/stereovideo.cpp @@ -61,13 +61,11 @@ void StereoVideoSource::init(const string &file) frames_ = std::vector<Frame>(2); #ifdef HAVE_OPTFLOW -/* - // TODO make optional, can be calculated at later step + // TODO could be calculated at later step too if have access to old frames nvof_ = cv::cuda::NvidiaOpticalFlow_1_0::create(size.width, size.height, cv::cuda::NvidiaOpticalFlow_1_0::NV_OF_PERF_LEVEL_SLOW, true, false, false, 0); -*/ #endif calib_ = ftl::create<Calibrate>(host_, "calibration", size, stream_); diff --git a/components/rgbd-sources/src/stereovideo.hpp b/components/rgbd-sources/src/stereovideo.hpp index cfbe9f5ef77e39ac539452b765255a0f5e9d93e9..2f9fa1831ce3871b115d7452efbdc7aec9a0ec4f 100644 --- a/components/rgbd-sources/src/stereovideo.hpp +++ b/components/rgbd-sources/src/stereovideo.hpp @@ -41,6 +41,7 @@ class StereoVideoSource : public detail::Source { Disparity *disp_; bool ready_; + bool use_optflow_; cv::cuda::Stream stream_; cv::cuda::Stream stream2_; @@ -50,7 +51,7 @@ class StereoVideoSource : public detail::Source { cv::Mat mask_l_; #ifdef HAVE_OPTFLOW -// cv::Ptr<cv::cuda::NvidiaOpticalFlow_1_0> nvof_; + cv::Ptr<cv::cuda::NvidiaOpticalFlow_1_0> nvof_; #endif void init(const std::string &);