JeVois
1.18
JeVois Smart Embedded Machine Vision Toolkit
|
Share this page: |
|
|
|
 |
 |
|
Go to the documentation of this file.
34 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
35 return itsInputFrame->get(casync);
40 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
41 return itsInputFrame->get();
46 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
47 return itsInputFrame->hasScaledImage();
52 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
53 return itsInputFrame->get2(casync);
58 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
59 return itsInputFrame->get2();
64 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
65 return itsInputFrame->getp(casync);
70 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
71 return itsInputFrame->getp();
76 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
77 itsInputFrame->done();
82 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
83 itsInputFrame->done2();
88 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
89 return itsInputFrame->getCvGRAY(casync);
94 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
95 return itsInputFrame->getCvGRAY();
100 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
101 return itsInputFrame->getCvBGR(casync);
106 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
107 return itsInputFrame->getCvBGR();
112 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
113 return itsInputFrame->getCvRGB(casync);
118 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
119 return itsInputFrame->getCvRGB();
124 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
125 return itsInputFrame->getCvRGBA(casync);
130 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
131 return itsInputFrame->getCvRGBA();
136 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
137 return itsInputFrame->getCvGRAYp();
142 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
143 return itsInputFrame->getCvBGRp();
148 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
149 return itsInputFrame->getCvRGBp();
154 if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error");
155 return itsInputFrame->getCvRGBAp();
166 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
167 return itsOutputFrame->get();
172 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
173 itsOutputFrame->send();
178 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
179 itsOutputFrame->sendCv(img, quality);
184 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
185 itsOutputFrame->sendCv(img);
190 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
191 itsOutputFrame->sendCvGRAY(img, quality);
196 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
197 itsOutputFrame->sendCvGRAY(img);
202 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
203 itsOutputFrame->sendCvBGR(img, quality);
208 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
209 itsOutputFrame->sendCvBGR(img);
214 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
215 itsOutputFrame->sendCvRGB(img, quality);
220 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
221 itsOutputFrame->sendCvRGB(img);
226 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
227 itsOutputFrame->sendCvRGBA(img, quality);
232 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
233 itsOutputFrame->sendCvRGBA(img);
238 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
239 itsOutputFrame->sendScaledCvGRAY(img, quality);
244 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
245 itsOutputFrame->sendScaledCvGRAY(img);
250 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
251 itsOutputFrame->sendScaledCvBGR(img, quality);
256 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
257 itsOutputFrame->sendScaledCvBGR(img);
262 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
263 itsOutputFrame->sendScaledCvRGB(img, quality);
268 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
269 itsOutputFrame->sendScaledCvRGB(img);
274 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
275 itsOutputFrame->sendScaledCvRGBA(img, quality);
280 if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error");
281 itsOutputFrame->sendScaledCvRGBA(img);
294 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
296 bool idle = itsGUIhelper->startFrame(w,
h);
297 return boost::python::make_tuple(idle, w,
h);
303 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
304 return itsGUIhelper->frameStarted();
309 bool noalias,
bool isoverlay)
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);
319 bool noalias,
bool isoverlay)
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);
329 bool noalias,
bool casync)
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);
339 bool noalias,
bool casync)
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);
350 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
351 return itsGUIhelper->i2d(p, name);
357 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
358 return itsGUIhelper->i2d(x, y, name);
364 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
365 return itsGUIhelper->i2ds(p, name);
371 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
372 return itsGUIhelper->i2ds(x, y, name);
378 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
379 return itsGUIhelper->d2i(p, name);
385 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
386 return itsGUIhelper->d2i(x, y, name);
392 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
393 return itsGUIhelper->d2is(p, name);
399 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
400 return itsGUIhelper->d2is(x, y, name);
406 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
407 itsGUIhelper->drawLine(x1, y1, x2, y2, col);
413 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
414 itsGUIhelper->drawRect(x1, y1, x2, y2, col, filled);
420 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
421 itsGUIhelper->drawPoly(pts, col, filled);
427 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
428 itsGUIhelper->drawPoly(pts, col, filled);
434 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
435 if (pts.total() == 0)
return;
439 if (pts.type() == CV_32FC2) imax = pts.cols * 2;
440 else if (pts.type() == CV_32F) imax = pts.cols;
443 if (imax < 4)
return;
445 float const * ptr = pts.ptr<
float>(0);
447 for (
int j = 0; j < pts.rows; ++j)
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);
458 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
459 itsGUIhelper->drawCircle(x, y, r, col, filled);
465 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
466 itsGUIhelper->drawText(x, y, txt, col);
472 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
473 return itsGUIhelper->iline(line, name);
479 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
480 itsGUIhelper->itext(txt, col, line);
485 unsigned short winw,
unsigned short winh)
487 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
488 itsGUIhelper->iinfo(*inframe.itsInputFrame, fpscpu, winw, winh);
494 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
495 itsGUIhelper->releaseImage(name);
501 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
502 itsGUIhelper->releaseImage2(name);
508 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
509 itsGUIhelper->endFrame();
515 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
516 itsGUIhelper->reportError(err);
522 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
523 itsGUIhelper->reportAndIgnoreException(prefix);
529 if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error");
530 itsGUIhelper->reportAndRethrowException(prefix);
540 if (m.ispython ==
false)
LFATAL(
"Passed video mapping is not for a python module");
597 std::string retstr = boost::python::extract<std::string>(ret);
598 if (retstr.empty() ==
false) s->
writeString(retstr);
609 std::string retstr = boost::python::extract<std::string>(ret);
610 if (retstr.empty() ==
false) os << retstr;
621 {
return itsPP->imagesize(); }
627 {
return itsPP->blobsize(num); }
630 { cv::Point2f p(x, y); itsPP->b2i(p.x, p.y, blobnum);
return p; }
633 {
return itsPP->getUnscaledCropRect(blobnum); }
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.
boost::python::list pyVecToList(std::vector< T > const &v)
Helper to convert std::vector<T> to python list.
cv::Point2f b2i(float x, float y, size_t blobnum)
Convert coordinates from blob back to original image.
boost::python::object & pyinst()
Get the python class pyinst, or throw if construction error occurred (e.g., file not found)
void itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
Draw some overlay text on top of an image.
cv::Rect getUnscaledCropRect(size_t blobnum)
Get unscaled crop rectangle in image coordinates.
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.
ImVec2 d2i1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
void postUninit() override
Optionally call uninit() python module function, if implemented.
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.
void releaseImage2(char const *name)
Release an image, second video stream.
ImVec2 d2is1(float x, float y, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
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.
Pre-Processor for neural network pipeline.
bool hasattr(boost::python::object &o, char const *name)
Check whether a boost::python::object has an attribute.
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 preInit() override
Load python code and optionally call init() python module function, if implemented.
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.
PreProcessorForPython(PreProcessor *pp)
Construct from an existing PreProcessor.
ImVec2 i2d1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
boost::python::list blobs() const
Access the last computed blobs (or empty if process() has not yet been called)
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.
ImVec2 d2i(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
#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.
cv::Size imagesize() const
Access the last processed image size.
void sendCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.
cv::Size blobsize(size_t num) const
Access the width and height of a given blob, accounting for NCHW or NHWC.
void pythonload(std::string const &path)
Init from path if default constructor was used.
void drawLine(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw line over an image.
GUIhelperPython(GUIhelper *src)
Construct from a regular GUIhelper that should be be coming from Engine.
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.
ImVec2 d2is(ImVec2 p, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
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.