JeVoisBase  1.20
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
FastOpticalFlow.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
21 #include <jevois/Debug/Profiler.H>
22 #include <opencv2/core/core.hpp>
23 
24 namespace fastopticalflow
25 {
26  static jevois::ParameterCategory const ParamCateg("Fast Optical Flow Options");
27 
28  //! Parameter \relates FastOpticalFlow
29  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(opoint, int, "Algorithm operating point",
30  1, jevois::Range<int>(1, 4), ParamCateg);
31 
32  //! Parameter \relates FastOpticalFlow
33  JEVOIS_DECLARE_PARAMETER(factor, float, "Factor to use when converting float velocities to byte",
34  25.0F, ParamCateg);
35 
36  //! Parameter \relates FastOpticalFlow
37  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(thetasf, int, "Finest scale in the pyramid, or -1 for auto",
38  -1, ParamCateg);
39 
40  //! Parameter \relates FastOpticalFlow
41  JEVOIS_DECLARE_PARAMETER(thetait, int, "Number of gradient descent iterations, or -1 for auto",
42  5, ParamCateg);
43 
44  //! Parameter \relates FastOpticalFlow
45  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(thetaps, int, "Patch size in pixels, or -1 for auto",
46  -1, ParamCateg);
47 
48  //! Parameter \relates FastOpticalFlow
49  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(thetaov, float, "Patch overlap on each scale, or -1 for auto",
50  0.1F, ParamCateg);
51 
52  //! Parameter \relates FastOpticalFlow
53  JEVOIS_DECLARE_PARAMETER(usevref, bool, "Use variational refinement when true",
54  false, ParamCateg);
55 }
56 
57 //! Fast optical flow computation using dense inverse search
58 /*! This algorithm computes what moved between two images (optical flow). It is based on the paper "Fast Optical Flow
59  using Dense Inverse Search" by Till Kroeger, Radu Timofte, Dengxin Dai and Luc Van Gool, Proc ECCV, 2016. Also see
60  here: http://www.vision.ee.ethz.ch/~kroegert/OFlow/ \ingroup components */
62  public jevois::Parameter<fastopticalflow::opoint, fastopticalflow::factor,
63  fastopticalflow::thetasf, fastopticalflow::thetait,
64  fastopticalflow::thetaps, fastopticalflow::thetaov,
65  fastopticalflow::usevref>
66 {
67  public:
68  //! Constructor
69  FastOpticalFlow(std::string const & instance);
70 
71  //! Destructor
72  virtual ~FastOpticalFlow();
73 
74  //! Process a greyscale image and return flow in a pre-allocated greyscale image of same with and 2x height
75  /*! The results are the concatenation of 2 images: vx on top of vy, both converted to byte. */
76  void process(cv::Mat const & src, cv::Mat & dst);
77 
78  protected:
79  void onParamChange(fastopticalflow::opoint const & param, int const & val) override;
80  void onParamChange(fastopticalflow::thetasf const & param, int const & val) override;
81  void onParamChange(fastopticalflow::thetaps const & param, int const & val) override;
82  void onParamChange(fastopticalflow::thetaov const & param, float const & val) override;
83 
85  std::mutex itsMtx;
86 
87  bool itsNuke; // nuke all caches when some sizes or params change
88 
89  const float ** img_bo_pyr; // those are just shallow pointers to the cv::Mat versions, no memory alloc
90  const float ** img_bo_dx_pyr;
91  const float ** img_bo_dy_pyr;
92 
93  cv::Mat * img_bo_fmat_pyr;
94  cv::Mat * img_bo_dx_fmat_pyr;
95  cv::Mat * img_bo_dy_fmat_pyr;
96 
97  cv::Mat img_bo_mat;
98  cv::Mat img_bo_fmat;
99 
102 };
Profiler.H
jevois::Range
FastOpticalFlow::itsProfiler
jevois::Profiler itsProfiler
Definition: FastOpticalFlow.H:84
FastOpticalFlow::~FastOpticalFlow
virtual ~FastOpticalFlow()
Destructor.
Definition: FastOpticalFlow.C:36
JEVOIS_DECLARE_PARAMETER
JEVOIS_DECLARE_PARAMETER(thresh1, double, "First threshold for hysteresis", 50.0, ParamCateg)
FastOpticalFlow::img_bo_dx_fmat_pyr
cv::Mat * img_bo_dx_fmat_pyr
Definition: FastOpticalFlow.H:94
jevois::Component
fastopticalflow
Definition: FastOpticalFlow.H:24
FastOpticalFlow::itsHeight
int itsHeight
Definition: FastOpticalFlow.H:100
jevois::ParameterCategory
FastOpticalFlow
Fast optical flow computation using dense inverse search.
Definition: FastOpticalFlow.H:61
FastOpticalFlow::img_bo_mat
cv::Mat img_bo_mat
Definition: FastOpticalFlow.H:97
F
float F
FastOpticalFlow::img_bo_fmat
cv::Mat img_bo_fmat
Definition: FastOpticalFlow.H:98
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(l2grad, bool, "Use more accurate L2 gradient norm if true, L1 if false", false, ParamCateg)
FastOpticalFlow::onParamChange
void onParamChange(fastopticalflow::opoint const &param, int const &val) override
Component.H
FastOpticalFlow::img_bo_fmat_pyr
cv::Mat * img_bo_fmat_pyr
Definition: FastOpticalFlow.H:93
jevois::Profiler
FastOpticalFlow::itsPyrDepth
int itsPyrDepth
Definition: FastOpticalFlow.H:101
FastOpticalFlow::img_bo_dx_pyr
const float ** img_bo_dx_pyr
Definition: FastOpticalFlow.H:90
FastOpticalFlow::img_bo_dy_fmat_pyr
cv::Mat * img_bo_dy_fmat_pyr
Definition: FastOpticalFlow.H:95
FastOpticalFlow::itsWidth
int itsWidth
Definition: FastOpticalFlow.H:100
FastOpticalFlow::FastOpticalFlow
FastOpticalFlow(std::string const &instance)
Constructor.
Definition: FastOpticalFlow.C:29
FastOpticalFlow::itsNuke
bool itsNuke
Definition: FastOpticalFlow.H:87
FastOpticalFlow::itsMtx
std::mutex itsMtx
Definition: FastOpticalFlow.H:85
FastOpticalFlow::process
void process(cv::Mat const &src, cv::Mat &dst)
Process a greyscale image and return flow in a pre-allocated greyscale image of same with and 2x heig...
Definition: FastOpticalFlow.C:154
FastOpticalFlow::img_bo_pyr
const float ** img_bo_pyr
Definition: FastOpticalFlow.H:89
FastOpticalFlow::img_bo_dy_pyr
const float ** img_bo_dy_pyr
Definition: FastOpticalFlow.H:91