JeVois  1.20
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 an OpenCV image, copying pixel data to an OpenGL texture
245  boost::python::tuple drawImage2(char const * name, RawImage const & img, int x, int y, int w, int h,
246  bool noalias = false, bool isoverlay = false);
247 
248  //! Draw an OpenCV image, copying pixel data to an OpenGL texture
249  boost::python::tuple drawImage3(char const * name, cv::Mat const & img, bool rgb, int x, int y, int w, int h,
250  bool noalias = false, bool isoverlay = false);
251 
252  //! Draw the input video frame from the camera using zero-copy
253  boost::python::tuple drawInputFrame(char const * name, InputFramePython const & frame,
254  bool noalias = false, bool casync = false);
255 
256  //! Draw the second (scaled) input video frame from the camera using zero-copy
257  boost::python::tuple drawInputFrame2(char const * name, InputFramePython const & frame,
258  bool noalias = false, bool casync = false);
259 
260  //! Convert coordinates of a point from within a rendered image to on-screen
261  ImVec2 i2d(ImVec2 p, char const * name = nullptr);
262 
263  //! Convert coordinates of a point from within a rendered image to on-screen
264  ImVec2 i2d1(float x, float y, char const * name = nullptr);
265 
266  //! Convert a 2D size from within a rendered image to on-screen
267  ImVec2 i2ds(ImVec2 p, char const * name = nullptr);
268 
269  //! Convert a 2D size from within a rendered image to on-screen
270  ImVec2 i2ds1(float x, float y, char const * name = nullptr);
271 
272  //! Draw line over an image
273  void drawLine(float x1, float y1, float x2, float y2, ImU32 col = IM_COL32(128,255,128,255));
274 
275  //! Draw rectangular box over an image
276  void drawRect(float x1, float y1, float x2, float y2, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
277 
278  //! Draw polygon over an image
279  void drawPoly(std::vector<cv::Point> const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
280 
281  //! Draw polygon over an image
282  void drawPoly1(std::vector<cv::Point2f> const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
283 
284  //! Draw polygon over an image
285  void drawPoly2(cv::Mat const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
286 
287  //! Draw circle over an image
288  void drawCircle(float x, float y, float r, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
289 
290  //! Draw text over an image
291  void drawText(float x, float y, char const * txt, ImU32 col = IM_COL32(128,255,128,255));
292 
293  //! Get coordinates of the start of a given line of text to be drawn as overlay on top of an image
294  ImVec2 iline(int line = -1, char const * name = nullptr);
295 
296  //! Draw some overlay text on top of an image
297  void itext(char const * txt, ImU32 const & col = IM_COL32_BLACK_TRANS, int line = -1);
298 
299  //! Display processing and video info at bottom of screen
300  void iinfo(jevois::InputFramePython const & inframe, std::string const & fpscpu,
301  unsigned short winw = 0, unsigned short winh = 0);
302 
303  //! Release an image
304  void releaseImage(char const * name);
305 
306  //! Release an image, second video stream
307  void releaseImage2(char const * name);
308 
309  //! Finish current frame and render it
310  void endFrame();
311 
312  //! Convert coordinates of a point from on-screen to within a rendered image
313  ImVec2 d2i(ImVec2 p, char const * name = nullptr);
314 
315  //! Convert coordinates of a point from on-screen to within a rendered image
316  ImVec2 d2i1(float x, float y, char const * name = nullptr);
317 
318  //! Convert a 2D size from on-screen to within a rendered image
319  ImVec2 d2is(ImVec2 p, char const * name = nullptr);
320 
321  //! Convert a 2D size from on-screen to within a rendered image
322  ImVec2 d2is1(float x, float y, char const * name = nullptr);
323 
324  //! Report an error in an overlay window
325  void reportError(std::string const & err);
326 
327  //! Report current exception in a modal dialog, then ignore it
328  void reportAndIgnoreException(std::string const & prefix = "");
329 
330  //! Report current exception in a modal dialog, then re-throw it
331  void reportAndRethrowException(std::string const & prefix = "");
332 
333  //! ImGui helper: get mouse position
334  ImVec2 getMousePos();
335 
336  //! ImGui helper: check if mouse button clicked
337  bool isMouseClicked(int button_num);
338 
339  //! ImGui helper: check if mouse button double-clicked
340  bool isMouseDoubleClicked(int button_num);
341 
342  //! ImGui helper: check if mouse button dragged
343  bool isMouseDragging(int button_num);
344 
345  //! ImGui helper: check if mouse button pressed
346  bool isMouseDown(int button_num);
347 
348  //! ImGui helper: check if mouse button released
349  bool isMouseReleased(int button_num);
350 
351  private:
352  GUIhelper * itsGUIhelper;
353  };
354 #endif
355 
356  //! Wrapper module to allow users to develop new modules written in Python
357  /*! This wrapper module calls a process function written in Python on every frame. Note how sendSerial() is added
358  dynamically after the python class is defined, as a new member function of the class. \ingroup python */
359  class PythonModule : public Module, public PythonWrapper
360  {
361  public:
362  //! Constructor needs the full path to a Python source code file
363  /*! Note that, contrary to C++ modules, construction will not throw. This is so that the module is always valid
364  and initialized, and its module path can be set by Engine, which is necessary to allow saving the source code
365  from JeVois Inventor. Instead, any construction error is stored internally in this class and will be re-thrown
366  at any access to process(), parfseSerial(), etc. */
367  PythonModule(VideoMapping const & m);
368 
369  //! Load python code and optionally call init() python module function, if implemented
370  void preInit() override;
371 
372  //! Virtual destructor for safe inheritance
373  virtual ~PythonModule();
374 
375  //! Processing function, version that receives a frame from camera and sends a frame out over USB
376  virtual void process(InputFrame && inframe, OutputFrame && outframe) override;
377 
378  //! Processing function, version that receives a frame from camera and does not use USB
379  virtual void process(InputFrame && inframe) override;
380 
381 #ifdef JEVOIS_PRO
382  //! Processing function, version that receives a frame from camera, no USB, but GUI output on JeVois-Pro
383  virtual void process(InputFrame && inframe, GUIhelper & helper);
384 #endif
385 
386  //! Receive a string from a serial port which contains a user command
387  virtual void parseSerial(std::string const & str, std::shared_ptr<UserInterface> s) override;
388 
389  //! Human-readable description of this Module's supported custom commands
390  virtual void supportedCommands(std::ostream & os) override;
391 
392  //! Optionally call uninit() python module function, if implemented
393  void postUninit() override;
394 
395  private:
396  std::string itsPyPath;
397  };
398 
399  namespace dnn
400  {
401  class PreProcessor;
402 
403  //! Pre-Processor interface exposed to the python side
404  /*! This wrapper is passed down to the process() function of a python post-processor, it provides a python-friendly
405  interface to b2i(), blobsizes(), etc \ingroup python */
407  {
408  public:
409  //! Construct from an existing PreProcessor
410  /*! Caller must ensure that pp outlives us. */
412 
413  //! Access the last processed image size
414  /*! Returned as a tuple (width, height). */
415  boost::python::tuple imagesize() const;
416 
417  //! Access the last computed blobs (or empty if process() has not yet been called)
418  boost::python::list blobs() const;
419 
420  //! Access the width and height of a given blob, accounting for NCHW or NHWC
421  /*! Returned as a tuple (width, height). */
422  boost::python::tuple blobsize(size_t num) const;
423 
424  //! Convert coordinates from blob back to original image
425  /*! 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
426  convert detected boxes back into original input coordinates. Returned as a tuple (x, y). */
427  boost::python::tuple b2i(float x, float y, size_t blobnum);
428 
429  //! Get unscaled crop rectangle in image coordinates
430  /*! This is useful to display an image overlay on top of the input image.
431  Returned as a tuple (x, y, w, h). */
432  boost::python::tuple getUnscaledCropRect(size_t blobnum);
433 
434  //! Convert coordinates from image to blob
435  /*! Given coords x,y should be in [0..w-1]x[0..h-1] where w,h are the image's width and height. This is useful
436  to convert mouse coordinates (after they have been converted from screen to image coords) to locations
437  within an input blob. */
438  boost::python::tuple i2b(float x, float y, size_t blobnum);
439 
440  private:
441  PreProcessor * itsPP;
442  };
443 
445 
446  //! YOLO post-processor exposed to python
447  /*! A bit hacky since PostProcessorDetectYOLO is a Component that holds parameters. This class will add a
448  PostProcessorDetectYOLO subcomponent to the current module, and then will forward yolo post-processing requests
449  to it. */
451  {
452  public:
453  //! Constructor constructs itsYOLO and adds it to current module
455 
456  //! Destructor removes itsYOLO from current module
458 
459  //! Freeze/unfreeze parameters that users should not change while running
460  void freeze(bool doit);
461 
462  //! Generic raw YOLO processing
463  /*! The returned tuple has 3 elements: list of int for classIds, list of float for confidences, and list of
464  4-element tuples of floats for boxes (x, y, w, h). */
465  boost::python::tuple yolo(boost::python::list outs, int nclass, float boxThreshold,
466  float confThreshold, int bw, int bh, int fudge, int maxbox);
467 
468  private:
469  std::shared_ptr<PostProcessorDetectYOLO> itsYOLO;
470  };
471 
472  } // namespace dnn
473 } // 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:244
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:112
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:94
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:510
jevois::InputFramePython::get
const RawImage & get() const
Get the next captured camera image, thin wrapper for default arg value.
Definition: PythonModule.C:40
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:178
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:320
jevois::dnn::PostProcessorDetectYOLO
Post-Processor sub-component for raw YOLO decoding.
Definition: PostProcessorDetectYOLO.H:27
jevois::GUIhelperPython::isMouseReleased
bool isMouseReleased(int button_num)
ImGui helper: check if mouse button released.
Definition: PythonModule.C:580
jevois::OutputFramePython::get
const RawImage & get() const
Get the next captured camera image.
Definition: PythonModule.C:166
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:444
jevois::PythonModule
Wrapper module to allow users to develop new modules written in Python.
Definition: PythonModule.H:359
jevois::InputFramePython::get1
const RawImage & get1(bool casync) const
Get the next captured camera image, thin wrapper for default arg value.
Definition: PythonModule.C:34
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:136
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:503
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:615
jevois::GUIhelperPython::drawImage3
boost::python::tuple drawImage3(char const *name, cv::Mat const &img, bool rgb, int x, int y, int w, int h, bool noalias=false, bool isoverlay=false)
Draw an OpenCV image, copying pixel data to an OpenGL texture.
Definition: PythonModule.C:342
jevois::OutputFramePython::send
void send() const
Indicate that user processing is done with the image previously obtained via get()
Definition: PythonModule.C:172
jevois::InputFramePython::getp
const RawImage & getp() const
Get the next captured camera image that is intended for processing.
Definition: PythonModule.C:70
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:496
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:148
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:274
jevois::InputFramePython::done
void done() const
Indicate that user processing is done with the image previously obtained via get()
Definition: PythonModule.C:76
jevois::GUIhelperPython::isMouseDown
bool isMouseDown(int button_num)
ImGui helper: check if mouse button pressed.
Definition: PythonModule.C:576
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:451
jevois::GUIhelperPython::frameStarted
bool frameStarted() const
Helper to indicate that startFrame() was called, and thus endFrame() should be called.
Definition: PythonModule.C:303
jevois::GUIhelperPython::endFrame
void endFrame()
Finish current frame and render it.
Definition: PythonModule.C:532
jevois::dnn::PreProcessorForPython
Pre-Processor interface exposed to the python side.
Definition: PythonModule.H:406
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:262
jevois::dnn::PreProcessorForPython::imagesize
boost::python::tuple imagesize() const
Access the last processed image size.
Definition: PythonModule.C:670
jevois::PythonModule::~PythonModule
virtual ~PythonModule()
Virtual destructor for safe inheritance.
Definition: PythonModule.C:611
jevois::GUIhelper
Helper class to assist modules in creating graphical and GUI elements.
Definition: GUIhelper.H:128
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:489
jevois::GUIhelperPython::isMouseDragging
bool isMouseDragging(int button_num)
ImGui helper: check if mouse button dragged.
Definition: PythonModule.C:572
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:409
jevois::PythonModule::postUninit
void postUninit() override
Optionally call uninit() python module function, if implemented.
Definition: PythonModule.C:604
jevois::dnn::PostProcessorDetectYOLOforPython::freeze
void freeze(bool doit)
Freeze/unfreeze parameters that users should not change while running.
Definition: PythonModule.C:729
jevois::GUIhelperPython::releaseImage2
void releaseImage2(char const *name)
Release an image, second video stream.
Definition: PythonModule.C:525
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:423
jevois::GUIhelperPython::startFrame
boost::python::tuple startFrame()
Start a new rendering frame.
Definition: PythonModule.C:294
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:190
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:154
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:142
jevois::dnn::PreProcessor
Pre-Processor for neural network pipeline.
Definition: PreProcessor.H:108
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:124
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:232
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:214
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:130
jevois::GUIhelperPython::reportAndIgnoreException
void reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
Definition: PythonModule.C:546
jevois::dnn::PreProcessorForPython::i2b
boost::python::tuple i2b(float x, float y, size_t blobnum)
Convert coordinates from image to blob.
Definition: PythonModule.C:700
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:310
jevois::InputFramePython::get2
const RawImage & get2() const
Get the next captured camera image, ISP-scaled second frame.
Definition: PythonModule.C:58
jevois::GUIhelperPython::isMouseDoubleClicked
bool isMouseDoubleClicked(int button_num)
ImGui helper: check if mouse button double-clicked.
Definition: PythonModule.C:568
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:395
jevois::PythonModule::preInit
void preInit() override
Load python code and optionally call init() python module function, if implemented.
Definition: PythonModule.C:594
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:458
jevois::PythonModule::supportedCommands
virtual void supportedCommands(std::ostream &os) override
Human-readable description of this Module's supported custom commands.
Definition: PythonModule.C:654
jevois::InputFramePython::getp1
const RawImage & getp1(bool casync) const
Get the next captured camera image that is intended for processing.
Definition: PythonModule.C:64
jevois::dnn::PostProcessorDetectYOLOforPython::~PostProcessorDetectYOLOforPython
~PostProcessorDetectYOLOforPython()
Destructor removes itsYOLO from current module.
Definition: PythonModule.C:726
jevois::dnn::PreProcessorForPython::PreProcessorForPython
PreProcessorForPython(PreProcessor *pp)
Construct from an existing PreProcessor.
Definition: PythonModule.C:667
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:381
jevois::dnn::PostProcessorDetectYOLOforPython
YOLO post-processor exposed to python.
Definition: PythonModule.H:450
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:676
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:238
jevois::PythonModule::PythonModule
PythonModule(VideoMapping const &m)
Constructor needs the full path to a Python source code file.
Definition: PythonModule.C:588
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:280
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:402
jevois::GUIhelperPython::getMousePos
ImVec2 getMousePos()
ImGui helper: get mouse position.
Definition: PythonModule.C:560
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::GUIhelperPython::isMouseClicked
bool isMouseClicked(int button_num)
ImGui helper: check if mouse button clicked.
Definition: PythonModule.C:564
jevois::InputFramePython::hasScaledImage
bool hasScaledImage() const
Check whether a second input image scaled by the JeVoisPro Platform ISP is available.
Definition: PythonModule.C:46
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:388
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:268
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:220
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:437
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:250
jevois::InputFrame
Exception-safe wrapper around a raw camera input frame.
Definition: InputFrame.H:50
jevois::dnn::PreProcessorForPython::getUnscaledCropRect
boost::python::tuple getUnscaledCropRect(size_t blobnum)
Get unscaled crop rectangle in image coordinates.
Definition: PythonModule.C:694
jevois::GUIhelperPython::releaseImage
void releaseImage(char const *name)
Release an image.
Definition: PythonModule.C:518
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:226
jevois::OutputFramePython::OutputFramePython
OutputFramePython()=default
Default constructor to keep boost::python happy, object is not operational.
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:208
jevois::InputFramePython::done2
void done2() const
Indicate that user processing is done with the ISP-scaled image previously obtained via get2()
Definition: PythonModule.C:82
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:118
jevois::dnn::PreProcessorForPython::blobsize
boost::python::tuple blobsize(size_t num) const
Access the width and height of a given blob, accounting for NCHW or NHWC.
Definition: PythonModule.C:681
jevois::InputFramePython::get21
const RawImage & get21(bool casync) const
Get the next captured camera image, ISP-scaled second frame.
Definition: PythonModule.C:52
jevois::InputFramePython::InputFramePython
InputFramePython()=default
Default constructor to keep boost::python happy, object is not operational.
jevois::GUIhelperPython::drawImage2
boost::python::tuple drawImage2(char const *name, RawImage const &img, int x, int y, int w, int h, bool noalias=false, bool isoverlay=false)
Draw an OpenCV image, copying pixel data to an OpenGL texture.
Definition: PythonModule.C:330
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:100
jevois::dnn::PostProcessorDetectYOLOforPython::PostProcessorDetectYOLOforPython
PostProcessorDetectYOLOforPython()
Constructor constructs itsYOLO and adds it to current module.
Definition: PythonModule.C:711
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:430
jevois::GUIhelperPython::GUIhelperPython
GUIhelperPython(GUIhelper *src)
Construct from a regular GUIhelper that should be be coming from Engine.
Definition: PythonModule.C:290
jevois::PythonWrapper
Helper class to run python code from C++.
Definition: PythonWrapper.H:41
h
int h
Definition: GUIhelper.C:2373
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:354
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:106
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:374
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:482
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:364
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:642
jevois::dnn::PostProcessorDetectYOLOforPython::yolo
boost::python::tuple yolo(boost::python::list outs, int nclass, float boxThreshold, float confThreshold, int bw, int bh, int fudge, int maxbox)
Generic raw YOLO processing.
Definition: PythonModule.C:733
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:184
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:88
jevois::GUIhelperPython::reportAndRethrowException
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
Definition: PythonModule.C:553
GUIhelper.H
jevois::dnn::PreProcessorForPython::b2i
boost::python::tuple b2i(float x, float y, size_t blobnum)
Convert coordinates from blob back to original image.
Definition: PythonModule.C:687
jevois::GUIhelperPython::reportError
void reportError(std::string const &err)
Report an error in an overlay window.
Definition: PythonModule.C:539
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:196
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:416
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:256
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:202
jevois::InputFramePython
Wrapper around InputFrame to be used by Python.
Definition: PythonModule.H:46