JeVois
1.17
JeVois Smart Embedded Machine Vision Toolkit
|
Share this page: |
|
|
|
 |
 |
|
Go to the documentation of this file.
31 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
32 return itsInputFrame->get(casync);
37 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
38 return itsInputFrame->get();
43 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
44 return itsInputFrame->hasScaledImage();
49 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
50 return itsInputFrame->get2(casync);
55 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
56 return itsInputFrame->get2();
61 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
62 return itsInputFrame->getp(casync);
67 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
68 return itsInputFrame->getp();
73 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
74 itsInputFrame->done();
79 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
80 itsInputFrame->done2();
85 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
86 return itsInputFrame->getCvGRAY(casync);
91 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
92 return itsInputFrame->getCvGRAY();
97 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
98 return itsInputFrame->getCvBGR(casync);
103 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
104 return itsInputFrame->getCvBGR();
109 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
110 return itsInputFrame->getCvRGB(casync);
115 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
116 return itsInputFrame->getCvRGB();
121 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
122 return itsInputFrame->getCvRGBA(casync);
127 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
128 return itsInputFrame->getCvRGBA();
133 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
134 return itsInputFrame->getCvGRAYp();
139 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
140 return itsInputFrame->getCvBGRp();
145 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
146 return itsInputFrame->getCvRGBp();
151 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
152 return itsInputFrame->getCvRGBAp();
163 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
164 return itsOutputFrame->get();
169 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
170 itsOutputFrame->send();
175 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
176 itsOutputFrame->sendCv(img, quality);
181 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
182 itsOutputFrame->sendCv(img);
187 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
188 itsOutputFrame->sendCvGRAY(img, quality);
193 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
194 itsOutputFrame->sendCvGRAY(img);
199 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
200 itsOutputFrame->sendCvBGR(img, quality);
205 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
206 itsOutputFrame->sendCvBGR(img);
211 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
212 itsOutputFrame->sendCvRGB(img, quality);
217 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
218 itsOutputFrame->sendCvRGB(img);
223 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
224 itsOutputFrame->sendCvRGBA(img, quality);
229 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
230 itsOutputFrame->sendCvRGBA(img);
235 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
236 itsOutputFrame->sendScaledCvGRAY(img, quality);
241 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
242 itsOutputFrame->sendScaledCvGRAY(img);
247 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
248 itsOutputFrame->sendScaledCvBGR(img, quality);
253 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
254 itsOutputFrame->sendScaledCvBGR(img);
259 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
260 itsOutputFrame->sendScaledCvRGB(img, quality);
265 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
266 itsOutputFrame->sendScaledCvRGB(img);
271 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
272 itsOutputFrame->sendScaledCvRGBA(img, quality);
277 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
278 itsOutputFrame->sendScaledCvRGBA(img);
291 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
293 bool idle = itsGUIhelper->startFrame(w,
h);
294 return boost::python::make_tuple(idle, w,
h);
300 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
301 return itsGUIhelper->frameStarted();
306 bool noalias,
bool isoverlay)
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);
316 bool noalias,
bool isoverlay)
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);
326 bool noalias,
bool casync)
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);
336 bool noalias,
bool casync)
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);
347 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
348 return itsGUIhelper->i2d(p, name);
354 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
355 return itsGUIhelper->i2d(x, y, name);
361 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
362 return itsGUIhelper->i2ds(p, name);
368 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
369 return itsGUIhelper->i2ds(x, y, name);
375 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
376 itsGUIhelper->drawLine(x1, y1, x2, y2, col);
382 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
383 itsGUIhelper->drawRect(x1, y1, x2, y2, col, filled);
389 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
390 itsGUIhelper->drawPoly(pts, col, filled);
396 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
397 itsGUIhelper->drawPoly(pts, col, filled);
403 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
404 if (pts.type() != CV_32FC2)
LFATAL(
"Incorrect type: should be 32FC2");
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]));
413 itsGUIhelper->drawPoly(p, col, filled);
419 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
420 itsGUIhelper->drawCircle(x, y, r, col, filled);
426 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
427 itsGUIhelper->drawText(x, y, txt, col);
433 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
434 return itsGUIhelper->iline(line, name);
440 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
441 itsGUIhelper->itext(txt, col, line);
446 unsigned short winw,
unsigned short winh)
448 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
449 itsGUIhelper->iinfo(*inframe.itsInputFrame, fpscpu, winw, winh);
455 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
456 itsGUIhelper->releaseImage(name);
462 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
463 itsGUIhelper->releaseImage2(name);
469 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
470 itsGUIhelper->endFrame();
476 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
477 itsGUIhelper->reportError(err);
483 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
484 itsGUIhelper->reportAndIgnoreException(prefix);
490 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
491 itsGUIhelper->reportAndRethrowException(prefix);
502 bool hasattr(boost::python::object &
o,
char const * name) {
return PyObject_HasAttrString(
o.ptr(), name); }
509 jevois::
Module(m.modulename), itsMainModule(), itsMainNamespace(), itsInstance(), itsConstructionError()
511 if (m.ispython ==
false)
LFATAL(
"Passed video mapping is not for a python module");
518 itsMainModule = boost::python::import(
"__main__");
519 itsMainNamespace = itsMainModule.attr(
"__dict__");
522 std::string
const pypath = m.sopath();
523 std::string
const pydir = pypath.substr(0, pypath.rfind(
'/'));
524 std::string
const execstr =
526 "sys.path.append(\"/usr/lib\")\n"
527 "sys.path.append(\"" JEVOIS_CONFIG_PATH
"\")\n"
528 "sys.path.append(\"" JEVOIS_OPENCV_PYTHON_PATH
"\")\n"
529 "sys.path.append(\"" + pydir +
"\")\n" +
530 "import " + m.modulename +
"\n" +
531 "import importlib\n" +
532 "importlib.reload(" + m.modulename +
")\n";
534 boost::python::exec(execstr.c_str(), itsMainNamespace, itsMainNamespace);
537 itsInstance = boost::python::eval((m.modulename +
"." + m.modulename +
"()").c_str(),
538 itsMainNamespace, itsMainNamespace);
540 catch (boost::python::error_already_set & e)
542 itsConstructionError =
"Initialization of Module " + m.modulename +
" failed:\n\n" +
551 if (hasattr(itsInstance,
"uninit")) itsInstance.attr(
"uninit")();
561 if (itsInstance.is_none())
throw std::runtime_error(itsConstructionError);
565 itsInstance.attr(
"process")(boost::ref(inframepy), boost::ref(outframepy));
571 if (itsInstance.is_none())
throw std::runtime_error(itsConstructionError);
574 itsInstance.attr(
"processNoUSB")(boost::ref(inframepy));
582 if (itsInstance.is_none())
throw std::runtime_error(itsConstructionError);
586 itsInstance.attr(
"processGUI")(boost::ref(inframepy), boost::ref(helperpy));
594 if (hasattr(itsInstance,
"parseSerial"))
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);
606 if (hasattr(itsInstance,
"supportedCommands"))
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;
void sendScaledCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format.
Exception-safe wrapper around a raw image to be sent over USB.
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.
void sendCv1(cv::Mat const &img, int quality) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
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.
const RawImage & get() const
Get the next captured camera image.
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 itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
Draw some overlay text on top of an image.
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 writeString(std::string const &str)=0
Write a string.
void send() const
Indicate that user processing is done with the image previously obtained via get()
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.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
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.
virtual void parseSerial(std::string const &str, std::shared_ptr< UserInterface > s)
Receive a string from a serial port which contains a user command.
void drawPoly1(std::vector< cv::Point2f > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
bool frameStarted() const
Helper to indicate that startFrame() was called, and thus endFrame() should be called.
void endFrame()
Finish current frame and render it.
Wrapper around GUIhelper to be used by Python.
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.
virtual ~PythonModule()
Virtual destructor for safe inheritance.
Helper class to assist modules in creating graphical and GUI elements.
void drawText(float x, float y, char const *txt, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw text over an image.
GUIhelperPython()=default
Default constructor to keep boost::python happy, object is not operational.
void postUninit() override
Optionally call uninit() python module function, if implemented.
void releaseImage2(char const *name)
Release an image, second video stream.
boost::python::tuple startFrame()
Start a new rendering frame.
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 sendCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
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 reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
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.
ImVec2 i2ds1(float x, float y, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
void drawPoly2(cv::Mat const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
virtual void supportedCommands(std::ostream &os) override
Human-readable description of this Module's supported custom commands.
ImVec2 i2d1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
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.
PythonModule(VideoMapping const &m)
Constructor needs the full path to a Python source code file.
void sendScaledCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
Wrapper around OutputFrame to be used by Python.
Virtual base class for a vision processing module.
ImVec2 i2ds(ImVec2 p, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
void sendScaledCvRGB(cv::Mat const &img) const
Shorthand to send a RGB 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 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.
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 releaseImage(char const *name)
Release an image.
void sendCvRGBA1(cv::Mat const &img, int quality) const
Shorthand to send a RGBA 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 drawLine(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw line over an image.
std::string getPythonExceptionString(boost::python::error_already_set &)
Python exception translation to string so we can print the traceback to our serlog stream.
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.
ImVec2 i2d(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
void drawCircle(float x, float y, float r, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw circle over an 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.
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 sendCv(cv::Mat const &img) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
virtual void supportedCommands(std::ostream &os)
Human-readable description of this Module's supported custom commands.
void reportError(std::string const &err)
Report an error in an overlay window.
void sendCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
void sendScaledCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after scaling/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.