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

optical flow in stereovideo

parent 93c99c43
No related branches found
No related tags found
2 merge requests!105CUDA optical flow smoothing,!103feature/frame class
Pipeline #13352 passed
......@@ -21,11 +21,13 @@ static const channel_t kChanNormals = 0x0020;
static const channel_t kChanConfidence = 0x0040;
static const channel_t kChanFlow = 0x0080;
static const channel_t kChanEnergy = 0x0100;
static const channel_t kChanLeftGray = 0x0200;
static const channel_t kChanRightGray = 0x0400;
static const channel_t kChanOverlay1 = 0x1000;
// maximum number of available channels
static const unsigned int n_channels = 11;
static const unsigned int n_channels = 13;
inline bool isFloatChannel(ftl::rgbd::channel_t chan) {
return (chan == ftl::rgbd::kChanDepth || chan == ftl::rgbd::kChanEnergy);
......
......@@ -62,7 +62,9 @@ void StereoVideoSource::init(const string &file)
#ifdef HAVE_OPTFLOW
// TODO could be calculated at later step too if have access to old frames
use_optflow_ = host_->value("use_optflow", false);
LOG(INFO) << "Using optical flow: " << (use_optflow_ ? "true" : "false");
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);
......@@ -178,22 +180,23 @@ bool StereoVideoSource::retrieve() {
lsrc_->get(left, right, calib_, stream2_);
#ifdef HAVE_OPTFLOW
/*
if (nvof_)
if (use_optflow_)
{
cv::cuda::cvtColor(frame.left, frame.left_gray, cv::COLOR_BGR2GRAY, 0, stream2_);
cv::cuda::cvtColor(frame.right, frame.right_gray, cv::COLOR_BGR2GRAY, 0, stream2_);
frame.left_gray_ready = frame.right_gray_ready = true;
auto &left_gray = frame.setChannel<cv::cuda::GpuMat>(kChanLeftGray);
auto &right_gray = frame.setChannel<cv::cuda::GpuMat>(kChanRightGray);
cv::cuda::cvtColor(left, left_gray, cv::COLOR_BGR2GRAY, 0, stream2_);
cv::cuda::cvtColor(right, right_gray, cv::COLOR_BGR2GRAY, 0, stream2_);
if (frames_[1].left_gray_ready)
if (frames_[1].hasChannel(kChanLeftGray))
{
nvof_->calc(frame.left_gray, frames_[1].left_gray, frame.optflow_, stream2_);
auto &left_gray_prev = frame.getChannel<cv::cuda::GpuMat>(kChanLeftGray, stream2_);
auto &optflow = frame.setChannel<cv::cuda::GpuMat>(kChanFlow);
nvof_->calc(left_gray, left_gray_prev, optflow_, stream2_);
// nvof_->upSampler() isn't implemented with CUDA
cv::cuda::resize(frame.optflow_, frame.optflow, frame.left.size(), 0.0, 0.0, cv::INTER_NEAREST, stream2_);
frame.optflow_ready = true;
cv::cuda::resize(optflow_, optflow, left.size(), 0.0, 0.0, cv::INTER_NEAREST, stream2_);
}
}
*/
#endif
stream2_.waitForCompletion();
......
......@@ -52,6 +52,7 @@ class StereoVideoSource : public detail::Source {
#ifdef HAVE_OPTFLOW
cv::Ptr<cv::cuda::NvidiaOpticalFlow_1_0> nvof_;
cv::cuda::GpuMat optflow_;
#endif
void init(const std::string &);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment