32{
if (itsInputFrame ==
nullptr)
LFATAL(
"Internal error"); }
36 return itsInputFrame->get(casync);
41 return itsInputFrame->get();
46 return itsInputFrame->hasScaledImage();
51 return itsInputFrame->get2(casync);
56 return itsInputFrame->get2();
61 return itsInputFrame->getp(casync);
66 return itsInputFrame->getp();
71 itsInputFrame->done();
76 itsInputFrame->done2();
81 return itsInputFrame->getCvGRAY(casync);
86 return itsInputFrame->getCvGRAY();
91 return itsInputFrame->getCvBGR(casync);
96 return itsInputFrame->getCvBGR();
101 return itsInputFrame->getCvRGB(casync);
106 return itsInputFrame->getCvRGB();
111 return itsInputFrame->getCvRGBA(casync);
116 return itsInputFrame->getCvRGBA();
121 return itsInputFrame->getCvGRAYp();
126 return itsInputFrame->getCvBGRp();
131 return itsInputFrame->getCvRGBp();
136 return itsInputFrame->getCvRGBAp();
143{
if (itsOutputFrame ==
nullptr)
LFATAL(
"Internal error"); }
147 return itsOutputFrame->get();
152 itsOutputFrame->send();
157 itsOutputFrame->sendCv(img, quality);
162 itsOutputFrame->sendCv(img);
167 itsOutputFrame->sendCvGRAY(img, quality);
172 itsOutputFrame->sendCvGRAY(img);
177 itsOutputFrame->sendCvBGR(img, quality);
182 itsOutputFrame->sendCvBGR(img);
187 itsOutputFrame->sendCvRGB(img, quality);
192 itsOutputFrame->sendCvRGB(img);
197 itsOutputFrame->sendCvRGBA(img, quality);
202 itsOutputFrame->sendCvRGBA(img);
207 itsOutputFrame->sendScaledCvGRAY(img, quality);
212 itsOutputFrame->sendScaledCvGRAY(img);
217 itsOutputFrame->sendScaledCvBGR(img, quality);
222 itsOutputFrame->sendScaledCvBGR(img);
227 itsOutputFrame->sendScaledCvRGB(img, quality);
232 itsOutputFrame->sendScaledCvRGB(img);
237 itsOutputFrame->sendScaledCvRGBA(img, quality);
242 itsOutputFrame->sendScaledCvRGBA(img);
250{
if (itsGUIhelper ==
nullptr)
LFATAL(
"Internal error"); }
256 bool idle = itsGUIhelper->startFrame(w,
h);
257 return boost::python::make_tuple(idle, w,
h);
263 return itsGUIhelper->frameStarted();
268 bool noalias,
bool isoverlay)
270 int x = 0, y = 0;
unsigned short w = 0,
h = 0;
271 itsGUIhelper->drawImage(name, img, x, y, w,
h, noalias, isoverlay);
272 return boost::python::make_tuple(x, y, w,
h);
277 bool noalias,
bool isoverlay)
279 int x = 0, y = 0;
unsigned short w = 0,
h = 0;
280 itsGUIhelper->drawImage(name, img, rgb, x, y, w,
h, noalias, isoverlay);
281 return boost::python::make_tuple(x, y, w,
h);
286 int x,
int y,
int w,
int h,
bool noalias,
bool isoverlay)
288 if (w < 0)
LFATAL(
"w must be positive");
289 if (
h < 0)
LFATAL(
"h must be positive");
290 unsigned short ww = (
unsigned short)(w);
unsigned short hh = (
unsigned short)(
h);
291 itsGUIhelper->drawImage(name, img, x, y, ww, hh, noalias, isoverlay);
292 return boost::python::make_tuple(x, y, w,
h);
297 int x,
int y,
int w,
int h,
bool noalias,
bool isoverlay)
299 if (w < 0)
LFATAL(
"w must be positive");
300 if (
h < 0)
LFATAL(
"h must be positive");
301 unsigned short ww = (
unsigned short)(w);
unsigned short hh = (
unsigned short)(
h);
302 itsGUIhelper->drawImage(name, img, rgb, x, y, ww, hh, noalias, isoverlay);
303 return boost::python::make_tuple(x, y, w,
h);
308 bool noalias,
bool casync)
310 int x = 0, y = 0;
unsigned short w = 0,
h = 0;
311 itsGUIhelper->drawInputFrame(name, *frame.itsInputFrame, x, y, w,
h, noalias, casync);
312 return boost::python::make_tuple(x, y, w,
h);
317 bool noalias,
bool casync)
319 int x = 0, y = 0;
unsigned short w = 0,
h = 0;
320 itsGUIhelper->drawInputFrame(name, *frame.itsInputFrame, x, y, w,
h, noalias, casync);
321 return boost::python::make_tuple(x, y, w,
h);
327 return itsGUIhelper->i2d(p, name);
333 return itsGUIhelper->i2d(x, y, name);
339 return itsGUIhelper->i2ds(p, name);
345 return itsGUIhelper->i2ds(x, y, name);
351 return itsGUIhelper->d2i(p, name);
357 return itsGUIhelper->d2i(x, y, name);
363 return itsGUIhelper->d2is(p, name);
369 return itsGUIhelper->d2is(x, y, name);
375 itsGUIhelper->drawLine(x1, y1, x2, y2, col);
381 itsGUIhelper->drawRect(x1, y1, x2, y2, col, filled);
387 itsGUIhelper->drawPoly(pts, col, filled);
393 itsGUIhelper->drawPoly(pts, col, filled);
399 itsGUIhelper->drawPoly(pts, col, filled);
405 itsGUIhelper->drawCircle(x, y, r, col, filled);
411 itsGUIhelper->drawEllipse(x, y, rx, ry, rot, col, filled);
417 itsGUIhelper->drawText(x, y, txt, col);
423 return itsGUIhelper->iline(line, name);
429 itsGUIhelper->itext(txt, col, line);
435 itsGUIhelper->itext(txt, 0, -1);
440 unsigned short winw,
unsigned short winh)
442 itsGUIhelper->iinfo(*inframe.itsInputFrame, fpscpu, winw, winh);
448 itsGUIhelper->releaseImage(name);
454 itsGUIhelper->releaseImage2(name);
460 itsGUIhelper->endFrame();
466 itsGUIhelper->reportError(err);
472 itsGUIhelper->reportAndIgnoreException(prefix);
478 itsGUIhelper->reportAndRethrowException(prefix);
483{
return ImGui::GetMousePos(); }
487{
return ImGui::IsMouseClicked(button_num); }
491{
return ImGui::IsMouseDoubleClicked(button_num); }
495{
return ImGui::IsMouseDragging(button_num); }
499{
return ImGui::IsMouseDown(button_num); }
503{
return ImGui::IsMouseReleased(button_num); }
513 if (m.
ispython ==
false)
LFATAL(
"Passed video mapping is not for a python module");
572 std::string retstr = boost::python::extract<std::string>(ret);
573 if (retstr.empty() ==
false) s->writeString(retstr);
584 std::string retstr = boost::python::extract<std::string>(ret);
585 if (retstr.empty() ==
false) os << retstr;
592jevois::dnn::PreProcessorForPython::PreProcessorForPython(PreProcessor * pp) : itsPP(pp)
595boost::python::tuple jevois::dnn::PreProcessorForPython::imagesize()
const
597 cv::Size
const s = itsPP->imagesize();
598 return boost::python::make_tuple(s.width, s.height);
601boost::python::list jevois::dnn::PreProcessorForPython::blobs()
const
606boost::python::tuple jevois::dnn::PreProcessorForPython::blobsize(
size_t num)
const
608 cv::Size s = itsPP->blobsize(num);
609 return boost::python::make_tuple(s.width, s.height);
612boost::python::tuple jevois::dnn::PreProcessorForPython::b2i(
float x,
float y,
size_t blobnum)
614 float px = x, py = y;
615 itsPP->b2i(px, py, blobnum);
616 return boost::python::make_tuple(px, py);
619boost::python::tuple jevois::dnn::PreProcessorForPython::getUnscaledCropRect(
size_t blobnum)
621 cv::Rect
const r = itsPP->getUnscaledCropRect(blobnum);
622 return boost::python::make_tuple(r.x, r.y, r.width, r.height);
625boost::python::tuple jevois::dnn::PreProcessorForPython::i2b(
float x,
float y,
size_t blobnum)
627 float px = x, py = y;
628 itsPP->i2b(px, py, blobnum);
629 return boost::python::make_tuple(px, py);
636jevois::dnn::PostProcessorDetectYOLOforPython::PostProcessorDetectYOLOforPython()
640 std::shared_ptr<Module> m = jevois::python::engine()->module();
641 if (!m)
LFATAL(
"Cannot instantiate without a current running module");
642 std::shared_ptr<Component> pi = m->getSubComponent(
"pipeline");
643 if (!pi)
LFATAL(
"Cannot instantiate without a current DNN pipeline");
644 std::shared_ptr<Component> pp = pi->getSubComponent(
"postproc");
645 if (!pp)
LFATAL(
"Cannot instantiate without a current python-type post-processor");
646 std::shared_ptr<Component> ppp = pp->getSubComponent(
"pypost");
647 if (!ppp)
LFATAL(
"Cannot instantiate without a current pypost post-processor");
648 itsYOLO = ppp->addSubComponent<PostProcessorDetectYOLO>(
"yolo");
651jevois::dnn::PostProcessorDetectYOLOforPython::~PostProcessorDetectYOLOforPython()
654void jevois::dnn::PostProcessorDetectYOLOforPython::freeze(
bool doit)
655{ itsYOLO->freeze(doit); }
658jevois::dnn::PostProcessorDetectYOLOforPython::yolo(boost::python::list outs,
int nclass,
659 float boxThreshold,
float confThreshold,
660 int bw,
int bh,
int fudge,
int maxbox,
bool sigmo)
662 std::vector<cv::Mat>
const outvec = jevois::python::pyListToVec<cv::Mat>(outs);
664 std::vector<int> classIds;
665 std::vector<float> confidences;
666 std::vector<cv::Rect> boxes;
668 itsYOLO->yolo(outvec, classIds, confidences, boxes, nclass, boxThreshold, confThreshold,
669 cv::Size(bw, bh), fudge, maxbox, sigmo);
673 boost::python::list b;
674 for (cv::Rect
const & r : boxes) b.append(boost::python::make_tuple(r.x, r.y, r.width, r.height));
676 return boost::python::make_tuple(ids, conf, b);
void unRegisterPythonComponent(Component *comp)
Unregister a component as linked to some python code, used by dynamic params created in python.
Wrapper around GUIhelper to be used by Python.
void itext2(char const *txt)
Draw some overlay text on top of an image, default color and line.
void iinfo(jevois::InputFramePython const &inframe, std::string const &fpscpu, unsigned short winw=0, unsigned short winh=0)
Display processing and video info at bottom of screen.
ImVec2 getMousePos()
ImGui helper: get mouse position.
void reportError(std::string const &err)
Report an error in an overlay window.
GUIhelperPython(GUIhelper *src)
Construct from a regular GUIhelper that should be be coming from Engine.
void releaseImage(char const *name)
Release an image.
ImVec2 d2is1(float x, float y, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
ImVec2 d2is(ImVec2 p, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
ImVec2 d2i(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
void reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
void drawCircle(float x, float y, float r, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw circle over an image.
ImVec2 d2i1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
boost::python::tuple drawInputFrame2(char const *name, InputFramePython const &frame, bool noalias=false, bool casync=false)
Draw the second (scaled) input video frame from the camera using zero-copy.
void drawPoly2(cv::Mat const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
void drawPoly1(std::vector< cv::Point2f > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
ImVec2 i2d1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
void drawPoly(std::vector< cv::Point > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
void endFrame()
Finish current frame and render it.
bool isMouseDown(int button_num)
ImGui helper: check if mouse button pressed.
ImVec2 iline(int line=-1, char const *name=nullptr)
Get coordinates of the start of a given line of text to be drawn as overlay on top of an image.
void drawText(float x, float y, char const *txt, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw text over an image.
boost::python::tuple drawImage(char const *name, RawImage const &img, bool noalias=false, bool isoverlay=false)
Draw a RawImage, copying pixel data to an OpenGL texture.
boost::python::tuple drawImage3(char const *name, cv::Mat const &img, bool rgb, int x, int y, int w, int h, bool noalias=false, bool isoverlay=false)
Draw an OpenCV image, copying pixel data to an OpenGL texture.
ImVec2 i2d(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
void releaseImage2(char const *name)
Release an image, second video stream.
bool isMouseReleased(int button_num)
ImGui helper: check if mouse button released.
boost::python::tuple drawImage1(char const *name, cv::Mat const &img, bool rgb, bool noalias=false, bool isoverlay=false)
Draw an OpenCV image, copying pixel data to an OpenGL texture.
ImVec2 i2ds1(float x, float y, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
bool frameStarted() const
Helper to indicate that startFrame() was called, and thus endFrame() should be called.
ImVec2 i2ds(ImVec2 p, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
void itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
Draw some overlay text on top of an image.
bool isMouseDragging(int button_num)
ImGui helper: check if mouse button dragged.
bool isMouseClicked(int button_num)
ImGui helper: check if mouse button clicked.
void drawRect(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw rectangular box over an image.
boost::python::tuple startFrame()
Start a new rendering frame.
void drawEllipse(float x, float y, float rx, float ry, float rot=0.0F, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw ellipse over an image.
void drawLine(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw line over an image.
boost::python::tuple drawImage2(char const *name, RawImage const &img, int x, int y, int w, int h, bool noalias=false, bool isoverlay=false)
Draw an OpenCV image, copying pixel data to an OpenGL texture.
boost::python::tuple drawInputFrame(char const *name, InputFramePython const &frame, bool noalias=false, bool casync=false)
Draw the input video frame from the camera using zero-copy.
bool isMouseDoubleClicked(int button_num)
ImGui helper: check if mouse button double-clicked.
Helper class to assist modules in creating graphical and GUI elements.
Virtual base class for a vision processing module.
virtual void supportedCommands(std::ostream &os)
Human-readable description of this Module's supported custom commands.
virtual void parseSerial(std::string const &str, std::shared_ptr< UserInterface > s)
Receive a string from a serial port which contains a user command.
Wrapper around OutputFrame to be used by Python.
void sendScaledCvRGBA1(cv::Mat const &img, int quality) const
Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format.
void sendScaledCvBGR1(cv::Mat const &img, int quality) const
Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format.
void sendScaledCvGRAY1(cv::Mat const &img, int quality) const
Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format.
RawImage const & get() const
Get the next captured camera image.
void sendCvRGB1(cv::Mat const &img, int quality) const
Shorthand to send a RGB cv::Mat after converting it to the current output format.
void sendScaledCvRGB1(cv::Mat const &img, int quality) const
Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format.
void send() const
Indicate that user processing is done with the image previously obtained via get()
void sendScaledCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format.
void sendCvGRAY1(cv::Mat const &img, int quality) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
void sendCvBGR1(cv::Mat const &img, int quality) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.
OutputFramePython()=default
Default constructor to keep boost::python happy, object is not operational.
void sendCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.
void sendScaledCvRGB(cv::Mat const &img) const
Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format.
void sendScaledCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format.
void sendCv1(cv::Mat const &img, int quality) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
void sendCvRGB(cv::Mat const &img) const
Shorthand to send a RGB cv::Mat after converting it to the current output format.
void sendScaledCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format.
void sendCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
void sendCv(cv::Mat const &img) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
void sendCvRGBA1(cv::Mat const &img, int quality) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
void sendCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
Exception-safe wrapper around a raw image to be sent over USB.
virtual void process(InputFrame &&inframe, OutputFrame &&outframe) override
Processing function, version that receives a frame from camera and sends a frame out over USB.
PythonModule(VideoMapping const &m)
Constructor needs the full path to a Python source code file.
virtual void supportedCommands(std::ostream &os) override
Human-readable description of this Module's supported custom commands.
void postUninit() override
Optionally call uninit() python module function, if implemented.
virtual void parseSerial(std::string const &str, std::shared_ptr< UserInterface > s) override
Receive a string from a serial port which contains a user command.
void preInit() override
Load python code and optionally call init() python module function, if implemented.
virtual ~PythonModule()
Virtual destructor for safe inheritance.
void pythonload(std::string const &path)
Init from path if default constructor was used.
boost::python::object & pyinst()
Get the python class pyinst, or throw if construction error occurred (e.g., file not found)
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
boost::python::list pyVecToList(std::vector< T > const &v)
Helper to convert std::vector<T> to python list.
bool hasattr(boost::python::object &o, char const *name)
Check whether a boost::python::object has an attribute.
Main namespace for all JeVois classes and functions.
Simple struct to hold video mapping definitions for the processing Engine.
bool ispython
True if the module is written in Python; affects behavior of sopath() only.