Skip to content
Snippets Groups Projects
Commit 93c99c43 authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

frame: sync/async versions (CUDA streams)

parent 3d6409d8
No related branches found
No related tags found
2 merge requests!105CUDA optical flow smoothing,!103feature/frame class
Pipeline #13348 passed
......@@ -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);
}
......
......@@ -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);
......
......@@ -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,
......
......@@ -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_);
......
......@@ -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 &);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment