JeVoisBase  1.20
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 also automatically rescales the image if input and output sizes differ.
52 
53  Things to try
54  -------------
55 
56  Edit <b>JEVOIS:/config/videomappings.cfg</b> on your MicroSD card (see \ref VideoMapping) and try to add some new
57  convert mappings. Not all of the thousands of possible convert mappings have been included in the card to avoid
58  having too many of these simple conversion mappings in the base software distribution. For example,
59 
60  \verbatim
61  YUYV 176 144 115.0 BAYER 176 144 115.0 JeVois Convert
62  \endverbatim
63 
64  will grab raw BAYER frames on the sensor, with resolution 176x144 at 115 frames/s, and will convert them to YUYV
65  before sending them over the USB link. To test this mapping, select the corresponding resolution and framerate in
66  your video viewing software (here, YUYV 176x144 \@ 115fps). Although the sensor can capture at up to 120fps at this
67  resolution, here we used 115fps to avoid a conflict with a mapping using YUYV 176x144 \@ 120fps USB output and the
68  SaveVideo module that is already in the default \b videomappings.cfg file.
69 
70  Note that this module may suffer from DMA coherency artifacts if the \p camturbo parameter of the jevois::Engine is
71  turned on, which it is by default. The \p camturbo parameter relaxes some of the cache coherency constraints on the
72  video buffers captured by the camera sensor, which allows the JeVois processor to access video pixel data from
73  memory faster. But with modules that do not do much processing, sometimes this yields video artifacts, we presume
74  because some of the video data from previous frames still is in the CPU cache and hence is not again fetched from
75  main memory by the CPU. If you see short stripes of what appears to be wrong pixel colors in the video, try to
76  disable \p camturbo by editing <b>JEVOIS:/config/params.cfg</b> on your MicroSD card and in there turning \p
77  camturbo to false.
78 
79 
80  @author Laurent Itti
81 
82  @videomapping BAYER 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
83  @videomapping BGR24 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
84  @videomapping GREY 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
85  @videomapping RGB565 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
86  @videomapping MJPG 352 288 60.0 BAYER 352 288 60.0 JeVois Convert
87  @videomapping MJPG 320 240 30.0 RGB565 320 240 30.0 JeVois Convert
88  @videomapping MJPG 320 240 15.0 YUYV 320 240 15.0 JeVois Convert
89  @videomapping YUYV 640 480 20.0 YUYV 640 480 20.0 JeVois Convert
90  @email itti\@usc.edu
91  @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
92  @copyright Copyright (C) 2016 by Laurent Itti, iLab and the University of Southern California
93  @mainurl http://jevois.org
94  @supporturl http://jevois.org/doc
95  @otherurl http://iLab.usc.edu
96  @license GPL v3
97  @distribution Unrestricted
98  @restrictions None
99  \ingroup modules */
100 class Convert : public jevois::Module, public jevois::Parameter<quality>
101 {
102  public:
103  //! Default base class constructor ok
105 
106  //! Virtual destructor for safe inheritance
107  virtual ~Convert() { }
108 
109  //! Processing function
110  virtual void process(jevois::InputFrame && inframe, jevois::OutputFrame && outframe) override
111  {
112  // Wait for next available camera image, convert it to OpenCV BGR:
113  cv::Mat imgbgr = inframe.getCvBGR();
114 
115  // Send the output image to the host over USB, after possible format conversion and size scaling:
116  outframe.sendCv(imgbgr, quality::get());
117  }
118 };
119 
120 // Allow the module to be loaded as a shared object (.so) file:
jevois::Range
jevois::OutputFrame
Convert::process
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function.
Definition: Convert.C:110
Module.H
JEVOIS_REGISTER_MODULE
JEVOIS_REGISTER_MODULE(Convert)
Log.H
Convert::~Convert
virtual ~Convert()
Virtual destructor for safe inheritance.
Definition: Convert.C:107
Convert
Simple module to convert between any supported camera grab formats and USB output formats.
Definition: Convert.C:100
jevois::ParameterCategory
jevois::Module
RawImageOps.H
jevois::InputFrame
Utils.H
ARtoolkit::JEVOIS_DECLARE_PARAMETER
JEVOIS_DECLARE_PARAMETER(camparams, std::string, "File stem of camera parameters, or empty. Camera resolution " "will be appended, as well as a .dat 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 (if relative stem) or " "from the specified absolute location (if absolute stem).", JEVOIS_SHARE_PATH "/camera/camera_para", ParamCateg)
Parameter.
jevois::Component::Module
friend friend class Module