Commit 771540b2c6e7d51305fdf647a929e715dde4a925

Authored by Austin Van Blanton
1 parent 4cb891c4

Cvt to gray before OF, propagate file from src to dst

openbr/plugins/opticalflow.cpp
1 #include <opencv2/video/tracking.hpp> 1 #include <opencv2/video/tracking.hpp>
2 #include "openbr_internal.h" 2 #include "openbr_internal.h"
  3 +#include "openbr/core/opencvutils.h"
3 4
4 using namespace cv; 5 using namespace cv;
5 6
@@ -11,7 +12,7 @@ namespace br @@ -11,7 +12,7 @@ namespace br
11 * \brief Gets a one-channel dense optical flow from two images 12 * \brief Gets a one-channel dense optical flow from two images
12 * \author Austin Blanton \cite imaus10 13 * \author Austin Blanton \cite imaus10
13 */ 14 */
14 -class OpticalFlowTransform : public UntrainableTransform 15 +class OpticalFlowTransform : public UntrainableMetaTransform
15 { 16 {
16 Q_OBJECT 17 Q_OBJECT
17 Q_PROPERTY(double pyr_scale READ get_pyr_scale WRITE set_pyr_scale RESET reset_pyr_scale STORED false) 18 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 @@ -33,18 +34,19 @@ class OpticalFlowTransform : public UntrainableTransform
33 void project(const Template &src, Template &dst) const 34 void project(const Template &src, Template &dst) const
34 { 35 {
35 // get the two images put there by AggregateFrames 36 // get the two images put there by AggregateFrames
36 - Mat prevImg = src[0];  
37 - Mat nextImg = src[1];  
38 - Mat flow; 37 + if (src.size() < 2) return;
  38 + Mat prevImg = src[0], nextImg = src[1], flow, flowOneCh;
  39 + if (src[0].channels() != 1) OpenCVUtils::cvtGray(src[0], prevImg);
  40 + if (src[1].channels() != 1) OpenCVUtils::cvtGray(src[1], nextImg);
39 calcOpticalFlowFarneback(prevImg, nextImg, flow, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags); 41 calcOpticalFlowFarneback(prevImg, nextImg, flow, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags);
40 - 42 +
41 // the result is two channels 43 // the result is two channels
42 std::vector<Mat> channels(2); 44 std::vector<Mat> channels(2);
43 split(flow, channels); 45 split(flow, channels);
44 - Mat flowOneCh;  
45 magnitude(channels[0], channels[1], flowOneCh); 46 magnitude(channels[0], channels[1], flowOneCh);
46 47
47 dst += flowOneCh; 48 dst += flowOneCh;
  49 + dst.file = src.file;
48 } 50 }
49 }; 51 };
50 52