JeVois  1.18
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
PythonModule.H
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 #pragma once
19 
20 #include <jevois/Core/Module.H>
23 #include <jevois/GPU/GUIhelper.H>
24 
25 namespace jevois
26 {
27  class Engine;
28 
29  /*! \defgroup python Support for JeVois modules written in Python
30 
31  In addition to writing modules in C++, JeVois supports writing modules in Python. JeVois provides two-way
32  mappings:
33 
34  - C++ functions and classes of JeVois become accessible in Python by importing Python package \p libjevois
35  - The JeVois engine can directly invoke class member functions of a Python class implementing a machine vision
36  processing module
37 
38  \ingroup core */
39 
40  //! Wrapper around InputFrame to be used by Python
41  /*! This wrapper is to work around the lack of move semantics in our Python support. This class is not intended for
42  general use, but only for use by PythonModule. Users of this class must ensure that the original InputFrame will
43  outlive any and all InputFramePython instances, since InputFramePython just references to the source InputFrame by
44  unprotected raw pointer. Although the C++ object is called InputFramePython, we will expose it to python under
45  the name InputFrame (see PythonSupport.C). \ingroup python */
47  {
48  public:
49  //! Default constructor to keep boost::python happy, object is not operational
50  InputFramePython() = default;
51 
52  //! Construct from a regular (move-only) InputFrame that should be be coming from Engine
54 
55  //! Get the next captured camera image, thin wrapper for default arg value
56  RawImage const & get1(bool casync) const;
57 
58  //! Get the next captured camera image, thin wrapper for default arg value
59  RawImage const & get() const;
60 
61  //! Check whether a second input image scaled by the JeVoisPro Platform ISP is available
62  bool hasScaledImage() const;
63 
64  //! Indicate that user processing is done with the image previously obtained via get()
65  void done() const;
66 
67  //! Indicate that user processing is done with the ISP-scaled image previously obtained via get2()
68  void done2() const;
69 
70  //! Get the next captured camera image, ISP-scaled second frame
71  RawImage const & get21(bool casync) const;
72 
73  //! Get the next captured camera image, ISP-scaled second frame
74  RawImage const & get2() const;
75 
76  //! Get the next captured camera image that is intended for processing
77  RawImage const & getp1(bool casync) const;
78 
79  //! Get the next captured camera image that is intended for processing
80  RawImage const & getp() const;
81 
82  //! Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer
83  cv::Mat getCvGRAY1(bool casync) const;
84 
85  //! Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer
86  cv::Mat getCvGRAY() const;
87 
88  //! Shorthand to get the input image as a BGR cv::Mat and release the raw buffer
89  cv::Mat getCvBGR1(bool casync) const;
90 
91  //! Shorthand to get the input image as a BGR cv::Mat and release the raw buffer
92  cv::Mat getCvBGR() const;
93 
94  //! Shorthand to get the input image as a RGB cv::Mat and release the raw buffer
95  cv::Mat getCvRGB1(bool casync) const;
96 
97  //! Shorthand to get the input image as a RGB cv::Mat and release the raw buffer
98  cv::Mat getCvRGB() const;
99 
100  //! Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer
101  cv::Mat getCvRGBA1(bool casync) const;
102 
103  //! Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer
104  cv::Mat getCvRGBA() const;
105 
106  //! Shorthand to get the input image for processing as a GRAY cv::Mat and release the raw buffer
107  cv::Mat getCvGRAYp() const;
108 
109  //! Shorthand to get the input image for processing as a BGR cv::Mat and release the raw buffer
110  cv::Mat getCvBGRp() const;
111 
112  //! Shorthand to get the input image for processing as a RGB cv::Mat and release the raw buffer
113  cv::Mat getCvRGBp() const;
114 
115  //! Shorthand to get the input image for processing as a RGBA cv::Mat and release the raw buffer
116  cv::Mat getCvRGBAp() const;
117 
118  private:
119  friend class GUIhelperPython;
120  InputFrame * itsInputFrame;
121  };
122 
123  //! Wrapper around OutputFrame to be used by Python
124  /*! This wrapper is to work around the lack of move semantics in our Python support. This class is not intended for
125  general use, but only for use by PythonModule. Users of this class must ensure that the original OutputFrame will
126  outlive any and all OutputFramePython instances, since OutputFramePython just references to the source OutputFrame
127  by unprotected raw pointer. Although the C++ object is called OutputFramePython, we will expose it to python
128  under the name OutputFrame (see PythonSupport.C). \ingroup python */
130  {
131  public:
132  //! Default constructor to keep boost::python happy, object is not operational
133  OutputFramePython() = default;
134 
135  //! Construct from a regular (move-only) OutputFrame that should be be coming from Engine
137 
138  //! Get the next captured camera image
139  RawImage const & get() const;
140 
141  //! Indicate that user processing is done with the image previously obtained via get()
142  void send() const;
143 
144  //! Shorthand to send a cv::Mat after scaling/converting it to the current output format
145  /* The pixel format of the given cv::Mat is guessed as follows:
146 
147  - if img.type() == CV_8UC3, assume BGR pixels
148  - if img.type() == CV_8UC1, assume GRAY pixels
149  - if img.type() == CV_8UC4, assume RGBA pixels
150 
151  If this is not what you want (e.g., you have CV_8UC3 but RGB pixels instead of BGR, then use the
152  other, more specialized sendScaledCv...() functions. */
153  void sendCv1(cv::Mat const & img, int quality) const;
154 
155  //! Shorthand to send a cv::Mat after scaling/converting it to the current output format
156  /* The pixel format of the given cv::Mat is guessed as follows:
157 
158  - if img.type() == CV_8UC3, assume BGR pixels
159  - if img.type() == CV_8UC1, assume GRAY pixels
160  - if img.type() == CV_8UC4, assume RGBA pixels
161 
162  If this is not what you want (e.g., you have CV_8UC3 but RGB pixels instead of BGR, then use the
163  other, more specialized sendScaledCv...() functions. */
164  void sendCv(cv::Mat const & img) const;
165 
166  //! Shorthand to send a GRAY cv::Mat after converting it to the current output format
167  void sendCvGRAY1(cv::Mat const & img, int quality) const;
168 
169  //! Shorthand to send a GRAY cv::Mat after converting it to the current output format
170  void sendCvGRAY(cv::Mat const & img) const;
171 
172  //! Shorthand to send a BGR cv::Mat after converting it to the current output format
173  void sendCvBGR1(cv::Mat const & img, int quality) const;
174 
175  //! Shorthand to send a BGR cv::Mat after converting it to the current output format
176  void sendCvBGR(cv::Mat const & img) const;
177 
178  //! Shorthand to send a RGB cv::Mat after converting it to the current output format
179  void sendCvRGB1(cv::Mat const & img, int quality) const;
180 
181  //! Shorthand to send a RGB cv::Mat after converting it to the current output format
182  void sendCvRGB(cv::Mat const & img) const;
183 
184  //! Shorthand to send a RGBA cv::Mat after converting it to the current output format
185  void sendCvRGBA1(cv::Mat const & img, int quality) const;
186 
187  //! Shorthand to send a RGBA cv::Mat after converting it to the current output format
188  void sendCvRGBA(cv::Mat const & img) const;
189 
190  //! Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format
191  void sendScaledCvGRAY1(cv::Mat const & img, int quality) const;
192 
193  //! Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format
194  void sendScaledCvGRAY(cv::Mat const & img) const;
195 
196  //! Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format
197  void sendScaledCvBGR1(cv::Mat const & img, int quality) const;
198 
199  //! Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format
200  void sendScaledCvBGR(cv::Mat const & img) const;
201 
202  //! Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format
203  void sendScaledCvRGB1(cv::Mat const & img, int quality) const;
204 
205  //! Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format
206  void sendScaledCvRGB(cv::Mat const & img) const;
207 
208  //! Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format
209  void sendScaledCvRGBA1(cv::Mat const & img, int quality) const;
210 
211  //! Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format
212  void sendScaledCvRGBA(cv::Mat const & img) const;
213 
214  private:
215  OutputFrame * itsOutputFrame;
216  };
217 
218 #ifdef JEVOIS_PRO
219  //! Wrapper around GUIhelper to be used by Python
220  /*! This class is not intended for general use, but only for use by PythonModule. Users of this class must ensure that
221  the original GUIhelper will outlive any and all GUIhelperPython instances, since GUIhelperPython just references
222  to the source GUIhelper by unprotected raw pointer. Although the C++ object is called GUIhelperPython, we will
223  expose it to python under the name GUIhelper (see PythonSupport.C). \ingroup python */
225  {
226  public:
227  //! Construct from a regular GUIhelper that should be be coming from Engine
228  GUIhelperPython(GUIhelper * src);
229 
230  //! Start a new rendering frame
231  boost::python::tuple startFrame();
232 
233  //! Helper to indicate that startFrame() was called, and thus endFrame() should be called
234  bool frameStarted() const;
235 
236  //! Draw a RawImage, copying pixel data to an OpenGL texture
237  boost::python::tuple drawImage(char const * name, RawImage const & img,
238  bool noalias = false, bool isoverlay = false);
239 
240  //! Draw an OpenCV image, copying pixel data to an OpenGL texture
241  boost::python::tuple drawImage1(char const * name, cv::Mat const & img, bool rgb,
242  bool noalias = false, bool isoverlay = false);
243 
244  //! Draw the input video frame from the camera using zero-copy
245  boost::python::tuple drawInputFrame(char const * name, InputFramePython const & frame,
246  bool noalias = false, bool casync = false);
247 
248  //! Draw the second (scaled) input video frame from the camera using zero-copy
249  boost::python::tuple drawInputFrame2(char const * name, InputFramePython const & frame,
250  bool noalias = false, bool casync = false);
251 
252  //! Convert coordinates of a point from within a rendered image to on-screen
253  ImVec2 i2d(ImVec2 p, char const * name = nullptr);
254 
255  //! Convert coordinates of a point from within a rendered image to on-screen
256  ImVec2 i2d1(float x, float y, char const * name = nullptr);
257 
258  //! Convert a 2D size from within a rendered image to on-screen
259  ImVec2 i2ds(ImVec2 p, char const * name = nullptr);
260 
261  //! Convert a 2D size from within a rendered image to on-screen
262  ImVec2 i2ds1(float x, float y, char const * name = nullptr);
263 
264  //! Draw line over an image
265  void drawLine(float x1, float y1, float x2, float y2, ImU32 col = IM_COL32(128,255,128,255));
266 
267  //! Draw rectangular box over an image
268  void drawRect(float x1, float y1, float x2, float y2, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
269 
270  //! Draw polygon over an image
271  void drawPoly(std::vector<cv::Point> const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
272 
273  //! Draw polygon over an image
274  void drawPoly1(std::vector<cv::Point2f> const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
275 
276  //! Draw polygon over an image
277  void drawPoly2(cv::Mat const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
278 
279  //! Draw circle over an image
280  void drawCircle(float x, float y, float r, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
281 
282  //! Draw text over an image
283  void drawText(float x, float y, char const * txt, ImU32 col = IM_COL32(128,255,128,255));
284 
285  //! Get coordinates of the start of a given line of text to be drawn as overlay on top of an image
286  ImVec2 iline(int line = -1, char const * name = nullptr);
287 
288  //! Draw some overlay text on top of an image
289  void itext(char const * txt, ImU32 const & col = IM_COL32_BLACK_TRANS, int line = -1);
290 
291  //! Display processing and video info at bottom of screen
292  void iinfo(jevois::InputFramePython const & inframe, std::string const & fpscpu,
293  unsigned short winw = 0, unsigned short winh = 0);
294 
295  //! Release an image
296  void releaseImage(char const * name);
297 
298  //! Release an image, second video stream
299  void releaseImage2(char const * name);
300 
301  //! Finish current frame and render it
302  void endFrame();
303 
304  //! Convert coordinates of a point from on-screen to within a rendered image
305  ImVec2 d2i(ImVec2 p, char const * name = nullptr);
306 
307  //! Convert coordinates of a point from on-screen to within a rendered image
308  ImVec2 d2i1(float x, float y, char const * name = nullptr);
309 
310  //! Convert a 2D size from on-screen to within a rendered image
311  ImVec2 d2is(ImVec2 p, char const * name = nullptr);
312 
313  //! Convert a 2D size from on-screen to within a rendered image
314  ImVec2 d2is1(float x, float y, char const * name = nullptr);
315 
316  //! Report an error in an overlay window
317  void reportError(std::string const & err);
318 
319  //! Report current exception in a modal dialog, then ignore it
320  void reportAndIgnoreException(std::string const & prefix = "");
321 
322  //! Report current exception in a modal dialog, then re-throw it
323  void reportAndRethrowException(std::string const & prefix = "");
324 
325  private:
326  GUIhelper * itsGUIhelper;
327  };
328 #endif
329 
330  //! Wrapper module to allow users to develop new modules written in Python
331  /*! This wrapper module calls a process function written in Python on every frame. Note how sendSerial() is added
332  dynamically after the python class is defined, as a new member function of the class. \ingroup python */
333  class PythonModule : public Module, public PythonWrapper
334  {
335  public:
336  //! Constructor needs the full path to a Python source code file
337  /*! Note that, contrary to C++ modules, construction will not throw. This is so that the module is always valid
338  and initialized, and its module path can be set by Engine, which is necessary to allow saving the source code
339  from JeVois Inventor. Instead, any construction error is stored internally in this class and will be re-thrown
340  at any access to process(), parfseSerial(), etc. */
341  PythonModule(VideoMapping const & m);
342 
343  //! Load python code and optionally call init() python module function, if implemented
344  void preInit() override;
345 
346  //! Virtual destructor for safe inheritance
347  virtual ~PythonModule();
348 
349  //! Processing function, version that receives a frame from camera and sends a frame out over USB
350  virtual void process(InputFrame && inframe, OutputFrame && outframe) override;
351 
352  //! Processing function, version that receives a frame from camera and does not use USB
353  virtual void process(InputFrame && inframe) override;
354 
355 #ifdef JEVOIS_PRO
356  //! Processing function, version that receives a frame from camera, no USB, but GUI output on JeVois-Pro
357  virtual void process(InputFrame && inframe, GUIhelper & helper);
358 #endif
359 
360  //! Receive a string from a serial port which contains a user command
361  virtual void parseSerial(std::string const & str, std::shared_ptr<UserInterface> s) override;
362 
363  //! Human-readable description of this Module's supported custom commands
364  virtual void supportedCommands(std::ostream & os) override;
365 
366  //! Optionally call uninit() python module function, if implemented
367  void postUninit() override;
368 
369  private:
370  std::string itsPyPath;
371  };
372 
373  namespace dnn
374  {
375  class PreProcessor;
376 
377  //! Pre-Processor interface expose to the python side
378  /*! This wrapper is passed down to the process() function of a python post-processor, it provides a python-friendly
379  interface to b2i(), blobsizes(), etc \ingroup python */
381  {
382  public:
383  //! Construct from an existing PreProcessor
384  /*! Caller must ensure that pp outlives us. */
386 
387  //! Access the last processed image size
388  cv::Size imagesize() const;
389 
390  //! Access the last computed blobs (or empty if process() has not yet been called)
391  boost::python::list blobs() const;
392 
393  //! Access the width and height of a given blob, accounting for NCHW or NHWC
394  cv::Size blobsize(size_t num) const;
395 
396  //! Convert coordinates from blob back to original image
397  /*! Given coords x,y should be in [0..w-1]x[0..h-1] where w,h are the blob's width and height. This is useful to
398  convert detected boxes back into original input coordinates. */
399  cv::Point2f b2i(float x, float y, size_t blobnum);
400 
401  //! Get unscaled crop rectangle in image coordinates
402  /*! This is useful to display an image overlay on top of the input image. */
403  cv::Rect getUnscaledCropRect(size_t blobnum);
404 
405  private:
406  PreProcessor * itsPP;
407  };
408 
409  } // namespace dnn
410 } // namespace jevois
jevois::OutputFramePython::sendScaledCvGRAY
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:242
jevois::InputFramePython::getCvRGB1
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:110
jevois::OutputFrame
Exception-safe wrapper around a raw image to be sent over USB.
Definition: OutputFrame.H:52
jevois::InputFramePython::getCvGRAY
cv::Mat getCvGRAY() const
Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer.
Definition: PythonModule.C:92
Module.H
jevois::GUIhelperPython::iinfo
void iinfo(jevois::InputFramePython const &inframe, std::string const &fpscpu, unsigned short winw=0, unsigned short winh=0)
Display processing and video info at bottom of screen.
Definition: PythonModule.C:484
jevois::InputFramePython::get
const RawImage & get() const
Get the next captured camera image, thin wrapper for default arg value.
Definition: PythonModule.C:38
jevois::OutputFramePython::sendCv1
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:176
jevois::GUIhelperPython::drawImage1
boost::python::tuple drawImage1(char const *name, cv::Mat const &img, bool rgb, bool noalias=false, bool isoverlay=false)
Draw an OpenCV image, copying pixel data to an OpenGL texture.
Definition: PythonModule.C:318
jevois::OutputFramePython::get
const RawImage & get() const
Get the next captured camera image.
Definition: PythonModule.C:164
jevois::GUIhelperPython::drawPoly
void drawPoly(std::vector< cv::Point > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
Definition: PythonModule.C:418
jevois::PythonModule
Wrapper module to allow users to develop new modules written in Python.
Definition: PythonModule.H:333
jevois::dnn::PreProcessorForPython::b2i
cv::Point2f b2i(float x, float y, size_t blobnum)
Convert coordinates from blob back to original image.
Definition: PythonModule.C:629
jevois::InputFramePython::get1
const RawImage & get1(bool casync) const
Get the next captured camera image, thin wrapper for default arg value.
Definition: PythonModule.C:32
jevois::InputFramePython::getCvGRAYp
cv::Mat getCvGRAYp() const
Shorthand to get the input image for processing as a GRAY cv::Mat and release the raw buffer.
Definition: PythonModule.C:134
jevois::GUIhelperPython::itext
void itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
Draw some overlay text on top of an image.
Definition: PythonModule.C:477
jevois::dnn::PreProcessorForPython::getUnscaledCropRect
cv::Rect getUnscaledCropRect(size_t blobnum)
Get unscaled crop rectangle in image coordinates.
Definition: PythonModule.C:632
jevois::PythonModule::process
virtual void process(InputFrame &&inframe, OutputFrame &&outframe) override
Processing function, version that receives a frame from camera and sends a frame out over USB.
Definition: PythonModule.C:565
jevois::OutputFramePython::send
void send() const
Indicate that user processing is done with the image previously obtained via get()
Definition: PythonModule.C:170
jevois::InputFramePython::getp
const RawImage & getp() const
Get the next captured camera image that is intended for processing.
Definition: PythonModule.C:68
jevois::GUIhelperPython::iline
ImVec2 iline(int line=-1, char const *name=nullptr)
Get coordinates of the start of a given line of text to be drawn as overlay on top of an image.
Definition: PythonModule.C:470
jevois::InputFramePython::getCvRGBp
cv::Mat getCvRGBp() const
Shorthand to get the input image for processing as a RGB cv::Mat and release the raw buffer.
Definition: PythonModule.C:146
jevois::RawImage
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
jevois::OutputFramePython::sendScaledCvRGBA1
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:272
jevois::InputFramePython::done
void done() const
Indicate that user processing is done with the image previously obtained via get()
Definition: PythonModule.C:74
jevois::GUIhelperPython::drawPoly1
void drawPoly1(std::vector< cv::Point2f > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
Definition: PythonModule.C:425
jevois::GUIhelperPython::frameStarted
bool frameStarted() const
Helper to indicate that startFrame() was called, and thus endFrame() should be called.
Definition: PythonModule.C:301
jevois::GUIhelperPython::endFrame
void endFrame()
Finish current frame and render it.
Definition: PythonModule.C:506
jevois::dnn::PreProcessorForPython
Pre-Processor interface expose to the python side.
Definition: PythonModule.H:380
jevois::GUIhelperPython
Wrapper around GUIhelper to be used by Python.
Definition: PythonModule.H:224
jevois::OutputFramePython::sendScaledCvRGB1
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:260
jevois::PythonModule::~PythonModule
virtual ~PythonModule()
Virtual destructor for safe inheritance.
Definition: PythonModule.C:561
jevois::GUIhelper
Helper class to assist modules in creating graphical and GUI elements.
Definition: GUIhelper.H:122
jevois::GUIhelperPython::drawText
void drawText(float x, float y, char const *txt, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw text over an image.
Definition: PythonModule.C:463
jevois::GUIhelperPython::d2i1
ImVec2 d2i1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
Definition: PythonModule.C:383
jevois::PythonModule::postUninit
void postUninit() override
Optionally call uninit() python module function, if implemented.
Definition: PythonModule.C:554
jevois::GUIhelperPython::releaseImage2
void releaseImage2(char const *name)
Release an image, second video stream.
Definition: PythonModule.C:499
jevois
Definition: Concepts.dox:1
jevois::GUIhelperPython::d2is1
ImVec2 d2is1(float x, float y, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
Definition: PythonModule.C:397
jevois::GUIhelperPython::startFrame
boost::python::tuple startFrame()
Start a new rendering frame.
Definition: PythonModule.C:292
jevois::OutputFramePython::sendCvGRAY1
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:188
jevois::InputFramePython::getCvRGBAp
cv::Mat getCvRGBAp() const
Shorthand to get the input image for processing as a RGBA cv::Mat and release the raw buffer.
Definition: PythonModule.C:152
jevois::InputFramePython::getCvBGRp
cv::Mat getCvBGRp() const
Shorthand to get the input image for processing as a BGR cv::Mat and release the raw buffer.
Definition: PythonModule.C:140
jevois::dnn::PreProcessor
Pre-Processor for neural network pipeline.
Definition: PreProcessor.H:102
jevois::InputFramePython::getCvRGBA1
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:122
jevois::OutputFramePython::sendCvRGBA
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:230
jevois::OutputFramePython::sendCvRGB1
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:212
jevois::InputFramePython::getCvRGBA
cv::Mat getCvRGBA() const
Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer.
Definition: PythonModule.C:128
jevois::GUIhelperPython::reportAndIgnoreException
void reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
Definition: PythonModule.C:520
jevois::GUIhelperPython::drawImage
boost::python::tuple drawImage(char const *name, RawImage const &img, bool noalias=false, bool isoverlay=false)
Draw a RawImage, copying pixel data to an OpenGL texture.
Definition: PythonModule.C:308
jevois::InputFramePython::get2
const RawImage & get2() const
Get the next captured camera image, ISP-scaled second frame.
Definition: PythonModule.C:56
jevois::GUIhelperPython::i2ds1
ImVec2 i2ds1(float x, float y, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
Definition: PythonModule.C:369
jevois::PythonModule::preInit
void preInit() override
Load python code and optionally call init() python module function, if implemented.
Definition: PythonModule.C:544
jevois::GUIhelperPython::drawPoly2
void drawPoly2(cv::Mat const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
Definition: PythonModule.C:432
jevois::PythonModule::supportedCommands
virtual void supportedCommands(std::ostream &os) override
Human-readable description of this Module's supported custom commands.
Definition: PythonModule.C:604
jevois::InputFramePython::getp1
const RawImage & getp1(bool casync) const
Get the next captured camera image that is intended for processing.
Definition: PythonModule.C:62
jevois::dnn::PreProcessorForPython::PreProcessorForPython
PreProcessorForPython(PreProcessor *pp)
Construct from an existing PreProcessor.
Definition: PythonModule.C:617
jevois::GUIhelperPython::i2d1
ImVec2 i2d1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
Definition: PythonModule.C:355
jevois::dnn::PreProcessorForPython::blobs
boost::python::list blobs() const
Access the last computed blobs (or empty if process() has not yet been called)
Definition: PythonModule.C:623
jevois::OutputFramePython::sendScaledCvGRAY1
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:236
jevois::PythonModule::PythonModule
PythonModule(VideoMapping const &m)
Constructor needs the full path to a Python source code file.
Definition: PythonModule.C:538
jevois::OutputFramePython::sendScaledCvRGBA
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:278
jevois::GUIhelperPython::d2i
ImVec2 d2i(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
Definition: PythonModule.C:376
jevois::OutputFramePython
Wrapper around OutputFrame to be used by Python.
Definition: PythonModule.H:129
VideoMapping.H
jevois::Module
Virtual base class for a vision processing module.
Definition: Module.H:104
jevois::InputFramePython::hasScaledImage
bool hasScaledImage() const
Check whether a second input image scaled by the JeVoisPro Platform ISP is available.
Definition: PythonModule.C:44
jevois::GUIhelperPython::i2ds
ImVec2 i2ds(ImVec2 p, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
Definition: PythonModule.C:362
jevois::OutputFramePython::sendScaledCvRGB
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:266
jevois::OutputFramePython::sendCvRGB
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:218
jevois::GUIhelperPython::drawRect
void drawRect(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw rectangular box over an image.
Definition: PythonModule.C:411
jevois::OutputFramePython::sendScaledCvBGR1
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:248
jevois::InputFrame
Exception-safe wrapper around a raw camera input frame.
Definition: InputFrame.H:50
jevois::GUIhelperPython::releaseImage
void releaseImage(char const *name)
Release an image.
Definition: PythonModule.C:492
jevois::OutputFramePython::sendCvRGBA1
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:224
jevois::OutputFramePython::OutputFramePython
OutputFramePython()=default
Default constructor to keep boost::python happy, object is not operational.
jevois::dnn::PreProcessorForPython::imagesize
cv::Size imagesize() const
Access the last processed image size.
Definition: PythonModule.C:620
jevois::OutputFramePython::sendCvBGR
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:206
jevois::InputFramePython::done2
void done2() const
Indicate that user processing is done with the ISP-scaled image previously obtained via get2()
Definition: PythonModule.C:80
jevois::dnn::PreProcessorForPython::blobsize
cv::Size blobsize(size_t num) const
Access the width and height of a given blob, accounting for NCHW or NHWC.
Definition: PythonModule.C:626
jevois::InputFramePython::getCvRGB
cv::Mat getCvRGB() const
Shorthand to get the input image as a RGB cv::Mat and release the raw buffer.
Definition: PythonModule.C:116
jevois::InputFramePython::get21
const RawImage & get21(bool casync) const
Get the next captured camera image, ISP-scaled second frame.
Definition: PythonModule.C:50
jevois::InputFramePython::InputFramePython
InputFramePython()=default
Default constructor to keep boost::python happy, object is not operational.
jevois::InputFramePython::getCvBGR1
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:98
jevois::GUIhelperPython::drawLine
void drawLine(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw line over an image.
Definition: PythonModule.C:404
jevois::GUIhelperPython::GUIhelperPython
GUIhelperPython(GUIhelper *src)
Construct from a regular GUIhelper that should be be coming from Engine.
Definition: PythonModule.C:288
jevois::PythonWrapper
Helper class to run python code from C++.
Definition: PythonWrapper.H:41
jevois::GUIhelperPython::drawInputFrame
boost::python::tuple drawInputFrame(char const *name, InputFramePython const &frame, bool noalias=false, bool casync=false)
Draw the input video frame from the camera using zero-copy.
Definition: PythonModule.C:328
jevois::InputFramePython::getCvBGR
cv::Mat getCvBGR() const
Shorthand to get the input image as a BGR cv::Mat and release the raw buffer.
Definition: PythonModule.C:104
jevois::GUIhelperPython::i2d
ImVec2 i2d(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
Definition: PythonModule.C:348
jevois::GUIhelperPython::drawCircle
void drawCircle(float x, float y, float r, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw circle over an image.
Definition: PythonModule.C:456
jevois::GUIhelperPython::drawInputFrame2
boost::python::tuple drawInputFrame2(char const *name, InputFramePython const &frame, bool noalias=false, bool casync=false)
Draw the second (scaled) input video frame from the camera using zero-copy.
Definition: PythonModule.C:338
jevois::PythonModule::parseSerial
virtual void parseSerial(std::string const &str, std::shared_ptr< UserInterface > s) override
Receive a string from a serial port which contains a user command.
Definition: PythonModule.C:592
jevois::OutputFramePython::sendCv
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:182
PythonWrapper.H
jevois::InputFramePython::getCvGRAY1
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:86
jevois::GUIhelperPython::reportAndRethrowException
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
Definition: PythonModule.C:527
GUIhelper.H
jevois::GUIhelperPython::reportError
void reportError(std::string const &err)
Report an error in an overlay window.
Definition: PythonModule.C:513
jevois::OutputFramePython::sendCvGRAY
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:194
jevois::GUIhelperPython::d2is
ImVec2 d2is(ImVec2 p, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
Definition: PythonModule.C:390
jevois::OutputFramePython::sendScaledCvBGR
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:254
jevois::OutputFramePython::sendCvBGR1
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:200
jevois::InputFramePython
Wrapper around InputFrame to be used by Python.
Definition: PythonModule.H:46