JeVois  1.18
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 
22 #include <jevois/DNN/Utils.H>
24 
25 // ####################################################################################################
26 // ####################################################################################################
27 // ####################################################################################################
28 
30 { }
31 
33 {
34  if (itsInputFrame == nullptr) LFATAL("Internal error");
35  return itsInputFrame->get(casync);
36 }
37 
39 {
40  if (itsInputFrame == nullptr) LFATAL("Internal error");
41  return itsInputFrame->get();
42 }
43 
45 {
46  if (itsInputFrame == nullptr) LFATAL("Internal error");
47  return itsInputFrame->hasScaledImage();
48 }
49 
51 {
52  if (itsInputFrame == nullptr) LFATAL("Internal error");
53  return itsInputFrame->get2(casync);
54 }
55 
57 {
58  if (itsInputFrame == nullptr) LFATAL("Internal error");
59  return itsInputFrame->get2();
60 }
61 
63 {
64  if (itsInputFrame == nullptr) LFATAL("Internal error");
65  return itsInputFrame->getp(casync);
66 }
67 
69 {
70  if (itsInputFrame == nullptr) LFATAL("Internal error");
71  return itsInputFrame->getp();
72 }
73 
75 {
76  if (itsInputFrame == nullptr) LFATAL("Internal error");
77  itsInputFrame->done();
78 }
79 
81 {
82  if (itsInputFrame == nullptr) LFATAL("Internal error");
83  itsInputFrame->done2();
84 }
85 
86 cv::Mat jevois::InputFramePython::getCvGRAY1(bool casync) const
87 {
88  if (itsInputFrame == nullptr) LFATAL("Internal error");
89  return itsInputFrame->getCvGRAY(casync);
90 }
91 
93 {
94  if (itsInputFrame == nullptr) LFATAL("Internal error");
95  return itsInputFrame->getCvGRAY();
96 }
97 
98 cv::Mat jevois::InputFramePython::getCvBGR1(bool casync) const
99 {
100  if (itsInputFrame == nullptr) LFATAL("Internal error");
101  return itsInputFrame->getCvBGR(casync);
102 }
103 
105 {
106  if (itsInputFrame == nullptr) LFATAL("Internal error");
107  return itsInputFrame->getCvBGR();
108 }
109 
110 cv::Mat jevois::InputFramePython::getCvRGB1(bool casync) const
111 {
112  if (itsInputFrame == nullptr) LFATAL("Internal error");
113  return itsInputFrame->getCvRGB(casync);
114 }
115 
117 {
118  if (itsInputFrame == nullptr) LFATAL("Internal error");
119  return itsInputFrame->getCvRGB();
120 }
121 
122 cv::Mat jevois::InputFramePython::getCvRGBA1(bool casync) const
123 {
124  if (itsInputFrame == nullptr) LFATAL("Internal error");
125  return itsInputFrame->getCvRGBA(casync);
126 }
127 
129 {
130  if (itsInputFrame == nullptr) LFATAL("Internal error");
131  return itsInputFrame->getCvRGBA();
132 }
133 
135 {
136  if (itsInputFrame == nullptr) LFATAL("Internal error");
137  return itsInputFrame->getCvGRAYp();
138 }
139 
141 {
142  if (itsInputFrame == nullptr) LFATAL("Internal error");
143  return itsInputFrame->getCvBGRp();
144 }
145 
147 {
148  if (itsInputFrame == nullptr) LFATAL("Internal error");
149  return itsInputFrame->getCvRGBp();
150 }
151 
153 {
154  if (itsInputFrame == nullptr) LFATAL("Internal error");
155  return itsInputFrame->getCvRGBAp();
156 }
157 
158 // ####################################################################################################
159 // ####################################################################################################
160 // ####################################################################################################
162 { }
163 
165 {
166  if (itsOutputFrame == nullptr) LFATAL("Internal error");
167  return itsOutputFrame->get();
168 }
169 
171 {
172  if (itsOutputFrame == nullptr) LFATAL("Internal error");
173  itsOutputFrame->send();
174 }
175 
176 void jevois::OutputFramePython::sendCv1(cv::Mat const & img, int quality) const
177 {
178  if (itsOutputFrame == nullptr) LFATAL("Internal error");
179  itsOutputFrame->sendCv(img, quality);
180 }
181 
182 void jevois::OutputFramePython::sendCv(cv::Mat const & img) const
183 {
184  if (itsOutputFrame == nullptr) LFATAL("Internal error");
185  itsOutputFrame->sendCv(img);
186 }
187 
188 void jevois::OutputFramePython::sendCvGRAY1(cv::Mat const & img, int quality) const
189 {
190  if (itsOutputFrame == nullptr) LFATAL("Internal error");
191  itsOutputFrame->sendCvGRAY(img, quality);
192 }
193 
194 void jevois::OutputFramePython::sendCvGRAY(cv::Mat const & img) const
195 {
196  if (itsOutputFrame == nullptr) LFATAL("Internal error");
197  itsOutputFrame->sendCvGRAY(img);
198 }
199 
200 void jevois::OutputFramePython::sendCvBGR1(cv::Mat const & img, int quality) const
201 {
202  if (itsOutputFrame == nullptr) LFATAL("Internal error");
203  itsOutputFrame->sendCvBGR(img, quality);
204 }
205 
206 void jevois::OutputFramePython::sendCvBGR(cv::Mat const & img) const
207 {
208  if (itsOutputFrame == nullptr) LFATAL("Internal error");
209  itsOutputFrame->sendCvBGR(img);
210 }
211 
212 void jevois::OutputFramePython::sendCvRGB1(cv::Mat const & img, int quality) const
213 {
214  if (itsOutputFrame == nullptr) LFATAL("Internal error");
215  itsOutputFrame->sendCvRGB(img, quality);
216 }
217 
218 void jevois::OutputFramePython::sendCvRGB(cv::Mat const & img) const
219 {
220  if (itsOutputFrame == nullptr) LFATAL("Internal error");
221  itsOutputFrame->sendCvRGB(img);
222 }
223 
224 void jevois::OutputFramePython::sendCvRGBA1(cv::Mat const & img, int quality) const
225 {
226  if (itsOutputFrame == nullptr) LFATAL("Internal error");
227  itsOutputFrame->sendCvRGBA(img, quality);
228 }
229 
230 void jevois::OutputFramePython::sendCvRGBA(cv::Mat const & img) const
231 {
232  if (itsOutputFrame == nullptr) LFATAL("Internal error");
233  itsOutputFrame->sendCvRGBA(img);
234 }
235 
236 void jevois::OutputFramePython::sendScaledCvGRAY1(cv::Mat const & img, int quality) const
237 {
238  if (itsOutputFrame == nullptr) LFATAL("Internal error");
239  itsOutputFrame->sendScaledCvGRAY(img, quality);
240 }
241 
242 void jevois::OutputFramePython::sendScaledCvGRAY(cv::Mat const & img) const
243 {
244  if (itsOutputFrame == nullptr) LFATAL("Internal error");
245  itsOutputFrame->sendScaledCvGRAY(img);
246 }
247 
248 void jevois::OutputFramePython::sendScaledCvBGR1(cv::Mat const & img, int quality) const
249 {
250  if (itsOutputFrame == nullptr) LFATAL("Internal error");
251  itsOutputFrame->sendScaledCvBGR(img, quality);
252 }
253 
254 void jevois::OutputFramePython::sendScaledCvBGR(cv::Mat const & img) const
255 {
256  if (itsOutputFrame == nullptr) LFATAL("Internal error");
257  itsOutputFrame->sendScaledCvBGR(img);
258 }
259 
260 void jevois::OutputFramePython::sendScaledCvRGB1(cv::Mat const & img, int quality) const
261 {
262  if (itsOutputFrame == nullptr) LFATAL("Internal error");
263  itsOutputFrame->sendScaledCvRGB(img, quality);
264 }
265 
266 void jevois::OutputFramePython::sendScaledCvRGB(cv::Mat const & img) const
267 {
268  if (itsOutputFrame == nullptr) LFATAL("Internal error");
269  itsOutputFrame->sendScaledCvRGB(img);
270 }
271 
272 void jevois::OutputFramePython::sendScaledCvRGBA1(cv::Mat const & img, int quality) const
273 {
274  if (itsOutputFrame == nullptr) LFATAL("Internal error");
275  itsOutputFrame->sendScaledCvRGBA(img, quality);
276 }
277 
278 void jevois::OutputFramePython::sendScaledCvRGBA(cv::Mat const & img) const
279 {
280  if (itsOutputFrame == nullptr) LFATAL("Internal error");
281  itsOutputFrame->sendScaledCvRGBA(img);
282 }
283 
284 // ####################################################################################################
285 // ####################################################################################################
286 // ####################################################################################################
287 #ifdef JEVOIS_PRO
289 { }
290 
291 // ####################################################################################################
293 {
294  if (itsGUIhelper == nullptr) LFATAL("Internal error");
295  unsigned short w, h;
296  bool idle = itsGUIhelper->startFrame(w, h);
297  return boost::python::make_tuple(idle, w, h);
298 }
299 
300 // ####################################################################################################
302 {
303  if (itsGUIhelper == nullptr) LFATAL("Internal error");
304  return itsGUIhelper->frameStarted();
305 }
306 
307 // ####################################################################################################
308 boost::python::tuple jevois::GUIhelperPython::drawImage(char const * name, RawImage const & img,
309  bool noalias, bool isoverlay)
310 {
311  if (itsGUIhelper == nullptr) LFATAL("Internal error");
312  int x = 0, y = 0; unsigned short w = 0, h = 0;
313  itsGUIhelper->drawImage(name, img, x, y, w, h, noalias, isoverlay);
314  return boost::python::make_tuple(x, y, w, h);
315 }
316 
317 // ####################################################################################################
318 boost::python::tuple jevois::GUIhelperPython::drawImage1(char const * name, cv::Mat const & img, bool rgb,
319  bool noalias, bool isoverlay)
320 {
321  if (itsGUIhelper == nullptr) LFATAL("Internal error");
322  int x = 0, y = 0; unsigned short w = 0, h = 0;
323  itsGUIhelper->drawImage(name, img, rgb, x, y, w, h, noalias, isoverlay);
324  return boost::python::make_tuple(x, y, w, h);
325 }
326 
327 // ####################################################################################################
328 boost::python::tuple jevois::GUIhelperPython::drawInputFrame(char const * name, InputFramePython const & frame,
329  bool noalias, bool casync)
330 {
331  if (itsGUIhelper == nullptr) LFATAL("Internal error");
332  int x = 0, y = 0; unsigned short w = 0, h = 0;
333  itsGUIhelper->drawInputFrame(name, *frame.itsInputFrame, x, y, w, h, noalias, casync);
334  return boost::python::make_tuple(x, y, w, h);
335 }
336 
337 // ####################################################################################################
338 boost::python::tuple jevois::GUIhelperPython::drawInputFrame2(char const * name, InputFramePython const & frame,
339  bool noalias, bool casync)
340 {
341  if (itsGUIhelper == nullptr) LFATAL("Internal error");
342  int x = 0, y = 0; unsigned short w = 0, h = 0;
343  itsGUIhelper->drawInputFrame(name, *frame.itsInputFrame, x, y, w, h, noalias, casync);
344  return boost::python::make_tuple(x, y, w, h);
345 }
346 
347 // ####################################################################################################
348 ImVec2 jevois::GUIhelperPython::i2d(ImVec2 p, char const * name)
349 {
350  if (itsGUIhelper == nullptr) LFATAL("Internal error");
351  return itsGUIhelper->i2d(p, name);
352 }
353 
354 // ####################################################################################################
355 ImVec2 jevois::GUIhelperPython::i2d1(float x, float y, char const * name)
356 {
357  if (itsGUIhelper == nullptr) LFATAL("Internal error");
358  return itsGUIhelper->i2d(x, y, name);
359 }
360 
361 // ####################################################################################################
362 ImVec2 jevois::GUIhelperPython::i2ds(ImVec2 p, char const * name)
363 {
364  if (itsGUIhelper == nullptr) LFATAL("Internal error");
365  return itsGUIhelper->i2ds(p, name);
366 }
367 
368 // ####################################################################################################
369 ImVec2 jevois::GUIhelperPython::i2ds1(float x, float y, char const * name)
370 {
371  if (itsGUIhelper == nullptr) LFATAL("Internal error");
372  return itsGUIhelper->i2ds(x, y, name);
373 }
374 
375 // ####################################################################################################
376 ImVec2 jevois::GUIhelperPython::d2i(ImVec2 p, char const * name)
377 {
378  if (itsGUIhelper == nullptr) LFATAL("Internal error");
379  return itsGUIhelper->d2i(p, name);
380 }
381 
382 // ####################################################################################################
383 ImVec2 jevois::GUIhelperPython::d2i1(float x, float y, char const * name)
384 {
385  if (itsGUIhelper == nullptr) LFATAL("Internal error");
386  return itsGUIhelper->d2i(x, y, name);
387 }
388 
389 // ####################################################################################################
390 ImVec2 jevois::GUIhelperPython::d2is(ImVec2 p, char const * name)
391 {
392  if (itsGUIhelper == nullptr) LFATAL("Internal error");
393  return itsGUIhelper->d2is(p, name);
394 }
395 
396 // ####################################################################################################
397 ImVec2 jevois::GUIhelperPython::d2is1(float x, float y, char const * name)
398 {
399  if (itsGUIhelper == nullptr) LFATAL("Internal error");
400  return itsGUIhelper->d2is(x, y, name);
401 }
402 
403 // ####################################################################################################
404 void jevois::GUIhelperPython::drawLine(float x1, float y1, float x2, float y2, ImU32 col)
405 {
406  if (itsGUIhelper == nullptr) LFATAL("Internal error");
407  itsGUIhelper->drawLine(x1, y1, x2, y2, col);
408 }
409 
410 // ####################################################################################################
411 void jevois::GUIhelperPython::drawRect(float x1, float y1, float x2, float y2, ImU32 col, bool filled)
412 {
413  if (itsGUIhelper == nullptr) LFATAL("Internal error");
414  itsGUIhelper->drawRect(x1, y1, x2, y2, col, filled);
415 }
416 
417 // ####################################################################################################
418 void jevois::GUIhelperPython::drawPoly(std::vector<cv::Point> const & pts, ImU32 col, bool filled)
419 {
420  if (itsGUIhelper == nullptr) LFATAL("Internal error");
421  itsGUIhelper->drawPoly(pts, col, filled);
422 }
423 
424 // ####################################################################################################
425 void jevois::GUIhelperPython::drawPoly1(std::vector<cv::Point2f> const & pts, ImU32 col, bool filled)
426 {
427  if (itsGUIhelper == nullptr) LFATAL("Internal error");
428  itsGUIhelper->drawPoly(pts, col, filled);
429 }
430 
431 // ####################################################################################################
432 void jevois::GUIhelperPython::drawPoly2(cv::Mat const & pts, ImU32 col, bool filled)
433 {
434  if (itsGUIhelper == nullptr) LFATAL("Internal error");
435  if (pts.total() == 0) return;
436 
437  // Convert mat to vectors of Point2f (one poly per mat row), and draw each poly:
438  int imax;
439  if (pts.type() == CV_32FC2) imax = pts.cols * 2;
440  else if (pts.type() == CV_32F) imax = pts.cols;
441  else LFATAL("Incorrect input " << jevois::dnn::shapestr(pts) << ": should be 32F or 32FC2");
442 
443  if (imax < 4) return; // need at least 2 vertices
444 
445  float const * ptr = pts.ptr<float>(0);
446 
447  for (int j = 0; j < pts.rows; ++j)
448  {
449  std::vector<cv::Point2f> p;
450  for (int i = 0; i < imax; i += 2) { p.emplace_back(cv::Point2f(ptr[0], ptr[1])); ptr += 2; }
451  itsGUIhelper->drawPoly(p, col, filled);
452  }
453 }
454 
455 // ####################################################################################################
456 void jevois::GUIhelperPython::drawCircle(float x, float y, float r, ImU32 col, bool filled)
457 {
458  if (itsGUIhelper == nullptr) LFATAL("Internal error");
459  itsGUIhelper->drawCircle(x, y, r, col, filled);
460 }
461 
462 // ####################################################################################################
463 void jevois::GUIhelperPython::drawText(float x, float y, char const * txt, ImU32 col)
464 {
465  if (itsGUIhelper == nullptr) LFATAL("Internal error");
466  itsGUIhelper->drawText(x, y, txt, col);
467 }
468 
469 // ####################################################################################################
470 ImVec2 jevois::GUIhelperPython::iline(int line, char const * name)
471 {
472  if (itsGUIhelper == nullptr) LFATAL("Internal error");
473  return itsGUIhelper->iline(line, name);
474 }
475 
476 // ####################################################################################################
477 void jevois::GUIhelperPython::itext(char const * txt, ImU32 const & col, int line)
478 {
479  if (itsGUIhelper == nullptr) LFATAL("Internal error");
480  itsGUIhelper->itext(txt, col, line);
481 }
482 
483 // ####################################################################################################
484 void jevois::GUIhelperPython::iinfo(jevois::InputFramePython const & inframe, std::string const & fpscpu,
485  unsigned short winw, unsigned short winh)
486 {
487  if (itsGUIhelper == nullptr) LFATAL("Internal error");
488  itsGUIhelper->iinfo(*inframe.itsInputFrame, fpscpu, winw, winh);
489 }
490 
491 // ####################################################################################################
493 {
494  if (itsGUIhelper == nullptr) LFATAL("Internal error");
495  itsGUIhelper->releaseImage(name);
496 }
497 
498 // ####################################################################################################
500 {
501  if (itsGUIhelper == nullptr) LFATAL("Internal error");
502  itsGUIhelper->releaseImage2(name);
503 }
504 
505 // ####################################################################################################
507 {
508  if (itsGUIhelper == nullptr) LFATAL("Internal error");
509  itsGUIhelper->endFrame();
510 }
511 
512 // ####################################################################################################
513 void jevois::GUIhelperPython::reportError(std::string const & err)
514 {
515  if (itsGUIhelper == nullptr) LFATAL("Internal error");
516  itsGUIhelper->reportError(err);
517 }
518 
519 // ####################################################################################################
521 {
522  if (itsGUIhelper == nullptr) LFATAL("Internal error");
523  itsGUIhelper->reportAndIgnoreException(prefix);
524 }
525 
526 // ####################################################################################################
528 {
529  if (itsGUIhelper == nullptr) LFATAL("Internal error");
530  itsGUIhelper->reportAndRethrowException(prefix);
531 }
532 
533 #endif // JEVOIS_PRO
534 
535 // ####################################################################################################
536 // ####################################################################################################
537 // ####################################################################################################
538 jevois::PythonModule::PythonModule(jevois::VideoMapping const & m) : jevois::Module(m.modulename), itsPyPath(m.sopath())
539 {
540  if (m.ispython == false) LFATAL("Passed video mapping is not for a python module");
541 }
542 
543 // ####################################################################################################
545 {
546  // Load the python code and instantiate the python class:
547  PythonWrapper::pythonload(itsPyPath);
548 
549  // Call python module's init() function if implemented:
551 }
552 
553 // ####################################################################################################
555 {
556  // Call python module's uninit() function if implemented:
557  if (jevois::python::hasattr(PythonWrapper::pyinst(), "uninit")) PythonWrapper::pyinst().attr("uninit")();
558 }
559 
560 // ####################################################################################################
562 { }
563 
564 // ####################################################################################################
566 {
567  jevois::InputFramePython inframepy(&inframe);
568  jevois::OutputFramePython outframepy(&outframe);
569  PythonWrapper::pyinst().attr("process")(boost::ref(inframepy), boost::ref(outframepy));
570 }
571 
572 // ####################################################################################################
574 {
575  jevois::InputFramePython inframepy(&inframe);
576  PythonWrapper::pyinst().attr("processNoUSB")(boost::ref(inframepy));
577 }
578 
579 #ifdef JEVOIS_PRO
580 
581 // ####################################################################################################
583 {
584  jevois::InputFramePython inframepy(&inframe);
585  jevois::GUIhelperPython helperpy(&helper);
586  PythonWrapper::pyinst().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 (jevois::python::hasattr(PythonWrapper::pyinst(), "parseSerial"))
595  {
596  boost::python::object ret = PythonWrapper::pyinst().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 (jevois::python::hasattr(PythonWrapper::pyinst(), "supportedCommands"))
607  {
608  boost::python::object ret = PythonWrapper::pyinst().attr("supportedCommands")();
609  std::string retstr = boost::python::extract<std::string>(ret);
610  if (retstr.empty() == false) os << retstr;
612 }
613 
614 // ####################################################################################################
615 // ####################################################################################################
616 // ####################################################################################################
618 { }
619 
621 { return itsPP->imagesize(); }
622 
623 boost::python::list jevois::dnn::PreProcessorForPython::blobs() const
624 { return jevois::python::pyVecToList(itsPP->blobs()); }
625 
627 { return itsPP->blobsize(num); }
628 
629 cv::Point2f jevois::dnn::PreProcessorForPython::b2i(float x, float y, size_t blobnum)
630 { cv::Point2f p(x, y); itsPP->b2i(p.x, p.y, blobnum); return p; }
631 
633 { return itsPP->getUnscaledCropRect(blobnum); }
634 
635 
jevois::OutputFramePython::sendScaledCvGRAY
void sendScaledCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:242
jevois::InputFramePython::getCvRGB1
cv::Mat getCvRGB1(bool casync) const
Shorthand to get the input image as a RGB cv::Mat and release the raw buffer.
Definition: PythonModule.C:110
jevois::OutputFrame
Exception-safe wrapper around a raw image to be sent over USB.
Definition: OutputFrame.H:52
jevois::InputFramePython::getCvGRAY
cv::Mat getCvGRAY() const
Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer.
Definition: PythonModule.C:92
jevois::GUIhelperPython::iinfo
void iinfo(jevois::InputFramePython const &inframe, std::string const &fpscpu, unsigned short winw=0, unsigned short winh=0)
Display processing and video info at bottom of screen.
Definition: PythonModule.C:484
PythonSupport.H
jevois::InputFramePython::get
const RawImage & get() const
Get the next captured camera image, thin wrapper for default arg value.
Definition: PythonModule.C:38
jevois::OutputFramePython::sendCv1
void sendCv1(cv::Mat const &img, int quality) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:176
jevois::GUIhelperPython::drawImage1
boost::python::tuple drawImage1(char const *name, cv::Mat const &img, bool rgb, bool noalias=false, bool isoverlay=false)
Draw an OpenCV image, copying pixel data to an OpenGL texture.
Definition: PythonModule.C:318
jevois::OutputFramePython::get
const RawImage & get() const
Get the next captured camera image.
Definition: PythonModule.C:164
jevois::GUIhelperPython::drawPoly
void drawPoly(std::vector< cv::Point > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
Definition: PythonModule.C:418
jevois::python::pyVecToList
boost::python::list pyVecToList(std::vector< T > const &v)
Helper to convert std::vector<T> to python list.
jevois::dnn::PreProcessorForPython::b2i
cv::Point2f b2i(float x, float y, size_t blobnum)
Convert coordinates from blob back to original image.
Definition: PythonModule.C:629
jevois::PythonWrapper::pyinst
boost::python::object & pyinst()
Get the python class pyinst, or throw if construction error occurred (e.g., file not found)
Definition: PythonWrapper.C:85
jevois::InputFramePython::get1
const RawImage & get1(bool casync) const
Get the next captured camera image, thin wrapper for default arg value.
Definition: PythonModule.C:32
jevois::InputFramePython::getCvGRAYp
cv::Mat getCvGRAYp() const
Shorthand to get the input image for processing as a GRAY cv::Mat and release the raw buffer.
Definition: PythonModule.C:134
jevois::GUIhelperPython::itext
void itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
Draw some overlay text on top of an image.
Definition: PythonModule.C:477
jevois::dnn::PreProcessorForPython::getUnscaledCropRect
cv::Rect getUnscaledCropRect(size_t blobnum)
Get unscaled crop rectangle in image coordinates.
Definition: PythonModule.C:632
jevois::PythonModule::process
virtual void process(InputFrame &&inframe, OutputFrame &&outframe) override
Processing function, version that receives a frame from camera and sends a frame out over USB.
Definition: PythonModule.C:565
jevois::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:170
Utils.H
jevois::InputFramePython::getp
const RawImage & getp() const
Get the next captured camera image that is intended for processing.
Definition: PythonModule.C:68
jevois::GUIhelperPython::iline
ImVec2 iline(int line=-1, char const *name=nullptr)
Get coordinates of the start of a given line of text to be drawn as overlay on top of an image.
Definition: PythonModule.C:470
jevois::InputFramePython::getCvRGBp
cv::Mat getCvRGBp() const
Shorthand to get the input image for processing as a RGB cv::Mat and release the raw buffer.
Definition: PythonModule.C:146
jevois::RawImage
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
jevois::OutputFramePython::sendScaledCvRGBA1
void sendScaledCvRGBA1(cv::Mat const &img, int quality) const
Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:272
jevois::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:74
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:425
jevois::GUIhelperPython::frameStarted
bool frameStarted() const
Helper to indicate that startFrame() was called, and thus endFrame() should be called.
Definition: PythonModule.C:301
jevois::GUIhelperPython::endFrame
void endFrame()
Finish current frame and render it.
Definition: PythonModule.C:506
jevois::GUIhelperPython
Wrapper around GUIhelper to be used by Python.
Definition: PythonModule.H:224
jevois::OutputFramePython::sendScaledCvRGB1
void sendScaledCvRGB1(cv::Mat const &img, int quality) const
Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:260
jevois::PythonModule::~PythonModule
virtual ~PythonModule()
Virtual destructor for safe inheritance.
Definition: PythonModule.C:561
jevois::GUIhelper
Helper class to assist modules in creating graphical and GUI elements.
Definition: GUIhelper.H:122
jevois::GUIhelperPython::drawText
void drawText(float x, float y, char const *txt, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw text over an image.
Definition: PythonModule.C:463
PreProcessorPython.H
jevois::GUIhelperPython::d2i1
ImVec2 d2i1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
Definition: PythonModule.C:383
jevois::PythonModule::postUninit
void postUninit() override
Optionally call uninit() python module function, if implemented.
Definition: PythonModule.C:554
jevois::dnn::shapestr
std::string shapestr(cv::Mat const &m)
Get a string of the form: "nD AxBxC... TYPE" from an n-dimensional cv::Mat with data type TYPE.
Definition: Utils.C:104
jevois::GUIhelperPython::releaseImage2
void releaseImage2(char const *name)
Release an image, second video stream.
Definition: PythonModule.C:499
jevois
Definition: Concepts.dox:1
jevois::GUIhelperPython::d2is1
ImVec2 d2is1(float x, float y, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
Definition: PythonModule.C:397
jevois::GUIhelperPython::startFrame
boost::python::tuple startFrame()
Start a new rendering frame.
Definition: PythonModule.C:292
jevois::OutputFramePython::sendCvGRAY1
void sendCvGRAY1(cv::Mat const &img, int quality) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
Definition: PythonModule.C:188
jevois::InputFramePython::getCvRGBAp
cv::Mat getCvRGBAp() const
Shorthand to get the input image for processing as a RGBA cv::Mat and release the raw buffer.
Definition: PythonModule.C:152
jevois::InputFramePython::getCvBGRp
cv::Mat getCvBGRp() const
Shorthand to get the input image for processing as a BGR cv::Mat and release the raw buffer.
Definition: PythonModule.C:140
jevois::dnn::PreProcessor
Pre-Processor for neural network pipeline.
Definition: PreProcessor.H:102
jevois::InputFramePython::getCvRGBA1
cv::Mat getCvRGBA1(bool casync) const
Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer.
Definition: PythonModule.C:122
jevois::python::hasattr
bool hasattr(boost::python::object &o, char const *name)
Check whether a boost::python::object has an attribute.
Definition: PythonSupport.C:107
jevois::OutputFramePython::sendCvRGBA
void sendCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
Definition: PythonModule.C:230
jevois::OutputFramePython::sendCvRGB1
void sendCvRGB1(cv::Mat const &img, int quality) const
Shorthand to send a RGB cv::Mat after converting it to the current output format.
Definition: PythonModule.C:212
jevois::InputFramePython::getCvRGBA
cv::Mat getCvRGBA() const
Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer.
Definition: PythonModule.C:128
jevois::GUIhelperPython::reportAndIgnoreException
void reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
Definition: PythonModule.C:520
jevois::GUIhelperPython::drawImage
boost::python::tuple drawImage(char const *name, RawImage const &img, bool noalias=false, bool isoverlay=false)
Draw a RawImage, copying pixel data to an OpenGL texture.
Definition: PythonModule.C:308
jevois::InputFramePython::get2
const RawImage & get2() const
Get the next captured camera image, ISP-scaled second frame.
Definition: PythonModule.C:56
jevois::GUIhelperPython::i2ds1
ImVec2 i2ds1(float x, float y, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
Definition: PythonModule.C:369
jevois::PythonModule::preInit
void preInit() override
Load python code and optionally call init() python module function, if implemented.
Definition: PythonModule.C:544
jevois::GUIhelperPython::drawPoly2
void drawPoly2(cv::Mat const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
Definition: PythonModule.C:432
jevois::PythonModule::supportedCommands
virtual void supportedCommands(std::ostream &os) override
Human-readable description of this Module's supported custom commands.
Definition: PythonModule.C:604
jevois::InputFramePython::getp1
const RawImage & getp1(bool casync) const
Get the next captured camera image that is intended for processing.
Definition: PythonModule.C:62
jevois::dnn::PreProcessorForPython::PreProcessorForPython
PreProcessorForPython(PreProcessor *pp)
Construct from an existing PreProcessor.
Definition: PythonModule.C:617
jevois::GUIhelperPython::i2d1
ImVec2 i2d1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
Definition: PythonModule.C:355
jevois::dnn::PreProcessorForPython::blobs
boost::python::list blobs() const
Access the last computed blobs (or empty if process() has not yet been called)
Definition: PythonModule.C:623
jevois::OutputFramePython::sendScaledCvGRAY1
void sendScaledCvGRAY1(cv::Mat const &img, int quality) const
Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:236
jevois::PythonModule::PythonModule
PythonModule(VideoMapping const &m)
Constructor needs the full path to a Python source code file.
Definition: PythonModule.C:538
jevois::OutputFramePython::sendScaledCvRGBA
void sendScaledCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:278
jevois::GUIhelperPython::d2i
ImVec2 d2i(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
Definition: PythonModule.C:376
LFATAL
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
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:44
jevois::GUIhelperPython::i2ds
ImVec2 i2ds(ImVec2 p, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
Definition: PythonModule.C:362
jevois::OutputFramePython::sendScaledCvRGB
void sendScaledCvRGB(cv::Mat const &img) const
Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:266
jevois::OutputFramePython::sendCvRGB
void sendCvRGB(cv::Mat const &img) const
Shorthand to send a RGB cv::Mat after converting it to the current output format.
Definition: PythonModule.C:218
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:411
jevois::OutputFramePython::sendScaledCvBGR1
void sendScaledCvBGR1(cv::Mat const &img, int quality) const
Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:248
jevois::InputFrame
Exception-safe wrapper around a raw camera input frame.
Definition: InputFrame.H:50
jevois::GUIhelperPython::releaseImage
void releaseImage(char const *name)
Release an image.
Definition: PythonModule.C:492
jevois::OutputFramePython::sendCvRGBA1
void sendCvRGBA1(cv::Mat const &img, int quality) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
Definition: PythonModule.C:224
jevois::OutputFramePython::OutputFramePython
OutputFramePython()=default
Default constructor to keep boost::python happy, object is not operational.
jevois::dnn::PreProcessorForPython::imagesize
cv::Size imagesize() const
Access the last processed image size.
Definition: PythonModule.C:620
jevois::OutputFramePython::sendCvBGR
void sendCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.
Definition: PythonModule.C:206
jevois::InputFramePython::done2
void done2() const
Indicate that user processing is done with the ISP-scaled image previously obtained via get2()
Definition: PythonModule.C:80
jevois::dnn::PreProcessorForPython::blobsize
cv::Size blobsize(size_t num) const
Access the width and height of a given blob, accounting for NCHW or NHWC.
Definition: PythonModule.C:626
jevois::InputFramePython::getCvRGB
cv::Mat getCvRGB() const
Shorthand to get the input image as a RGB cv::Mat and release the raw buffer.
Definition: PythonModule.C:116
jevois::InputFramePython::get21
const RawImage & get21(bool casync) const
Get the next captured camera image, ISP-scaled second frame.
Definition: PythonModule.C:50
jevois::InputFramePython::InputFramePython
InputFramePython()=default
Default constructor to keep boost::python happy, object is not operational.
jevois::InputFramePython::getCvBGR1
cv::Mat getCvBGR1(bool casync) const
Shorthand to get the input image as a BGR cv::Mat and release the raw buffer.
Definition: PythonModule.C:98
jevois::PythonWrapper::pythonload
void pythonload(std::string const &path)
Init from path if default constructor was used.
Definition: PythonWrapper.C:34
jevois::GUIhelperPython::drawLine
void drawLine(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw line over an image.
Definition: PythonModule.C:404
jevois::GUIhelperPython::GUIhelperPython
GUIhelperPython(GUIhelper *src)
Construct from a regular GUIhelper that should be be coming from Engine.
Definition: PythonModule.C:288
PythonException.H
h
int h
Definition: GUIhelper.C:1968
jevois::GUIhelperPython::drawInputFrame
boost::python::tuple drawInputFrame(char const *name, InputFramePython const &frame, bool noalias=false, bool casync=false)
Draw the input video frame from the camera using zero-copy.
Definition: PythonModule.C:328
jevois::InputFramePython::getCvBGR
cv::Mat getCvBGR() const
Shorthand to get the input image as a BGR cv::Mat and release the raw buffer.
Definition: PythonModule.C:104
jevois::GUIhelperPython::i2d
ImVec2 i2d(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
Definition: PythonModule.C:348
jevois::GUIhelperPython::drawCircle
void drawCircle(float x, float y, float r, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw circle over an image.
Definition: PythonModule.C:456
jevois::GUIhelperPython::drawInputFrame2
boost::python::tuple drawInputFrame2(char const *name, InputFramePython const &frame, bool noalias=false, bool casync=false)
Draw the second (scaled) input video frame from the camera using zero-copy.
Definition: PythonModule.C:338
jevois::PythonModule::parseSerial
virtual void parseSerial(std::string const &str, std::shared_ptr< UserInterface > s) override
Receive a string from a serial port which contains a user command.
Definition: PythonModule.C:592
jevois::OutputFramePython::sendCv
void sendCv(cv::Mat const &img) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:182
jevois::InputFramePython::getCvGRAY1
cv::Mat getCvGRAY1(bool casync) const
Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer.
Definition: PythonModule.C:86
jevois::GUIhelperPython::reportAndRethrowException
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
Definition: PythonModule.C:527
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:513
jevois::OutputFramePython::sendCvGRAY
void sendCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
Definition: PythonModule.C:194
jevois::GUIhelperPython::d2is
ImVec2 d2is(ImVec2 p, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
Definition: PythonModule.C:390
jevois::OutputFramePython::sendScaledCvBGR
void sendScaledCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format.
Definition: PythonModule.C:254
jevois::OutputFramePython::sendCvBGR1
void sendCvBGR1(cv::Mat const &img, int quality) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.
Definition: PythonModule.C:200
jevois::InputFramePython
Wrapper around InputFrame to be used by Python.
Definition: PythonModule.H:46