JeVois  1.10
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
PythonSupport.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 <boost/python.hpp>
19 
21 #include <jevois/Core/Engine.H>
22 #include <jevois/Image/RawImage.H>
27 #include <jevois/Core/Serial.H>
28 #include <jevois/Util/Utils.H>
30 #include <jevois/Debug/Log.H>
31 #include <jevois/Debug/Timer.H>
32 #include <jevois/Debug/Profiler.H>
33 #include <jevois/Debug/SysInfo.H>
34 
35 #define PY_ARRAY_UNIQUE_SYMBOL pbcvt_ARRAY_API
37 
38 // ####################################################################################################
39 //! Convenience macro to define a Python binding for a free function in the jevois namespace
40 #define JEVOIS_PYTHON_FUNC(funcname) \
41  boost::python::def(#funcname, jevois::funcname)
42 
43 //! Convenience macro to define a Python binding for a free function in the jevois::rawimage namespace
44 #define JEVOIS_PYTHON_RAWIMAGE_FUNC(funcname) \
45  boost::python::def(#funcname, jevois::rawimage::funcname)
46 
47 //! Convenience macro to define a python enum value where the value is in jevois::rawimage
48 #define JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(val) value(#val, jevois::rawimage::val)
49 
50 //! Convenience macro to define a python enum value where the value is in jevois::python
51 #define JEVOIS_PYTHON_ENUM_VAL(val) value(#val, jevois::python::val)
52 
53 //! Convenience macro to define a constant that exists in the global C++ namespace
54 #define JEVOIS_PYTHON_CONSTANT(cst) boost::python::scope().attr(#cst) = cst;
55 
56 
57 // ####################################################################################################
58 // Helper to provide jevois.sendSerial() function that emulates a C++ module's sendSerial()
59 namespace jevois
60 {
61  namespace python
62  {
64  }
65 }
66 namespace
67 {
68  void * init_numpy()
69  {
70  // Initialize Python:
71  Py_SetProgramName(Py_DecodeLocale("", nullptr)); // black magic
72  Py_Initialize();
73 
74  // Initialize numpy array. Use the signal handler hack to prevent numpy from grabbing CTRL-C from
75  // https://stackoverflow.com/questions/28750774/
76  // python-import-array-makes-it-impossible-to-kill-embedded-python-with-ctrl-c
77  //PyOS_sighandler_t sighandler = PyOS_getsig(SIGINT);
78  import_array();
79  //PyOS_setsig(SIGINT,sighandler);
80  return NUMPY_IMPORT_ARRAY_RETVAL;
81  }
82 }
83 
84 void jevois::pythonModuleSetEngine(jevois::Engine * e)
85 {
87  init_numpy();
88 }
89 
90 // ####################################################################################################
91 // Thin wrappers to handle default arguments or overloads in free functions
92 
93 namespace
94 {
95  void pythonSendSerial(std::string const & str)
96  {
97  if (jevois::python::engineForPythonModule == nullptr) LFATAL("internal error");
99  }
100 
101 #ifdef JEVOIS_LDEBUG_ENABLE
102  void pythonLDEBUG(std::string const & logmsg) { LDEBUG(logmsg); }
103 #else
104  void pythonLDEBUG(std::string const & JEVOIS_UNUSED_PARAM(logmsg)) { }
105 #endif
106  void pythonLINFO(std::string const & logmsg) { LINFO(logmsg); }
107  void pythonLERROR(std::string const & logmsg) { LERROR(logmsg); }
108  void pythonLFATAL(std::string const & logmsg) { LFATAL(logmsg); }
109 
110 } // anonymous namespace
111 
112 namespace jevois
113 {
114  namespace python
115  {
116  // Aux enum for YUYV colors - keep this in sync with RawImage.H:
117  enum YUYV { Black = 0x8000, DarkGrey = 0x8050, MedGrey = 0x8080, LightGrey = 0x80a0, White = 0x80ff,
118  DarkGreen = 0x0000, MedGreen = 0x0040, LightGreen = 0x00ff, DarkTeal = 0x7070, MedTeal = 0x7090,
119  LightTeal = 0x70b0, DarkPurple = 0xa030, MedPurple = 0xa050, LightPurple = 0xa080,
120  DarkPink = 0xff00, MedPink = 0xff80, LightPink = 0xffff };
121  }
122 }
123 
124 // ####################################################################################################
126 {
127  // #################### Initialize converters for cv::Mat support:
128  boost::python::to_python_converter<cv::Mat, pbcvt::matToNDArrayBoostConverter>();
130 
131  // #################### module sendSerial() emulation:
132  boost::python::def("sendSerial", pythonSendSerial);
133 
134  // #################### Log.H
135  JEVOIS_PYTHON_CONSTANT(LOG_DEBUG);
136  JEVOIS_PYTHON_CONSTANT(LOG_INFO);
137  JEVOIS_PYTHON_CONSTANT(LOG_ERR);
138  JEVOIS_PYTHON_CONSTANT(LOG_CRIT);
139 
140  boost::python::def("LDEBUG", pythonLDEBUG);
141  boost::python::def("LINFO", pythonLINFO);
142  boost::python::def("LERROR", pythonLERROR);
143  boost::python::def("LFATAL", pythonLFATAL);
144 
145  // #################### Utils.H
154 
155  // #################### Coordinates.H
156  void (*imgToStd1)(float & x, float & y, jevois::RawImage const & camimg, float const eps) = jevois::coords::imgToStd;
157  void (*imgToStd2)(float & x, float & y, unsigned int const width, unsigned int const height, float const eps) =
159  boost::python::def("imgToStd", imgToStd1);
160  boost::python::def("imgToStd", imgToStd2);
161 
162  void (*stdToImg1)(float & x, float & y, jevois::RawImage const & camimg, float const eps) = jevois::coords::stdToImg;
163  void (*stdToImg2)(float & x, float & y, unsigned int const width, unsigned int const height, float const eps) =
165  boost::python::def("stdToImg", stdToImg1);
166  boost::python::def("stdToImg", stdToImg2);
167 
168  boost::python::def("imgToStdX", jevois::coords::imgToStdX);
169  boost::python::def("imgToStdY", jevois::coords::imgToStdY);
170  boost::python::def("imgToStdSize", jevois::coords::imgToStdSize);
171  boost::python::def("stdToImgSize", jevois::coords::stdToImgSize);
172 
173  // #################### RawImage.H
174  boost::python::class_<jevois::RawImage>("RawImage") // default constructor is included
175  .def("invalidate", &jevois::RawImage::invalidate)
176  .def("valid", &jevois::RawImage::valid)
177  .def("clear", &jevois::RawImage::clear)
178  .def("require", &jevois::RawImage::require)
179  .def_readwrite("width", &jevois::RawImage::width)
180  .def_readwrite("height", &jevois::RawImage::height)
181  .def_readwrite("fmt", &jevois::RawImage::fmt)
182  .def_readwrite("fps", &jevois::RawImage::fps)
183  .def("bytesperpix", &jevois::RawImage::bytesperpix)
184  .def("bytesize", &jevois::RawImage::bytesize)
185  .def("coordsOk", &jevois::RawImage::coordsOk)
186  //.def("pixels", &jevois::RawImage::pixelsw<unsigned char>,
187  // boost::python::return_value_policy<boost::python::reference_existing_object>())
188  ;
189 
190  boost::python::enum_<jevois::python::YUYV>("YUYV")
192  .JEVOIS_PYTHON_ENUM_VAL(DarkGrey)
193  .JEVOIS_PYTHON_ENUM_VAL(MedGrey)
194  .JEVOIS_PYTHON_ENUM_VAL(LightGrey)
195  .JEVOIS_PYTHON_ENUM_VAL(White)
196  .JEVOIS_PYTHON_ENUM_VAL(DarkGreen)
197  .JEVOIS_PYTHON_ENUM_VAL(MedGreen)
198  .JEVOIS_PYTHON_ENUM_VAL(LightGreen)
199  .JEVOIS_PYTHON_ENUM_VAL(DarkTeal)
200  .JEVOIS_PYTHON_ENUM_VAL(MedTeal)
201  .JEVOIS_PYTHON_ENUM_VAL(LightTeal)
202  .JEVOIS_PYTHON_ENUM_VAL(DarkPurple)
203  .JEVOIS_PYTHON_ENUM_VAL(MedPurple)
204  .JEVOIS_PYTHON_ENUM_VAL(LightPurple)
205  .JEVOIS_PYTHON_ENUM_VAL(DarkPink)
206  .JEVOIS_PYTHON_ENUM_VAL(MedPink)
207  .JEVOIS_PYTHON_ENUM_VAL(LightPink)
208  ;
209 
210  JEVOIS_PYTHON_CONSTANT(V4L2_PIX_FMT_SRGGB8);
211  JEVOIS_PYTHON_CONSTANT(V4L2_PIX_FMT_YUYV);
212  JEVOIS_PYTHON_CONSTANT(V4L2_PIX_FMT_GREY);
213  JEVOIS_PYTHON_CONSTANT(V4L2_PIX_FMT_RGB565);
214  JEVOIS_PYTHON_CONSTANT(V4L2_PIX_FMT_MJPEG);
215  JEVOIS_PYTHON_CONSTANT(V4L2_PIX_FMT_BGR24);
216 
217  // #################### PythonModule.H
218  boost::python::class_<jevois::InputFramePython>("InputFrame")
219  .def("get", &jevois::InputFramePython::get1,
220  boost::python::return_value_policy<boost::python::reference_existing_object>())
221  .def("get", &jevois::InputFramePython::get,
222  boost::python::return_value_policy<boost::python::reference_existing_object>())
223  .def("done", &jevois::InputFramePython::done)
224  .def("getCvGRAY", &jevois::InputFramePython::getCvGRAY1)
225  .def("getCvGRAY", &jevois::InputFramePython::getCvGRAY)
226  .def("getCvBGR", &jevois::InputFramePython::getCvBGR1)
227  .def("getCvBGR", &jevois::InputFramePython::getCvBGR)
228  .def("getCvRGB", &jevois::InputFramePython::getCvRGB1)
229  .def("getCvRGB", &jevois::InputFramePython::getCvRGB)
230  .def("getCvRGBA", &jevois::InputFramePython::getCvRGBA1)
231  .def("getCvRGBA", &jevois::InputFramePython::getCvRGBA)
232  ;
233 
234  boost::python::class_<jevois::OutputFramePython>("OutputFrame")
235  .def("get", &jevois::OutputFramePython::get,
236  boost::python::return_value_policy<boost::python::reference_existing_object>())
237  .def("send", &jevois::OutputFramePython::send)
238 
239  .def("sendCv", &jevois::OutputFramePython::sendCv1)
240  .def("sendCv", &jevois::OutputFramePython::sendCv)
241 
242  .def("sendCvGRAY", &jevois::OutputFramePython::sendCvGRAY1)
243  .def("sendCvGRAY", &jevois::OutputFramePython::sendCvGRAY)
244  .def("sendCvBGR", &jevois::OutputFramePython::sendCvBGR1)
245  .def("sendCvBGR", &jevois::OutputFramePython::sendCvBGR)
246  .def("sendCvRGB", &jevois::OutputFramePython::sendCvRGB1)
247  .def("sendCvRGB", &jevois::OutputFramePython::sendCvRGB)
248  .def("sendCvRGBA", &jevois::OutputFramePython::sendCvRGBA1)
249  .def("sendCvRGBA", &jevois::OutputFramePython::sendCvRGBA)
250 
251  .def("sendScaledCvGRAY", &jevois::OutputFramePython::sendScaledCvGRAY1)
252  .def("sendScaledCvGRAY", &jevois::OutputFramePython::sendScaledCvGRAY)
253  .def("sendScaledCvBGR", &jevois::OutputFramePython::sendScaledCvBGR1)
254  .def("sendScaledCvBGR", &jevois::OutputFramePython::sendScaledCvBGR)
255  .def("sendScaledCvRGB", &jevois::OutputFramePython::sendScaledCvRGB1)
256  .def("sendScaledCvRGB", &jevois::OutputFramePython::sendScaledCvRGB)
257  .def("sendScaledCvRGBA", &jevois::OutputFramePython::sendScaledCvRGBA1)
258  .def("sendScaledCvRGBA", &jevois::OutputFramePython::sendScaledCvRGBA)
259  ;
260 
261  // #################### RawImageOps.H
274 
275  void (*drawRect1)(jevois::RawImage & img, int x, int y, unsigned int w,
276  unsigned int h, unsigned int thick, unsigned int col) = jevois::rawimage::drawRect;
277  void (*drawRect2)(jevois::RawImage & img, int x, int y, unsigned int w, unsigned int h, unsigned int col) =
279  boost::python::def("drawRect", drawRect1);
280  boost::python::def("drawRect", drawRect2);
282 
283  boost::python::enum_<jevois::rawimage::Font>("Font")
285  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font6x10)
286  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font7x13)
287  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font8x13bold)
288  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font9x15bold)
289  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font10x20)
290  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font11x22)
291  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font12x22)
292  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font14x26)
293  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font15x28)
294  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font16x29)
295  .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(Font20x38);
296 
297  void (*writeText1)(jevois::RawImage & img, std::string const & txt, int x, int y,
298  unsigned int col, jevois::rawimage::Font font) = jevois::rawimage::writeText;
299  boost::python::def("writeText", writeText1);
300 
307 
308  // #################### Timer.H
309  boost::python::class_<jevois::Timer>("Timer", boost::python::init<char const *, size_t, int>())
310  .def("start", &jevois::Timer::start)
311  .def("stop", &jevois::Timer::stop, boost::python::return_value_policy<boost::python::copy_const_reference>())
312  ;
313 
314  // #################### Profiler.H
315  boost::python::class_<jevois::Profiler>("Profiler", boost::python::init<char const *, size_t, int>())
316  .def("start", &jevois::Profiler::start)
317  .def("checkpoint", &jevois::Profiler::checkpoint)
318  .def("stop", &jevois::Profiler::stop, boost::python::return_value_policy<boost::python::copy_const_reference>())
319  ;
320 
321  // #################### SysInfo.H
325 
326 }
#define LDEBUG(msg)
Convenience macro for users to print out console or syslog messages, DEBUG level. ...
Definition: Log.H:155
cv::Mat convertToCvRGB(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB byte...
Definition: RawImageOps.C:302
void sendCvGRAY1(cv::Mat const &img, int quality) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
Definition: PythonModule.C:125
cv::Mat convertToCvRGBA(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB-A byte...
Definition: RawImageOps.C:325
void start()
Start a time measurement period.
Definition: Timer.C:50
void imgToStdY(float &y, unsigned int const height, float const eps=0.1F)
Transform Y coordinate in-place from camera to standardized, using given image width and height...
Definition: Coordinates.C:43
cv::Mat cvImage(RawImage const &src)
Create an OpenCV image from the existing RawImage data, sharing the pixel memory rather than copying ...
Definition: RawImageOps.C:30
unsigned int whiteColor(unsigned int fcc)
Return a value that corresponds to white for the given video format.
Definition: Utils.C:127
void sendScaledCvRGBA1(cv::Mat const &img, int quality) const
Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format...
Definition: PythonModule.C:209
void imgToStd(float &x, float &y, RawImage const &camimg, float const eps=0.1F)
Transform coordinates in-place from camera to standardized, using a RawImage to establish image size...
Definition: Coordinates.C:22
bool coordsOk(int x, int y) const
Helper function to check that coords are within image bounds.
Definition: RawImage.C:76
void drawCircle(RawImage &img, int x, int y, unsigned int rad, unsigned int thick, unsigned int col)
Draw a circle in a YUYV image.
Definition: RawImageOps.C:474
void flushcache()
Flush the caches, may sometimes be useful when running the camera in turbo mode.
Definition: Utils.C:236
void writeText(RawImage &img, std::string const &txt, int x, int y, unsigned int col, Font font=Font6x10)
Write some text in an image.
Definition: RawImageOps.C:677
cv::Mat convertToCvBGR(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV BGR byte...
Definition: RawImageOps.C:279
unsigned int height
Image height in pixels.
Definition: RawImage.H:146
void stdToImgSize(float &x, float &y, unsigned int const width, unsigned int const height, float const eps=0.1F)
Transform size in-place from standardized to image, using a RawImage to establish image size...
Definition: Coordinates.C:74
unsigned int blackColor(unsigned int fcc)
Return a value that corresponds to black for the given video format.
Definition: Utils.C:112
void drawLine(RawImage &img, int x1, int y1, int x2, int y2, unsigned int thick, unsigned int col)
Draw a line in a YUYV image.
Definition: RawImageOps.C:555
void sendCvRGB1(cv::Mat const &img, int quality) const
Shorthand to send a RGB cv::Mat after converting it to the current output format. ...
Definition: PythonModule.C:149
void sendScaledCvGRAY1(cv::Mat const &img, int quality) const
Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format...
Definition: PythonModule.C:173
unsigned int fmt
Pixel format as a V4L2_PIX_FMT_XXX.
Definition: RawImage.H:147
void sendCvBGR1(cv::Mat const &img, int quality) const
Shorthand to send a BGR cv::Mat after converting it to the current output format. ...
Definition: PythonModule.C:137
cv::Mat getCvRGBA1(bool casync) const
Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer.
Definition: PythonModule.C:83
void invalidate()
Invalidate the image by zero&#39;ing out the pointer to pixel buffer and the dims and format...
Definition: RawImage.C:42
void stdToImg(float &x, float &y, RawImage const &camimg, float const eps=0.1F)
Transform coordinates in-place from standardized to image, using a RawImage to establish image size...
Definition: Coordinates.C:60
void sendCv1(cv::Mat const &img, int quality) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:113
void roipaste(RawImage const &src, int x, int y, unsigned int w, unsigned int h, RawImage &dest, int dx, int dy)
Paste an ROI from an image to within another of same pixel type.
Definition: RawImageOps.C:416
void sendCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
Definition: PythonModule.C:131
void sendCvRGB(cv::Mat const &img) const
Shorthand to send a RGB cv::Mat after converting it to the current output format. ...
Definition: PythonModule.C:155
std::string getSysInfoVersion()
Get O.S. version info.
Definition: SysInfo.C:72
void sendCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
Definition: PythonModule.C:167
void sendSerial(std::string const &str, bool islog=false)
Send a string to all serial ports.
Definition: Engine.C:867
RawImage const & get() const
Get the next captured camera image, thin wrapper for default arg value.
Definition: PythonModule.C:35
void checkpoint(char const *description)
Note the time for a particular event.
Definition: Profiler.C:49
RawImage const & get1(bool casync) const
Get the next captured camera image, thin wrapper for default arg value.
Definition: PythonModule.C:29
BOOST_PYTHON_MODULE(libjevois)
#define JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(val)
Convenience macro to define a python enum value where the value is in jevois::rawimage.
Definition: PythonSupport.C:48
bool valid() const
Check whether the image has a valid pixel buffer.
Definition: RawImage.C:46
unsigned int v4l2BytesPerPix(unsigned int fcc)
Return the number of bytes per pixel for a given V4L2_PIX_FMT_...
Definition: Utils.C:92
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level. ...
Definition: Log.H:193
void send() const
Indicate that user processing is done with the image previously obtained via get() ...
Definition: PythonModule.C:107
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
Font
Available fonts for writeText()
Definition: RawImageOps.H:152
RawImage const & get() const
Get the next captured camera image.
Definition: PythonModule.C:101
void hFlipYUYV(RawImage &img)
Flip a YUYV RawImage horizontally while preserving color information.
Definition: RawImageOps.C:1400
std::string getSysInfoCPU()
Get CPU info: frequency, thermal, load.
Definition: SysInfo.C:38
#define JEVOIS_PYTHON_CONSTANT(cst)
Convenience macro to define a constant that exists in the global C++ namespace.
Definition: PythonSupport.C:54
void sendScaledCvBGR1(cv::Mat const &img, int quality) const
Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format...
Definition: PythonModule.C:185
std::string system(std::string const &cmd, bool errtoo=true)
Execute a command and grab stdout output to a string.
Definition: Utils.C:248
cv::Mat getCvBGR1(bool casync) const
Shorthand to get the input image as a BGR cv::Mat and release the raw buffer.
Definition: PythonModule.C:59
void sendCv(cv::Mat const &img) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:119
void imgToStdSize(float &w, float &h, unsigned int const width, unsigned int const height, float const eps=0.1F)
Transform size in-place from camera to standardized, using given image width and height.
Definition: Coordinates.C:50
#define JEVOIS_PYTHON_ENUM_VAL(val)
Convenience macro to define a python enum value where the value is in jevois::python.
Definition: PythonSupport.C:51
cv::Mat getCvGRAY() const
Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer.
Definition: PythonModule.C:53
void sendCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after converting it to the current output format. ...
Definition: PythonModule.C:143
std::string fccstr(unsigned int fcc)
Convert a V4L2 four-cc code (V4L2_PIX_FMT_...) to a 4-char string.
Definition: Utils.C:39
cv::Mat convertToCvGray(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV gray byte...
Definition: RawImageOps.C:245
void convertCvBGRtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a BGR cv::Mat to RawImage with already-allocated pixels and pixel type.
Definition: RawImageOps.C:1254
void imgToStdX(float &x, unsigned int const width, float const eps=0.1F)
Transform X coordinate in-place from camera to standardized, using given image width and height...
Definition: Coordinates.C:36
std::string const & stop()
End a time measurement period, report time spent if reporting interval is reached.
Definition: Timer.C:57
void start()
Start a time measurement period.
Definition: Profiler.C:43
void sendScaledCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format...
Definition: PythonModule.C:191
cv::Mat getCvGRAY1(bool casync) const
Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer.
Definition: PythonModule.C:47
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level. ...
Definition: Log.H:212
void sendCvRGBA1(cv::Mat const &img, int quality) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
Definition: PythonModule.C:161
unsigned int v4l2ImageSize(unsigned int fcc, unsigned int width, unsigned int height)
Return the image size in bytes for a given V4L2_PIX_FMT_..., width, height.
Definition: Utils.C:108
void drawFilledRect(RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int col)
Draw a filled rectangle in a YUYV image.
Definition: RawImageOps.C:634
void done() const
Indicate that user processing is done with the image previously obtained via get() ...
Definition: PythonModule.C:41
cv::Mat getCvRGB1(bool casync) const
Shorthand to get the input image as a RGB cv::Mat and release the raw buffer.
Definition: PythonModule.C:71
void sendScaledCvRGB(cv::Mat const &img) const
Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format...
Definition: PythonModule.C:203
void convertCvRGBAtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert an RGBA cv::Mat to RawImage with already-allocated pixels and pixel type. ...
Definition: RawImageOps.C:1323
#define JEVOIS_PYTHON_RAWIMAGE_FUNC(funcname)
Convenience macro to define a Python binding for a free function in the jevois::rawimage namespace...
Definition: PythonSupport.C:44
#define JEVOIS_PYTHON_FUNC(funcname)
Convenience macro to define a Python binding for a free function in the jevois namespace.
Definition: PythonSupport.C:40
JeVois processing engine - gets images from camera sensor, processes them, and sends results over USB...
Definition: Engine.H:263
void unpackCvRGBAtoGrayRawImage(cv::Mat const &src, RawImage &dst)
Split an RGBA cv::Mat into a 4x taller grey RawImage with already-allocated pixels.
Definition: RawImageOps.C:1298
void pasteGreyToYUYV(cv::Mat const &src, RawImage &dest, int dx, int dy)
Paste a grey byte image into a YUYV image.
Definition: RawImageOps.C:439
Converter from Python numpy NDarray to cv::Mat.
Definition: PythonOpenCV.H:107
void convertCvGRAYtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a Gray cv::Mat to RawImage with already-allocated pixels and pixel type.
Definition: RawImageOps.C:1344
void clear()
Clear the pixels to all black.
Definition: RawImage.C:50
void stop()
End a time measurement period, report time spent for each checkpoint if reporting interval is reached...
Definition: Profiler.C:84
cv::Mat getCvBGR() const
Shorthand to get the input image as a BGR cv::Mat and release the raw buffer.
Definition: PythonModule.C:65
void sendScaledCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format...
Definition: PythonModule.C:215
void sendScaledCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format...
Definition: PythonModule.C:179
float fps
Programmed frames/s as given by current video mapping, may not be actual.
Definition: RawImage.H:148
unsigned int bytesize() const
Helper function to get the total number of bytes in the RawImage, i.e., width * height * bytesperpix(...
Definition: RawImage.C:38
std::string getSysInfoMem()
Get memory info.
Definition: SysInfo.C:64
Engine * engineForPythonModule
Definition: PythonSupport.C:63
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
Definition: Log.H:176
void drawDisk(RawImage &img, int x, int y, unsigned int rad, unsigned int col)
Draw a disk in a YUYV image.
Definition: RawImageOps.C:456
void drawRect(RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int thick, unsigned int col)
Draw a rectangle in a YUYV image.
Definition: RawImageOps.C:595
void byteSwap(RawImage &img)
Swap pairs of bytes in a RawImage.
Definition: RawImageOps.C:359
void sendScaledCvRGB1(cv::Mat const &img, int quality) const
Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format...
Definition: PythonModule.C:197
unsigned int width
Image width in pixels.
Definition: RawImage.H:145
cv::Mat getCvRGB() const
Shorthand to get the input image as a RGB cv::Mat and release the raw buffer.
Definition: PythonModule.C:77
unsigned int strfcc(std::string const &str)
Convert a JeVois video format string to V4L2 four-cc code (V4L2_PIX_FMT_...)
Definition: Utils.C:79
void convertCvRGBtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a RGB cv::Mat to RawImage with already-allocated pixels and pixel type.
Definition: RawImageOps.C:1276
cv::Mat getCvRGBA() const
Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer.
Definition: PythonModule.C:89
void paste(RawImage const &src, RawImage &dest, int dx, int dy)
Paste an image within another of same pixel type.
Definition: RawImageOps.C:394
unsigned int bytesperpix() const
Helper function to get the number of bytes/pixel given the RawImage pixel format. ...
Definition: RawImage.C:34
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
Require a particular image size and format, issue a fatal error message and throw if no match...
Definition: RawImage.C:68