JeVois  1.16
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
PythonModule.C
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
21 
22 // ####################################################################################################
23 // ####################################################################################################
24 // ####################################################################################################
25 
27 { }
28 
30 {
31  if (itsInputFrame == nullptr) LFATAL("Internal error");
32  return itsInputFrame->get(casync);
33 }
34 
36 {
37  if (itsInputFrame == nullptr) LFATAL("Internal error");
38  return itsInputFrame->get();
39 }
40 
42 {
43  if (itsInputFrame == nullptr) LFATAL("Internal error");
44  return itsInputFrame->hasScaledImage();
45 }
46 
48 {
49  if (itsInputFrame == nullptr) LFATAL("Internal error");
50  return itsInputFrame->get2(casync);
51 }
52 
54 {
55  if (itsInputFrame == nullptr) LFATAL("Internal error");
56  return itsInputFrame->get2();
57 }
58 
60 {
61  if (itsInputFrame == nullptr) LFATAL("Internal error");
62  return itsInputFrame->getp(casync);
63 }
64 
66 {
67  if (itsInputFrame == nullptr) LFATAL("Internal error");
68  return itsInputFrame->getp();
69 }
70 
72 {
73  if (itsInputFrame == nullptr) LFATAL("Internal error");
74  itsInputFrame->done();
75 }
76 
78 {
79  if (itsInputFrame == nullptr) LFATAL("Internal error");
80  itsInputFrame->done2();
81 }
82 
83 cv::Mat jevois::InputFramePython::getCvGRAY1(bool casync) const
84 {
85  if (itsInputFrame == nullptr) LFATAL("Internal error");
86  return itsInputFrame->getCvGRAY(casync);
87 }
88 
90 {
91  if (itsInputFrame == nullptr) LFATAL("Internal error");
92  return itsInputFrame->getCvGRAY();
93 }
94 
95 cv::Mat jevois::InputFramePython::getCvBGR1(bool casync) const
96 {
97  if (itsInputFrame == nullptr) LFATAL("Internal error");
98  return itsInputFrame->getCvBGR(casync);
99 }
100 
102 {
103  if (itsInputFrame == nullptr) LFATAL("Internal error");
104  return itsInputFrame->getCvBGR();
105 }
106 
107 cv::Mat jevois::InputFramePython::getCvRGB1(bool casync) const
108 {
109  if (itsInputFrame == nullptr) LFATAL("Internal error");
110  return itsInputFrame->getCvRGB(casync);
111 }
112 
114 {
115  if (itsInputFrame == nullptr) LFATAL("Internal error");
116  return itsInputFrame->getCvRGB();
117 }
118 
119 cv::Mat jevois::InputFramePython::getCvRGBA1(bool casync) const
120 {
121  if (itsInputFrame == nullptr) LFATAL("Internal error");
122  return itsInputFrame->getCvRGBA(casync);
123 }
124 
126 {
127  if (itsInputFrame == nullptr) LFATAL("Internal error");
128  return itsInputFrame->getCvRGBA();
129 }
130 
132 {
133  if (itsInputFrame == nullptr) LFATAL("Internal error");
134  return itsInputFrame->getCvGRAYp();
135 }
136 
138 {
139  if (itsInputFrame == nullptr) LFATAL("Internal error");
140  return itsInputFrame->getCvBGRp();
141 }
142 
144 {
145  if (itsInputFrame == nullptr) LFATAL("Internal error");
146  return itsInputFrame->getCvRGBp();
147 }
148 
150 {
151  if (itsInputFrame == nullptr) LFATAL("Internal error");
152  return itsInputFrame->getCvRGBAp();
153 }
154 
155 // ####################################################################################################
156 // ####################################################################################################
157 // ####################################################################################################
159 { }
160 
162 {
163  if (itsOutputFrame == nullptr) LFATAL("Internal error");
164  return itsOutputFrame->get();
165 }
166 
168 {
169  if (itsOutputFrame == nullptr) LFATAL("Internal error");
170  itsOutputFrame->send();
171 }
172 
173 void jevois::OutputFramePython::sendCv1(cv::Mat const & img, int quality) const
174 {
175  if (itsOutputFrame == nullptr) LFATAL("Internal error");
176  itsOutputFrame->sendCv(img, quality);
177 }
178 
179 void jevois::OutputFramePython::sendCv(cv::Mat const & img) const
180 {
181  if (itsOutputFrame == nullptr) LFATAL("Internal error");
182  itsOutputFrame->sendCv(img);
183 }
184 
185 void jevois::OutputFramePython::sendCvGRAY1(cv::Mat const & img, int quality) const
186 {
187  if (itsOutputFrame == nullptr) LFATAL("Internal error");
188  itsOutputFrame->sendCvGRAY(img, quality);
189 }
190 
191 void jevois::OutputFramePython::sendCvGRAY(cv::Mat const & img) const
192 {
193  if (itsOutputFrame == nullptr) LFATAL("Internal error");
194  itsOutputFrame->sendCvGRAY(img);
195 }
196 
197 void jevois::OutputFramePython::sendCvBGR1(cv::Mat const & img, int quality) const
198 {
199  if (itsOutputFrame == nullptr) LFATAL("Internal error");
200  itsOutputFrame->sendCvBGR(img, quality);
201 }
202 
203 void jevois::OutputFramePython::sendCvBGR(cv::Mat const & img) const
204 {
205  if (itsOutputFrame == nullptr) LFATAL("Internal error");
206  itsOutputFrame->sendCvBGR(img);
207 }
208 
209 void jevois::OutputFramePython::sendCvRGB1(cv::Mat const & img, int quality) const
210 {
211  if (itsOutputFrame == nullptr) LFATAL("Internal error");
212  itsOutputFrame->sendCvRGB(img, quality);
213 }
214 
215 void jevois::OutputFramePython::sendCvRGB(cv::Mat const & img) const
216 {
217  if (itsOutputFrame == nullptr) LFATAL("Internal error");
218  itsOutputFrame->sendCvRGB(img);
219 }
220 
221 void jevois::OutputFramePython::sendCvRGBA1(cv::Mat const & img, int quality) const
222 {
223  if (itsOutputFrame == nullptr) LFATAL("Internal error");
224  itsOutputFrame->sendCvRGBA(img, quality);
225 }
226 
227 void jevois::OutputFramePython::sendCvRGBA(cv::Mat const & img) const
228 {
229  if (itsOutputFrame == nullptr) LFATAL("Internal error");
230  itsOutputFrame->sendCvRGBA(img);
231 }
232 
233 void jevois::OutputFramePython::sendScaledCvGRAY1(cv::Mat const & img, int quality) const
234 {
235  if (itsOutputFrame == nullptr) LFATAL("Internal error");
236  itsOutputFrame->sendScaledCvGRAY(img, quality);
237 }
238 
239 void jevois::OutputFramePython::sendScaledCvGRAY(cv::Mat const & img) const
240 {
241  if (itsOutputFrame == nullptr) LFATAL("Internal error");
242  itsOutputFrame->sendScaledCvGRAY(img);
243 }
244 
245 void jevois::OutputFramePython::sendScaledCvBGR1(cv::Mat const & img, int quality) const
246 {
247  if (itsOutputFrame == nullptr) LFATAL("Internal error");
248  itsOutputFrame->sendScaledCvBGR(img, quality);
249 }
250 
251 void jevois::OutputFramePython::sendScaledCvBGR(cv::Mat const & img) const
252 {
253  if (itsOutputFrame == nullptr) LFATAL("Internal error");
254  itsOutputFrame->sendScaledCvBGR(img);
255 }
256 
257 void jevois::OutputFramePython::sendScaledCvRGB1(cv::Mat const & img, int quality) const
258 {
259  if (itsOutputFrame == nullptr) LFATAL("Internal error");
260  itsOutputFrame->sendScaledCvRGB(img, quality);
261 }
262 
263 void jevois::OutputFramePython::sendScaledCvRGB(cv::Mat const & img) const
264 {
265  if (itsOutputFrame == nullptr) LFATAL("Internal error");
266  itsOutputFrame->sendScaledCvRGB(img);
267 }
268 
269 void jevois::OutputFramePython::sendScaledCvRGBA1(cv::Mat const & img, int quality) const
270 {
271  if (itsOutputFrame == nullptr) LFATAL("Internal error");
272  itsOutputFrame->sendScaledCvRGBA(img, quality);
273 }
274 
275 void jevois::OutputFramePython::sendScaledCvRGBA(cv::Mat const & img) const
276 {
277  if (itsOutputFrame == nullptr) LFATAL("Internal error");
278  itsOutputFrame->sendScaledCvRGBA(img);
279 }
280 
281 // ####################################################################################################
282 // ####################################################################################################
283 // ####################################################################################################
284 #ifdef JEVOIS_PRO
286 { }
287 
288 // ####################################################################################################
290 {
291  if (itsGUIhelper == nullptr) LFATAL("Internal error");
292  unsigned short w, h;
293  bool idle = itsGUIhelper->startFrame(w, h);
294  return boost::python::make_tuple(idle, w, h);
295 }
296 
297 // ####################################################################################################
299 {
300  if (itsGUIhelper == nullptr) LFATAL("Internal error");
301  return itsGUIhelper->frameStarted();
302 }
303 
304 // ####################################################################################################
305 boost::python::tuple jevois::GUIhelperPython::drawImage(char const * name, RawImage const & img,
306  bool noalias, bool isoverlay)
307 {
308  if (itsGUIhelper == nullptr) LFATAL("Internal error");
309  int x = 0, y = 0; unsigned short w = 0, h = 0;
310  itsGUIhelper->drawImage(name, img, x, y, w, h, noalias, isoverlay);
311  return boost::python::make_tuple(x, y, w, h);
312 }
313 
314 // ####################################################################################################
315 boost::python::tuple jevois::GUIhelperPython::drawImage1(char const * name, cv::Mat const & img, bool rgb,
316  bool noalias, bool isoverlay)
317 {
318  if (itsGUIhelper == nullptr) LFATAL("Internal error");
319  int x = 0, y = 0; unsigned short w = 0, h = 0;
320  itsGUIhelper->drawImage(name, img, rgb, x, y, w, h, noalias, isoverlay);
321  return boost::python::make_tuple(x, y, w, h);
322 }
323 
324 // ####################################################################################################
325 boost::python::tuple jevois::GUIhelperPython::drawInputFrame(char const * name, InputFramePython const & frame,
326  bool noalias, bool casync)
327 {
328  if (itsGUIhelper == nullptr) LFATAL("Internal error");
329  int x = 0, y = 0; unsigned short w = 0, h = 0;
330  itsGUIhelper->drawInputFrame(name, *frame.itsInputFrame, x, y, w, h, noalias, casync);
331  return boost::python::make_tuple(x, y, w, h);
332 }
333 
334 // ####################################################################################################
335 boost::python::tuple jevois::GUIhelperPython::drawInputFrame2(char const * name, InputFramePython const & frame,
336  bool noalias, bool casync)
337 {
338  if (itsGUIhelper == nullptr) LFATAL("Internal error");
339  int x = 0, y = 0; unsigned short w = 0, h = 0;
340  itsGUIhelper->drawInputFrame(name, *frame.itsInputFrame, x, y, w, h, noalias, casync);
341  return boost::python::make_tuple(x, y, w, h);
342 }
343 
344 // ####################################################################################################
345 ImVec2 jevois::GUIhelperPython::i2d(ImVec2 p, char const * name)
346 {
347  if (itsGUIhelper == nullptr) LFATAL("Internal error");
348  return itsGUIhelper->i2d(p, name);
349 }
350 
351 // ####################################################################################################
352 ImVec2 jevois::GUIhelperPython::i2d1(float x, float y, char const * name)
353 {
354  if (itsGUIhelper == nullptr) LFATAL("Internal error");
355  return itsGUIhelper->i2d(x, y, name);
356 }
357 
358 // ####################################################################################################
359 ImVec2 jevois::GUIhelperPython::i2ds(ImVec2 p, char const * name)
360 {
361  if (itsGUIhelper == nullptr) LFATAL("Internal error");
362  return itsGUIhelper->i2ds(p, name);
363 }
364 
365 // ####################################################################################################
366 ImVec2 jevois::GUIhelperPython::i2ds1(float x, float y, char const * name)
367 {
368  if (itsGUIhelper == nullptr) LFATAL("Internal error");
369  return itsGUIhelper->i2ds(x, y, name);
370 }
371 
372 // ####################################################################################################
373 void jevois::GUIhelperPython::drawLine(float x1, float y1, float x2, float y2, ImU32 col)
374 {
375  if (itsGUIhelper == nullptr) LFATAL("Internal error");
376  itsGUIhelper->drawLine(x1, y1, x2, y2, col);
377 }
378 
379 // ####################################################################################################
380 void jevois::GUIhelperPython::drawRect(float x1, float y1, float x2, float y2, ImU32 col, bool filled)
381 {
382  if (itsGUIhelper == nullptr) LFATAL("Internal error");
383  itsGUIhelper->drawRect(x1, y1, x2, y2, col, filled);
384 }
385 
386 // ####################################################################################################
387 void jevois::GUIhelperPython::drawPoly(std::vector<cv::Point> const & pts, ImU32 col, bool filled)
388 {
389  if (itsGUIhelper == nullptr) LFATAL("Internal error");
390  itsGUIhelper->drawPoly(pts, col, filled);
391 }
392 
393 // ####################################################################################################
394 void jevois::GUIhelperPython::drawPoly1(std::vector<cv::Point2f> const & pts, ImU32 col, bool filled)
395 {
396  if (itsGUIhelper == nullptr) LFATAL("Internal error");
397  itsGUIhelper->drawPoly(pts, col, filled);
398 }
399 
400 // ####################################################################################################
401 void jevois::GUIhelperPython::drawPoly2(cv::Mat const & pts, ImU32 col, bool filled)
402 {
403  if (itsGUIhelper == nullptr) LFATAL("Internal error");
404  if (pts.type() != CV_32FC2) LFATAL("Incorrect type: should be 32FC2");
405 
406  // Convert mat to vector of Point2f:
407  std::vector<cv::Point2f> p;
408  size_t const sz = pts.total() * 2;
409  float const * ptr = pts.ptr<float>(0);
410  for (size_t i = 0; i < sz; i += 2) p.emplace_back(cv::Point2f(ptr[i], ptr[i+1]));
411 
412  // Draw:
413  itsGUIhelper->drawPoly(p, col, filled);
414 }
415 
416 // ####################################################################################################
417 void jevois::GUIhelperPython::drawCircle(float x, float y, float r, ImU32 col, bool filled)
418 {
419  if (itsGUIhelper == nullptr) LFATAL("Internal error");
420  itsGUIhelper->drawCircle(x, y, r, col, filled);
421 }
422 
423 // ####################################################################################################
424 void jevois::GUIhelperPython::drawText(float x, float y, char const * txt, ImU32 col)
425 {
426  if (itsGUIhelper == nullptr) LFATAL("Internal error");
427  itsGUIhelper->drawText(x, y, txt, col);
428 }
429 
430 // ####################################################################################################
431 ImVec2 jevois::GUIhelperPython::iline(int line, char const * name)
432 {
433  if (itsGUIhelper == nullptr) LFATAL("Internal error");
434  return itsGUIhelper->iline(line, name);
435 }
436 
437 // ####################################################################################################
438 void jevois::GUIhelperPython::itext(char const * txt, ImU32 const & col, int line)
439 {
440  if (itsGUIhelper == nullptr) LFATAL("Internal error");
441  itsGUIhelper->itext(txt, col, line);
442 }
443 
444 // ####################################################################################################
445 void jevois::GUIhelperPython::iinfo(jevois::InputFramePython const & inframe, std::string const & fpscpu,
446  unsigned short winw, unsigned short winh)
447 {
448  if (itsGUIhelper == nullptr) LFATAL("Internal error");
449  itsGUIhelper->iinfo(*inframe.itsInputFrame, fpscpu, winw, winh);
450 }
451 
452 // ####################################################################################################
454 {
455  if (itsGUIhelper == nullptr) LFATAL("Internal error");
456  itsGUIhelper->releaseImage(name);
457 }
458 
459 // ####################################################################################################
461 {
462  if (itsGUIhelper == nullptr) LFATAL("Internal error");
463  itsGUIhelper->releaseImage2(name);
464 }
465 
466 // ####################################################################################################
468 {
469  if (itsGUIhelper == nullptr) LFATAL("Internal error");
470  itsGUIhelper->endFrame();
471 }
472 
473 // ####################################################################################################
474 void jevois::GUIhelperPython::reportError(std::string const & err)
475 {
476  if (itsGUIhelper == nullptr) LFATAL("Internal error");
477  itsGUIhelper->reportError(err);
478 }
479 
480 // ####################################################################################################
482 {
483  if (itsGUIhelper == nullptr) LFATAL("Internal error");
484  itsGUIhelper->reportAndIgnoreException(prefix);
485 }
486 
487 // ####################################################################################################
489 {
490  if (itsGUIhelper == nullptr) LFATAL("Internal error");
491  itsGUIhelper->reportAndRethrowException(prefix);
492 }
493 
494 #endif // JEVOIS_PRO
495 
496 // ####################################################################################################
497 // ####################################################################################################
498 // ####################################################################################################
499 namespace
500 {
501  // from https://stackoverflow.com/questions/39924912/finding-if-member-function-exists-in-a-boost-pythonobject
502  bool hasattr(boost::python::object & o, char const * name) { return PyObject_HasAttrString(o.ptr(), name); }
503 }
504 
505 // ####################################################################################################
506 // ####################################################################################################
507 // ####################################################################################################
508 jevois::PythonModule::PythonModule(jevois::VideoMapping const & m) :
509  jevois::Module(m.modulename), itsMainModule(), itsMainNamespace(), itsInstance(), itsConstructionError()
510 {
511  if (m.ispython == false) LFATAL("Passed video mapping is not for a python module");
512 
513  // Do not throw during construction because we need users to be able to save modified code from JeVois Inventor, which
514  // requires a valid module with a valid path being set by Engine:
515  try
516  {
517  // Get the python interpreter going:
518  itsMainModule = boost::python::import("__main__");
519  itsMainNamespace = itsMainModule.attr("__dict__");
520 
521  // Import the module. Note that we import the whole directory:
522  std::string const pypath = m.sopath();
523  std::string const pydir = pypath.substr(0, pypath.rfind('/'));
524  std::string const execstr =
525  "import sys\n"
526  "sys.path.append(\"/usr/lib\")\n" // To find libjevois[pro] module in /usr/lib
527  "sys.path.append(\"" JEVOIS_CONFIG_PATH "\")\n" // To find pyjevois.py config
528  "sys.path.append(\"" JEVOIS_OPENCV_PYTHON_PATH "\")\n" // To find cv2 module
529  "sys.path.append(\"" + pydir + "\")\n" +
530  "import " + m.modulename + "\n" +
531  "import importlib\n" +
532  "importlib.reload(" + m.modulename + ")\n"; // reload so we are always fresh if file changed on SD card
533 
534  boost::python::exec(execstr.c_str(), itsMainNamespace, itsMainNamespace);
535 
536  // Create an instance of the python class defined in the module:
537  itsInstance = boost::python::eval((m.modulename + "." + m.modulename + "()").c_str(),
538  itsMainNamespace, itsMainNamespace);
539  }
540  catch (boost::python::error_already_set & e)
541  {
542  itsConstructionError = "Initialization of Module " + m.modulename + " failed:\n\n" +
544  }
545 }
546 
547 // ####################################################################################################
549 {
550  // Call python module's uninit() function if implemented:
551  if (hasattr(itsInstance, "uninit")) itsInstance.attr("uninit")();
552 }
553 
554 // ####################################################################################################
556 { }
557 
558 // ####################################################################################################
560 {
561  if (itsInstance.is_none()) throw std::runtime_error(itsConstructionError);
562 
563  jevois::InputFramePython inframepy(&inframe);
564  jevois::OutputFramePython outframepy(&outframe);
565  itsInstance.attr("process")(boost::ref(inframepy), boost::ref(outframepy));
566 }
567 
568 // ####################################################################################################
570 {
571  if (itsInstance.is_none()) throw std::runtime_error(itsConstructionError);
572 
573  jevois::InputFramePython inframepy(&inframe);
574  itsInstance.attr("processNoUSB")(boost::ref(inframepy));
575 }
576 
577 #ifdef JEVOIS_PRO
578 
579 // ####################################################################################################
581 {
582  if (itsInstance.is_none()) throw std::runtime_error(itsConstructionError);
583 
584  jevois::InputFramePython inframepy(&inframe);
585  jevois::GUIhelperPython helperpy(&helper);
586  itsInstance.attr("processGUI")(boost::ref(inframepy), boost::ref(helperpy));
587 }
588 
589 #endif
590 
591 // ####################################################################################################
592 void jevois::PythonModule::parseSerial(std::string const & str, std::shared_ptr<UserInterface> s)
593 {
594  if (hasattr(itsInstance, "parseSerial"))
595  {
596  boost::python::object ret = itsInstance.attr("parseSerial")(str);
597  std::string retstr = boost::python::extract<std::string>(ret);
598  if (retstr.empty() == false) s->writeString(retstr);
599  }
600  else jevois::Module::parseSerial(str, s);
601 }
602 
603 // ####################################################################################################
605 {
606  if (hasattr(itsInstance, "supportedCommands"))
607  {
608  boost::python::object ret = itsInstance.attr("supportedCommands")();
609  std::string retstr = boost::python::extract<std::string>(ret);
610  if (retstr.empty() == false) os << retstr;
612 }
613 
614 
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:239
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:107
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:89
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:445
jevois::InputFramePython::get
const RawImage & get() const
Get the next captured camera image, thin wrapper for default arg value.
Definition: PythonModule.C:35
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:173
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:315
jevois::OutputFramePython::get
const RawImage & get() const
Get the next captured camera image.
Definition: PythonModule.C:161
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:387
jevois::InputFramePython::get1
const RawImage & get1(bool casync) const
Get the next captured camera image, thin wrapper for default arg value.
Definition: PythonModule.C:29
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:131
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:438
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:559
jevois::UserInterface::writeString
virtual void writeString(std::string const &str)=0
Write a string.
jevois::OutputFramePython::send
void send() const
Indicate that user processing is done with the image previously obtained via get()
Definition: PythonModule.C:167
jevois::InputFramePython::getp
const RawImage & getp() const
Get the next captured camera image that is intended for processing.
Definition: PythonModule.C:65
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:431
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:143
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:269
jevois::Module::parseSerial
virtual void parseSerial(std::string const &str, std::shared_ptr< UserInterface > s)
Receive a string from a serial port which contains a user command.
Definition: Module.C:63
jevois::InputFramePython::done
void done() const
Indicate that user processing is done with the image previously obtained via get()
Definition: PythonModule.C:71
o
#define o
Definition: Font10x20.C:6
UserInterface.H
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:394
jevois::GUIhelperPython::frameStarted
bool frameStarted() const
Helper to indicate that startFrame() was called, and thus endFrame() should be called.
Definition: PythonModule.C:298
jevois::GUIhelperPython::endFrame
void endFrame()
Finish current frame and render it.
Definition: PythonModule.C:467
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:257
jevois::PythonModule::~PythonModule
virtual ~PythonModule()
Virtual destructor for safe inheritance.
Definition: PythonModule.C:555
jevois::GUIhelper
Helper class to assist modules in creating graphical and GUI elements.
Definition: GUIhelper.H:108
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:424
jevois::GUIhelperPython::GUIhelperPython
GUIhelperPython()=default
Default constructor to keep boost::python happy, object is not operational.
jevois::PythonModule::postUninit
void postUninit() override
Optionally call uninit() python module function, if implemented.
Definition: PythonModule.C:548
jevois::GUIhelperPython::releaseImage2
void releaseImage2(char const *name)
Release an image, second video stream.
Definition: PythonModule.C:460
jevois
Definition: Concepts.dox:1
jevois::GUIhelperPython::startFrame
boost::python::tuple startFrame()
Start a new rendering frame.
Definition: PythonModule.C:289
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:185
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:149
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:137
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:119
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:227
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:209
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:125
jevois::GUIhelperPython::reportAndIgnoreException
void reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
Definition: PythonModule.C:481
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:305
jevois::InputFramePython::get2
const RawImage & get2() const
Get the next captured camera image, ISP-scaled second frame.
Definition: PythonModule.C:53
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:366
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:401
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:59
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:352
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:233
jevois::PythonModule::PythonModule
PythonModule(VideoMapping const &m)
Constructor needs the full path to a Python source code file.
Definition: PythonModule.C:508
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:275
LFATAL
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
Definition: Log.H:217
jevois::OutputFramePython
Wrapper around OutputFrame to be used by Python.
Definition: PythonModule.H:129
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:41
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:359
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:263
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:215
PythonModule.H
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:380
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:245
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:453
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:221
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:203
jevois::InputFramePython::done2
void done2() const
Indicate that user processing is done with the ISP-scaled image previously obtained via get2()
Definition: PythonModule.C:77
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:113
jevois::InputFramePython::get21
const RawImage & get21(bool casync) const
Get the next captured camera image, ISP-scaled second frame.
Definition: PythonModule.C:47
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:95
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:373
jevois::getPythonExceptionString
std::string getPythonExceptionString(boost::python::error_already_set &)
Python exception translation to string so we can print the traceback to our serlog stream.
Definition: PythonException.C:146
PythonException.H
h
int h
Definition: GUIhelper.C:2150
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:325
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:101
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:345
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:417
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:335
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:179
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:83
jevois::GUIhelperPython::reportAndRethrowException
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
Definition: PythonModule.C:488
jevois::Module::supportedCommands
virtual void supportedCommands(std::ostream &os)
Human-readable description of this Module's supported custom commands.
Definition: Module.C:68
jevois::GUIhelperPython::reportError
void reportError(std::string const &err)
Report an error in an overlay window.
Definition: PythonModule.C:474
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:191
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:251
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:197
jevois::InputFramePython
Wrapper around InputFrame to be used by Python.
Definition: PythonModule.H:46