JeVoisBase  1.0
JeVois Smart Embedded Machine Vision Toolkit Base Modules
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). Note that it only converts pixel type, and is not
38  capable of resizing the image. Thus, input and output image dimensions must match.
39 
40  @author Laurent Itti
41 
42  @videomapping BAYER 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
43  @videomapping BGR24 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
44  @videomapping GREY 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
45  @videomapping RGB565 640 480 26.8 YUYV 640 480 26.8 JeVois Convert
46  @videomapping MJPG 352 288 60.0 BAYER 352 288 60.0 JeVois Convert
47  @videomapping MJPG 320 240 30.0 RGB565 320 240 30.0 JeVois Convert
48  @videomapping MJPG 320 240 15.0 YUYV 320 240 15.0 JeVois Convert
49  @videomapping YUYV 640 500 20.0 YUYV 640 480 20.0 JeVois DemoArUco
50  @email itti\@usc.edu
51  @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
52  @copyright Copyright (C) 2016 by Laurent Itti, iLab and the University of Southern California
53  @mainurl http://jevois.org
54  @supporturl http://jevois.org/doc
55  @otherurl http://iLab.usc.edu
56  @license GPL v3
57  @distribution Unrestricted
58  @restrictions None
59  \ingroup modules */
60 class Convert : public jevois::Module, public jevois::Parameter<quality>
61 {
62  public:
63  //! Default base class constructor ok
65 
66  //! Virtual destructor for safe inheritance
67  virtual ~Convert() { }
68 
69  //! Processing function
70  virtual void process(jevois::InputFrame && inframe, jevois::OutputFrame && outframe) override
71  {
72  // Wait for next available camera image:
73  jevois::RawImage inimg = inframe.get(true);
74  unsigned int const w = inimg.width, h = inimg.height;
75 
76  // Convert it to BGR24:
77  cv::Mat imgbgr = jevois::rawimage::convertToCvBGR(inimg);
78 
79  // Let camera know we are done processing the input image:
80  inframe.done();
81 
82  // Wait for an image from our gadget driver into which we will put our results:
83  jevois::RawImage outimg = outframe.get();
84 
85  // Require that output has same dims as input, allow any output format:
86  outimg.require("output", w, h, outimg.fmt);
87 
88  // Convert from BGR to desired output format:
89  jevois::rawimage::convertCvBGRtoRawImage(imgbgr, outimg, quality::get());
90 
91  // Send the output image with our processing results to the host over USB:
92  outframe.send();
93  }
94 };
95 
96 // 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:60
JEVOIS_REGISTER_MODULE(Convert)
friend friend class Module
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
cv::Mat convertToCvBGR(RawImage const &src)
unsigned int height
#define JEVOIS_DECLARE_PARAMETER(ParamName, ParamType,...)
Parameter.
unsigned int fmt
virtual ~Convert()
Virtual destructor for safe inheritance.
Definition: Convert.C:67
void convertCvBGRtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
unsigned int width
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function.
Definition: Convert.C:70