JeVoisBase  1.0
JeVois Smart Embedded Machine Vision Toolkit Base Modules
OpticalFlow.C
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 #include <jevois/Core/Module.H>
20 
22 
23 #include <linux/videodev2.h>
24 
25 // icon by Gregor Cresnar in arrows at flaticon
26 
27 //! Fast optical flow computation using OF_DIS
28 /*! Computes horizontal and vertical optical flow into two separate optical flow maps. This module is intended for uas
29  as a pre-processor, that is, the images sent out may be further processed by the host computer.
30 
31  The optical flow image output is twoce taller than the camera input image. On top is the horisontal motion map
32  (darker shades for things moving rightward from the viewpoint of the camera, lighter for leftward, mid-grey level
33  for no motion), and below it is the vertical motion map (dark for things moving down, bright for up).
34 
35  @author Laurent Itti
36 
37  @videomapping GREY 176 288 100 YUYV 176 144 100 JeVois OpticalFlow
38  @email itti\@usc.edu
39  @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
40  @copyright Copyright (C) 2016 by Laurent Itti, iLab and the University of Southern California
41  @mainurl http://jevois.org
42  @supporturl http://jevois.org/doc
43  @otherurl http://iLab.usc.edu
44  @license GPL v3
45  @distribution Unrestricted
46  @restrictions None
47  \ingroup modules */
49 {
50  public:
51  //! Constructor
52  OpticalFlow(std::string const & instance) : jevois::Module(instance)
53  { itsOpticalFlow = addSubComponent<FastOpticalFlow>("fastflow"); }
54 
55  //! Virtual destructor for safe inheritance
56  virtual ~OpticalFlow() { }
57 
58  //! Processing function
59  virtual void process(jevois::InputFrame && inframe, jevois::OutputFrame && outframe) override
60  {
61  // Wait for next available camera image:
62  jevois::RawImage inimg = inframe.get(); unsigned int const w = inimg.width, h = inimg.height;
63 
64  // Convert to openCV grayscale:
65  cv::Mat cvimg = jevois::rawimage::convertToCvGray(inimg);
66 
67  // Let camera know we are done processing the input image:
68  inframe.done();
69 
70  // Get the output image and require same width as input, 2x taller, and grey pixels:
71  jevois::RawImage outimg = outframe.get();
72  outimg.require("output", w, h * 2, V4L2_PIX_FMT_GREY);
73 
74  // Process the input and get output:
75  cv::Mat cvout = jevois::rawimage::cvImage(outimg); // cvout's pixels point to outimg's, no copy
76  itsOpticalFlow->process(cvimg, cvout);
77 
78  // Send the output image with our processing results to the host over USB:
79  outframe.send();
80  }
81 
82  private:
83  std::shared_ptr<FastOpticalFlow> itsOpticalFlow;
84 };
85 
86 // Allow the module to be loaded as a shared object (.so) file:
cv::Mat cvImage(RawImage const &src)
friend friend class Module
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
unsigned int height
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function.
Definition: OpticalFlow.C:59
virtual ~OpticalFlow()
Virtual destructor for safe inheritance.
Definition: OpticalFlow.C:56
OpticalFlow(std::string const &instance)
Constructor.
Definition: OpticalFlow.C:52
cv::Mat convertToCvGray(RawImage const &src)
JEVOIS_REGISTER_MODULE(OpticalFlow)
Fast optical flow computation using OF_DIS.
Definition: OpticalFlow.C:48
unsigned int width