JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
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>
24
25namespace 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
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 ellipse over an image
291 void drawEllipse(float x, float y, float rx, float ry, float rot = 0.0F,
292 ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
293
294 //! Draw text over an image
295 void drawText(float x, float y, char const * txt, ImU32 col = IM_COL32(128,255,128,255));
296
297 //! Get coordinates of the start of a given line of text to be drawn as overlay on top of an image
298 ImVec2 iline(int line = -1, char const * name = nullptr);
299
300 //! Draw some overlay text on top of an image
301 void itext(char const * txt, ImU32 const & col = IM_COL32_BLACK_TRANS, int line = -1);
302
303 //! Draw some overlay text on top of an image, default color and line
304 void itext2(char const * txt);
305
306 //! Display processing and video info at bottom of screen
307 void iinfo(jevois::InputFramePython const & inframe, std::string const & fpscpu,
308 unsigned short winw = 0, unsigned short winh = 0);
309
310 //! Release an image
311 void releaseImage(char const * name);
312
313 //! Release an image, second video stream
314 void releaseImage2(char const * name);
315
316 //! Finish current frame and render it
317 void endFrame();
318
319 //! Convert coordinates of a point from on-screen to within a rendered image
320 ImVec2 d2i(ImVec2 p, char const * name = nullptr);
321
322 //! Convert coordinates of a point from on-screen to within a rendered image
323 ImVec2 d2i1(float x, float y, char const * name = nullptr);
324
325 //! Convert a 2D size from on-screen to within a rendered image
326 ImVec2 d2is(ImVec2 p, char const * name = nullptr);
327
328 //! Convert a 2D size from on-screen to within a rendered image
329 ImVec2 d2is1(float x, float y, char const * name = nullptr);
330
331 //! Report an error in an overlay window
332 void reportError(std::string const & err);
333
334 //! Report current exception in a modal dialog, then ignore it
335 void reportAndIgnoreException(std::string const & prefix = "");
336
337 //! Report current exception in a modal dialog, then re-throw it
338 void reportAndRethrowException(std::string const & prefix = "");
339
340 //! ImGui helper: get mouse position
341 ImVec2 getMousePos();
342
343 //! ImGui helper: check if mouse button clicked
344 bool isMouseClicked(int button_num);
345
346 //! ImGui helper: check if mouse button double-clicked
347 bool isMouseDoubleClicked(int button_num);
348
349 //! ImGui helper: check if mouse button dragged
350 bool isMouseDragging(int button_num);
351
352 //! ImGui helper: check if mouse button pressed
353 bool isMouseDown(int button_num);
354
355 //! ImGui helper: check if mouse button released
356 bool isMouseReleased(int button_num);
357
358 private:
359 GUIhelper * itsGUIhelper;
360 };
361#endif
362
363 //! Wrapper module to allow users to develop new modules written in Python
364 /*! This wrapper module calls a process function written in Python on every frame. Note how sendSerial() is added
365 dynamically after the python class is defined, as a new member function of the class. \ingroup python */
366 class PythonModule : public Module, public PythonWrapper
367 {
368 public:
369 //! Constructor needs the full path to a Python source code file
370 /*! Note that, contrary to C++ modules, construction will not throw. This is so that the module is always valid
371 and initialized, and its module path can be set by Engine, which is necessary to allow saving the source code
372 from JeVois Inventor. Instead, any construction error is stored internally in this class and will be re-thrown
373 at any access to process(), parfseSerial(), etc. */
374 PythonModule(VideoMapping const & m);
375
376 //! Load python code and optionally call init() python module function, if implemented
377 void preInit() override;
378
379 //! Virtual destructor for safe inheritance
380 virtual ~PythonModule();
381
382 //! Processing function, version that receives a frame from camera and sends a frame out over USB
383 virtual void process(InputFrame && inframe, OutputFrame && outframe) override;
384
385 //! Processing function, version that receives a frame from camera and does not use USB
386 virtual void process(InputFrame && inframe) override;
387
388#ifdef JEVOIS_PRO
389 //! Processing function, version that receives a frame from camera, no USB, but GUI output on JeVois-Pro
390 virtual void process(InputFrame && inframe, GUIhelper & helper);
391#endif
392
393 //! Receive a string from a serial port which contains a user command
394 virtual void parseSerial(std::string const & str, std::shared_ptr<UserInterface> s) override;
395
396 //! Human-readable description of this Module's supported custom commands
397 virtual void supportedCommands(std::ostream & os) override;
398
399 //! Optionally call uninit() python module function, if implemented
400 void postUninit() override;
401
402 private:
403 std::string itsPyPath;
404 };
405
406 namespace dnn
407 {
408 class PreProcessor;
409
410 //! Pre-Processor interface exposed to the python side
411 /*! This wrapper is passed down to the process() function of a python post-processor, it provides a python-friendly
412 interface to b2i(), blobsizes(), etc \ingroup python */
413 class PreProcessorForPython
414 {
415 public:
416 //! Construct from an existing PreProcessor
417 /*! Caller must ensure that pp outlives us. */
418 PreProcessorForPython(PreProcessor * pp);
419
420 //! Access the last processed image size
421 /*! Returned as a tuple (width, height). */
422 boost::python::tuple imagesize() const;
423
424 //! Access the last computed blobs (or empty if process() has not yet been called)
425 boost::python::list blobs() const;
426
427 //! Access the width and height of a given blob, accounting for NCHW or NHWC
428 /*! Returned as a tuple (width, height). */
429 boost::python::tuple blobsize(size_t num) const;
430
431 //! Convert coordinates from blob back to original image
432 /*! 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
433 convert detected boxes back into original input coordinates. Returned as a tuple (x, y). */
434 boost::python::tuple b2i(float x, float y, size_t blobnum);
435
436 //! Get unscaled crop rectangle in image coordinates
437 /*! This is useful to display an image overlay on top of the input image.
438 Returned as a tuple (x, y, w, h). */
439 boost::python::tuple getUnscaledCropRect(size_t blobnum);
440
441 //! Convert coordinates from image to blob
442 /*! 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
443 to convert mouse coordinates (after they have been converted from screen to image coords) to locations
444 within an input blob. */
445 boost::python::tuple i2b(float x, float y, size_t blobnum);
446
447 private:
448 PreProcessor * itsPP;
449 };
450
451 class PostProcessorDetectYOLO;
452
453 //! YOLO post-processor exposed to python
454 /*! A bit hacky since PostProcessorDetectYOLO is a Component that holds parameters. This class will add a
455 PostProcessorDetectYOLO subcomponent to the current module, and then will forward yolo post-processing requests
456 to it. */
457 class PostProcessorDetectYOLOforPython
458 {
459 public:
460 //! Constructor constructs itsYOLO and adds it to current module
461 PostProcessorDetectYOLOforPython();
462
463 //! Destructor removes itsYOLO from current module
464 ~PostProcessorDetectYOLOforPython();
465
466 //! Freeze/unfreeze parameters that users should not change while running
467 void freeze(bool doit);
468
469 //! Generic raw YOLO processing
470 /*! The returned tuple has 3 elements: list of int for classIds, list of float for confidences, and list of
471 4-element tuples of floats for boxes (x, y, w, h). */
472 boost::python::tuple yolo(boost::python::list outs, int nclass, float boxThreshold,
473 float confThreshold, int bw, int bh, int fudge, int maxbox, bool sigmo);
474
475 private:
476 std::shared_ptr<PostProcessorDetectYOLO> itsYOLO;
477 };
478
479 } // namespace dnn
480} // namespace jevois
int h
Definition GUIhelper.C:2520
Wrapper around GUIhelper to be used by Python.
void itext2(char const *txt)
Draw some overlay text on top of an image, default color and line.
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.
ImVec2 getMousePos()
ImGui helper: get mouse position.
void reportError(std::string const &err)
Report an error in an overlay window.
void releaseImage(char const *name)
Release an image.
ImVec2 d2is1(float x, float y, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
ImVec2 d2is(ImVec2 p, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
ImVec2 d2i(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
void reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
void drawCircle(float x, float y, float r, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw circle over an image.
ImVec2 d2i1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
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.
void drawPoly2(cv::Mat const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
void drawPoly1(std::vector< cv::Point2f > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
ImVec2 i2d1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
void drawPoly(std::vector< cv::Point > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
void endFrame()
Finish current frame and render it.
bool isMouseDown(int button_num)
ImGui helper: check if mouse button pressed.
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.
void drawText(float x, float y, char const *txt, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw text over an image.
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.
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.
ImVec2 i2d(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
void releaseImage2(char const *name)
Release an image, second video stream.
bool isMouseReleased(int button_num)
ImGui helper: check if mouse button released.
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.
ImVec2 i2ds1(float x, float y, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
bool frameStarted() const
Helper to indicate that startFrame() was called, and thus endFrame() should be called.
ImVec2 i2ds(ImVec2 p, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
void itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
Draw some overlay text on top of an image.
bool isMouseDragging(int button_num)
ImGui helper: check if mouse button dragged.
bool isMouseClicked(int button_num)
ImGui helper: check if mouse button clicked.
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.
boost::python::tuple startFrame()
Start a new rendering frame.
void drawEllipse(float x, float y, float rx, float ry, float rot=0.0F, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw ellipse over an image.
void drawLine(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw line over an image.
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.
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.
bool isMouseDoubleClicked(int button_num)
ImGui helper: check if mouse button double-clicked.
Helper class to assist modules in creating graphical and GUI elements.
Definition GUIhelper.H:133
Wrapper around InputFrame to be used by Python.
RawImage const & getp() const
Get the next captured camera image that is intended for processing.
cv::Mat getCvGRAYp() const
Shorthand to get the input image for processing as a GRAY cv::Mat and release the raw buffer.
cv::Mat getCvRGBA() const
Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer.
RawImage const & get2() const
Get the next captured camera image, ISP-scaled second frame.
RawImage const & get1(bool casync) const
Get the next captured camera image, thin wrapper for default arg value.
cv::Mat getCvRGBA1(bool casync) const
Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer.
cv::Mat getCvRGBp() const
Shorthand to get the input image for processing as a RGB cv::Mat and release the raw buffer.
InputFramePython()=default
Default constructor to keep boost::python happy, object is not operational.
cv::Mat getCvRGBAp() const
Shorthand to get the input image for processing as a RGBA cv::Mat and release the raw buffer.
cv::Mat getCvBGR() const
Shorthand to get the input image as a BGR cv::Mat and release the raw buffer.
RawImage const & get() const
Get the next captured camera image, thin wrapper for default arg value.
cv::Mat getCvBGR1(bool casync) const
Shorthand to get the input image as a BGR cv::Mat and release the raw buffer.
cv::Mat getCvBGRp() const
Shorthand to get the input image for processing as a BGR cv::Mat and release the raw buffer.
cv::Mat getCvRGB() const
Shorthand to get the input image as a RGB cv::Mat and release the raw buffer.
RawImage const & get21(bool casync) const
Get the next captured camera image, ISP-scaled second frame.
void done() const
Indicate that user processing is done with the image previously obtained via get()
cv::Mat getCvGRAY1(bool casync) const
Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer.
RawImage const & getp1(bool casync) const
Get the next captured camera image that is intended for processing.
cv::Mat getCvRGB1(bool casync) const
Shorthand to get the input image as a RGB cv::Mat and release the raw buffer.
void done2() const
Indicate that user processing is done with the ISP-scaled image previously obtained via get2()
bool hasScaledImage() const
Check whether a second input image scaled by the JeVoisPro Platform ISP is available.
cv::Mat getCvGRAY() const
Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer.
Exception-safe wrapper around a raw camera input frame.
Definition InputFrame.H:51
Virtual base class for a vision processing module.
Definition Module.H:105
Wrapper around OutputFrame to be used by Python.
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.
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.
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.
RawImage const & get() const
Get the next captured camera image.
void sendCvRGB1(cv::Mat const &img, int quality) const
Shorthand to send a RGB cv::Mat after converting it to the current output format.
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.
void send() const
Indicate that user processing is done with the image previously obtained via get()
void sendScaledCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format.
void sendCvGRAY1(cv::Mat const &img, int quality) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
void sendCvBGR1(cv::Mat const &img, int quality) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.
OutputFramePython()=default
Default constructor to keep boost::python happy, object is not operational.
void sendCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.
void sendScaledCvRGB(cv::Mat const &img) const
Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format.
void sendScaledCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format.
void sendCv1(cv::Mat const &img, int quality) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
void sendCvRGB(cv::Mat const &img) const
Shorthand to send a RGB cv::Mat after converting it to the current output format.
void sendScaledCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format.
void sendCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
void sendCv(cv::Mat const &img) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
void sendCvRGBA1(cv::Mat const &img, int quality) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
void sendCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
Exception-safe wrapper around a raw image to be sent over USB.
Definition OutputFrame.H:53
Wrapper module to allow users to develop new modules written in Python.
virtual void process(InputFrame &&inframe, OutputFrame &&outframe) override
Processing function, version that receives a frame from camera and sends a frame out over USB.
virtual void supportedCommands(std::ostream &os) override
Human-readable description of this Module's supported custom commands.
void postUninit() override
Optionally call uninit() python module function, if implemented.
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.
void preInit() override
Load python code and optionally call init() python module function, if implemented.
virtual ~PythonModule()
Virtual destructor for safe inheritance.
Helper class to run python code from C++.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition RawImage.H:111
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2
Simple struct to hold video mapping definitions for the processing Engine.