JeVoisBase  1.6
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Convert.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 #include <jevois/Debug/Log.H>
20 #include <jevois/Util/Utils.H>
22 
23 #include <linux/videodev2.h>
24 #include <opencv2/core/core.hpp>
25 #include <opencv2/imgproc/imgproc.hpp>
26 #include <string.h>
27 
28 // icon by Pixel Buddha in arrows at flaticon
29 
30 static jevois::ParameterCategory const ParamCateg("Convert Options");
31 
32 //! Parameter \relates Convert
33 JEVOIS_DECLARE_PARAMETER(quality, int, "Compression quality for MJPEG", 75, jevois::Range<int>(1, 100), ParamCateg);
34 
35 //! Simple module to convert between any supported camera grab formats and USB output formats
36 /*! This module can convert from any supported camera sensor pixel format (YUYV, BAYER, RGB565) to any supported USB
37  output pixel format (YUYV, GREY, MJPG, BAYER, RGB565, BGR24).
38 
39  See \ref PixelFormats for information about supported pixel formats.
40 
41  This module accepts any resolution supported by the JeVois camera sensor:
42 
43  - SXGA (1280 x 1024): up to 15 fps
44  - VGA (640 x 480): up to 30 fps
45  - CIF (352 x 288): up to 60 fps
46  - QVGA (320 x 240): up to 60 fps
47  - QCIF (176 x 144): up to 120 fps
48  - QQVGA (160 x 120): up to 60 fps
49  - QQCIF (88 x 72): up to 120 fps
50 
51  This module only converts pixel type, and is not capable of rescaling images. Thus, input and output image
52  resolutions must match.
53 
54  Things to try
55  -------------
56 
57  Edit <b>JEVOIS:/config/videomappings.cfg</b> on your MicroSD card (see \ref VideoMapping) and try to add some new
58  convert mappings. Not all of the thousands of possible convert mappings have been included in the card to avoid
59  having too many of these simple conversion mappings in the base software distribution. For example,
60 
61  \verbatim
62  YUYV 176 144 115.0 BAYER 176 144 115.0 JeVois Convert
63  \endverbatim
64 
65  will grab raw BAYER frames on the sensor, with resolution 176x144 at 115 frames/s, and will convert them to YUYV
66  before sending them over the USB link. To test this mapping, select the corresponding resolution and framerate in
67  your video viewing software (here, YUYV 176x144 \@ 115fps). Although the sensor can capture at up to 120fps at this
68  resolution, here we used 115fps to avoid a conflict with a mapping using YUYV 176x144 \@ 120fps USB output and the
69  SaveVideo module that is already in the default \b videomappings.cfg file.
70 
71  Note that this module may suffer from DMA coherency artifacts if the \p camturbo parameter of the jevois::Engine is
72  turned on, which it is by default. The \p camturbo parameter relaxes some of the cache coherency constraints on the
73  video buffers captured by the camera sensor, which allows the JeVois processor to access video pixel data from
74  memory faster. But with modules that do not do much processing, sometimes this yields video artifacts, we presume
75  because some of the video data from previous frames still is in the CPU cache and hence is not again fetched from
76  main memory by the CPU. If you see short stripes of what appears to be wrong pixel colors in the video, try to
77  disable \p camturbo by editing <b>JEVOIS:/config/params.cfg</b> on your MicroSD card and in there turning \p
78  camturbo to false.
79 
80 
81  @author Laurent Itti
82 
83  @videomapping BAYER 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
84  @videomapping BGR24 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
85  @videomapping GREY 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
86  @videomapping RGB565 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
87  @videomapping MJPG 352 288 60.0 BAYER 352 288 60.0 JeVois Convert
88  @videomapping MJPG 320 240 30.0 RGB565 320 240 30.0 JeVois Convert
89  @videomapping MJPG 320 240 15.0 YUYV 320 240 15.0 JeVois Convert
90  @videomapping YUYV 640 480 20.0 YUYV 640 480 20.0 JeVois Convert
91  @email itti\@usc.edu
92  @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
93  @copyright Copyright (C) 2016 by Laurent Itti, iLab and the University of Southern California
94  @mainurl http://jevois.org
95  @supporturl http://jevois.org/doc
96  @otherurl http://iLab.usc.edu
97  @license GPL v3
98  @distribution Unrestricted
99  @restrictions None
100  \ingroup modules */
101 class Convert : public jevois::Module, public jevois::Parameter<quality>
102 {
103  public:
104  //! Default base class constructor ok
106 
107  //! Virtual destructor for safe inheritance
108  virtual ~Convert() { }
109 
110  //! Processing function
111  virtual void process(jevois::InputFrame && inframe, jevois::OutputFrame && outframe) override
112  {
113  // Wait for next available camera image:
114  jevois::RawImage inimg = inframe.get(true);
115  unsigned int const w = inimg.width, h = inimg.height;
116 
117  // Convert it to BGR24:
118  cv::Mat imgbgr = jevois::rawimage::convertToCvBGR(inimg);
119 
120  // Let camera know we are done processing the input image:
121  inframe.done();
122 
123  // Wait for an image from our gadget driver into which we will put our results:
124  jevois::RawImage outimg = outframe.get();
125 
126  // Require that output has same dims as input, allow any output format:
127  outimg.require("output", w, h, outimg.fmt);
128 
129  // Convert from BGR to desired output format:
130  jevois::rawimage::convertCvBGRtoRawImage(imgbgr, outimg, quality::get());
131 
132  // Send the output image with our processing results to the host over USB:
133  outframe.send();
134  }
135 };
136 
137 // Allow the module to be loaded as a shared object (.so) file:
Simple module to convert between any supported camera grab formats and USB output formats...
Definition: Convert.C:101
JEVOIS_REGISTER_MODULE(Convert)
friend friend class Module
cv::Mat convertToCvBGR(RawImage const &src)
unsigned int height
unsigned int fmt
virtual ~Convert()
Virtual destructor for safe inheritance.
Definition: Convert.C:108
void convertCvBGRtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
JEVOIS_DECLARE_PARAMETER(camparams, std::string, "File stem of camera parameters, or empty. Camera resolution " "will be appended, as well as a .cfg extension. For example, specifying 'camera_para' " "here and running the camera sensor at 320x240 will attempt to load " "camera_para320x240.dat from within the module's directory.", "camera_para", ParamCateg)
Parameter.
unsigned int width
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function.
Definition: Convert.C:111
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const