JeVoisBase  1.5
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
PassThrough.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>
19 
21 #include <linux/videodev2.h>
22 
23 // icon by Catalin Fertu in cinema at flaticon
24 
25 //! Simple module that just passes the captured camera frames through to USB host
26 /*! This module makes your JeVois smart camera operate like a regular "dumb" camera. It is intended mainly for use in
27  programming tutorials, and to allow you to debug new machine vision modules that you test on your host computer,
28  using the JeVois camera in pass-through mode as input, to simulate what will happen when your code runs on the
29  JeVois embedded processor.
30 
31  Any video mapping is possible here, as long as camera and USB pixel types match, and camera and USB image
32  resolutions also match.
33 
34  See \ref PixelFormats for information about pixel formats; with this module you can use the formats supported by the
35  camera sensor: YUYV, BAYER, RGB565, and resolutions:
36 
37  - SXGA (1280 x 1024): up to 15 fps
38  - VGA (640 x 480): up to 30 fps
39  - CIF (352 x 288): up to 60 fps
40  - QVGA (320 x 240): up to 60 fps
41  - QCIF (176 x 144): up to 120 fps
42  - QQVGA (160 x 120): up to 60 fps
43  - QQCIF (88 x 72): up to 120 fps
44 
45  Things to try
46  -------------
47 
48  Edit <b>JEVOIS:/config/videomappings.cfg</b> on your MicroSD card (see \ref VideoMapping) and try to add some new
49  pass-through mappings. Not all of the possible pass-through mappings have been included in the card to avoid having
50  too many of these simple "dumb camera" mappings in the base software distribution. For example, you can try
51 
52  \verbatim
53  YUYV 176 144 115.0 YUYV 176 144 115.0 JeVois PassThrough
54  \endverbatim
55 
56  will grab YUYV frames on the sensor, with resolution 176x144 at 115 frames/s, and will directly send them to the
57  host computer over the USB link. To test this mapping, select the corresponding resolution and framerate in your
58  video viewing software (here, YUYV 176x144 \@ 115fps). Although the sensor can capture at up to 120fps at this
59  resolution, here we used 115fps to avoid a conflict with a mapping using YUYV 176x144 \@ 120fps USB output and the
60  \jvmod{SaveVideo} module that is already in the default <b>videomappings.cfg</b> file.
61 
62  Note that this module may suffer from DMA coherency artifacts if the \p camturbo parameter of the jevois::Engine is
63  turned on, which it is by default. The \p camturbo parameter relaxes some of the cache coherency constraints on the
64  video buffers captured by the camera sensor, which allows the JeVois processor to access video pixel data from
65  memory faster. But with modules that do not do much processing, sometimes this yields video artifacts, we presume
66  because some of the video data from previous frames still is in the CPU cache and hence is not again fetched from
67  main memory by the CPU. If you see short stripes of what appears to be wrong pixel colors in the video, try to
68  disable \p camturbo, by editing <b>JEVOIS:/config/params.cfg</b> on your MicroSD card and in there turning \p
69  camturbo to false.
70 
71 
72  @author Laurent Itti
73 
74  @videomapping YUYV 1280 1024 7.5 YUYV 1280 1024 7.5 JeVois PassThrough
75  @videomapping YUYV 640 480 30.0 YUYV 640 480 30.0 JeVois PassThrough
76  @videomapping YUYV 640 480 19.6 YUYV 640 480 19.6 JeVois PassThrough
77  @videomapping YUYV 640 480 12.0 YUYV 640 480 12.0 JeVois PassThrough
78  @videomapping YUYV 640 480 8.3 YUYV 640 480 8.3 JeVois PassThrough
79  @videomapping YUYV 640 480 7.5 YUYV 640 480 7.5 JeVois PassThrough
80  @videomapping YUYV 640 480 5.5 YUYV 640 480 5.5 JeVois PassThrough
81  @email itti\@usc.edu
82  @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
83  @copyright Copyright (C) 2016 by Laurent Itti, iLab and the University of Southern California
84  @mainurl http://jevois.org
85  @supporturl http://jevois.org/doc
86  @otherurl http://iLab.usc.edu
87  @license GPL v3
88  @distribution Unrestricted
89  @restrictions None
90  \ingroup modules */
92 {
93  public:
94  //! Default base class constructor ok
96 
97  //! Virtual destructor for safe inheritance
98  virtual ~PassThrough() { }
99 
100  //! Processing function
101  virtual void process(jevois::InputFrame && inframe, jevois::OutputFrame && outframe) override
102  {
103  // Wait for next available camera image:
104  jevois::RawImage const inimg = inframe.get(true);
105 
106  // Wait for an image from our gadget driver into which we will put our results:
107  jevois::RawImage outimg = outframe.get();
108 
109  // Enforce that the input and output formats and image sizes match:
110  outimg.require("output", inimg.width, inimg.height, inimg.fmt);
111 
112  // Just copy the pixel data over:
113  memcpy(outimg.pixelsw<void>(), inimg.pixels<void>(), std::min(inimg.buf->length(), outimg.buf->length()));
114 
115  // Camera outputs RGB565 in big-endian, but most video grabbers expect little-endian:
116  if (outimg.fmt == V4L2_PIX_FMT_RGB565) jevois::rawimage::byteSwap(outimg);
117 
118  // Let camera know we are done processing the input image:
119  inframe.done(); // NOTE: optional here, inframe destructor would call it anyway
120 
121  // Send the output image with our processing results to the host over USB:
122  outframe.send(); // NOTE: optional here, outframe destructor would call it anyway
123  }
124 };
125 
126 // Allow the module to be loaded as a shared object (.so) file:
Simple module that just passes the captured camera frames through to USB host.
Definition: PassThrough.C:91
friend friend class Module
unsigned int height
unsigned int fmt
std::shared_ptr< VideoBuf > buf
JEVOIS_REGISTER_MODULE(PassThrough)
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function.
Definition: PassThrough.C:101
T const * pixels() const
void byteSwap(RawImage &img)
unsigned int width
virtual ~PassThrough()
Virtual destructor for safe inheritance.
Definition: PassThrough.C:98
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const