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