From 771540b2c6e7d51305fdf647a929e715dde4a925 Mon Sep 17 00:00:00 2001 From: Austin Van Blanton Date: Mon, 5 Aug 2013 14:41:20 -0400 Subject: [PATCH] Cvt to gray before OF, propagate file from src to dst --- openbr/plugins/opticalflow.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/openbr/plugins/opticalflow.cpp b/openbr/plugins/opticalflow.cpp index f5fde4b..5246ad5 100644 --- a/openbr/plugins/opticalflow.cpp +++ b/openbr/plugins/opticalflow.cpp @@ -1,5 +1,6 @@ #include #include "openbr_internal.h" +#include "openbr/core/opencvutils.h" using namespace cv; @@ -11,7 +12,7 @@ namespace br * \brief Gets a one-channel dense optical flow from two images * \author Austin Blanton \cite imaus10 */ -class OpticalFlowTransform : public UntrainableTransform +class OpticalFlowTransform : public UntrainableMetaTransform { Q_OBJECT Q_PROPERTY(double pyr_scale READ get_pyr_scale WRITE set_pyr_scale RESET reset_pyr_scale STORED false) @@ -33,18 +34,19 @@ class OpticalFlowTransform : public UntrainableTransform void project(const Template &src, Template &dst) const { // get the two images put there by AggregateFrames - Mat prevImg = src[0]; - Mat nextImg = src[1]; - Mat flow; + if (src.size() < 2) return; + Mat prevImg = src[0], nextImg = src[1], flow, flowOneCh; + if (src[0].channels() != 1) OpenCVUtils::cvtGray(src[0], prevImg); + if (src[1].channels() != 1) OpenCVUtils::cvtGray(src[1], nextImg); calcOpticalFlowFarneback(prevImg, nextImg, flow, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags); - + // the result is two channels std::vector channels(2); split(flow, channels); - Mat flowOneCh; magnitude(channels[0], channels[1], flowOneCh); dst += flowOneCh; + dst.file = src.file; } }; -- libgit2 0.21.4