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 PassThrough mode as input, to simulate what will happen when your code runs on the JeVois
29  embedded processor.
30 
31  Any video mapping is possible here, as long as camera and USB pixel types match, and camera and USB image dimensions
32  also match.
33 
34  @author Laurent Itti
35 
36  @videomapping YUYV 1280 1024 7.5 YUYV 1280 1024 7.5 JeVois PassThrough
37  @videomapping YUYV 640 480 30.0 YUYV 640 480 30.0 JeVois SaveVideo
38  @videomapping YUYV 640 480 19.6 YUYV 640 480 19.6 JeVois PassThrough
39  @videomapping YUYV 640 480 12.0 YUYV 640 480 12.0 JeVois PassThrough
40  @videomapping YUYV 640 480 8.3 YUYV 640 480 8.3 JeVois PassThrough
41  @videomapping YUYV 640 480 7.5 YUYV 640 480 7.5 JeVois PassThrough
42  @videomapping YUYV 640 480 5.5 YUYV 640 480 5.5 JeVois PassThrough
43  @email itti\@usc.edu
44  @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
45  @copyright Copyright (C) 2016 by Laurent Itti, iLab and the University of Southern California
46  @mainurl http://jevois.org
47  @supporturl http://jevois.org/doc
48  @otherurl http://iLab.usc.edu
49  @license GPL v3
50  @distribution Unrestricted
51  @restrictions None
52  \ingroup modules */
54 {
55  public:
56  //! Default base class constructor ok
58 
59  //! Virtual destructor for safe inheritance
60  virtual ~PassThrough() { }
61 
62  //! Processing function
63  virtual void process(jevois::InputFrame && inframe, jevois::OutputFrame && outframe) override
64  {
65  // Wait for next available camera image:
66  jevois::RawImage const inimg = inframe.get(true);
67 
68  // Wait for an image from our gadget driver into which we will put our results:
69  jevois::RawImage outimg = outframe.get();
70 
71  // Enforce that the input and output formats and image sizes match:
72  outimg.require("output", inimg.width, inimg.height, inimg.fmt);
73 
74  // Just copy the pixel data over:
75  memcpy(outimg.pixelsw<void>(), inimg.pixels<void>(), std::min(inimg.buf->length(), outimg.buf->length()));
76 
77  // Camera outputs RGB565 in big-endian, but most video grabbers expect little-endian:
78  if (outimg.fmt == V4L2_PIX_FMT_RGB565) jevois::rawimage::byteSwap(outimg);
79 
80  // Let camera know we are done processing the input image:
81  inframe.done(); // NOTE: optional here, inframe destructor would call it anyway
82 
83  // Send the output image with our processing results to the host over USB:
84  outframe.send(); // NOTE: optional here, outframe destructor would call it anyway
85  }
86 };
87 
88 // 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:53
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:63
void byteSwap(RawImage &img)
unsigned int width
virtual ~PassThrough()
Virtual destructor for safe inheritance.
Definition: PassThrough.C:60