JeVois
1.21
JeVois Smart Embedded Machine Vision Toolkit
|
|
#include <jevois/Core/Module.H>
Base class for a module that supports standardized serial messages.
Modules that can output standardized serial messages should derive from StdModule instead of Module. StdModule brings in extra parameters to set serial message style and precision, and extra member functions to assemble, format, and send standardized serial messages. The process(), sendSerial(), parseSerial(), supportedCommands(), etc of StdModule functions are directly inherited from Module. See Standardized serial messages formatting for standardized serial messages.
Public Member Functions | |
StdModule (std::string const &instance) | |
Constructor. | |
virtual | ~StdModule () |
Virtual destructor for safe inheritance. | |
void | sendSerialImg1Dx (unsigned int camw, float x, float size=0.0F, std::string const &id="", std::string const &extra="") |
Send standardized 1D message for an X image coordinate. | |
void | sendSerialStd1Dx (float x, float size=0.0F, std::string const &id="", std::string const &extra="") |
Send standardized 1D message for a standardized X coordinate. | |
void | sendSerialImg1Dy (unsigned int camh, float y, float size=0.0F, std::string const &id="", std::string const &extra="") |
Send standardized 1D message for an Y image coordinate. | |
void | sendSerialStd1Dy (float y, float size=0.0F, std::string const &id="", std::string const &extra="") |
Send standardized 1D message for a standardized Y coordinate. | |
void | sendSerialImg2D (unsigned int camw, unsigned int camh, float x, float y, float w=0.0F, float h=0.0F, std::string const &id="", std::string const &extra="") |
Send standardized 2D message for image coordinates. | |
void | sendSerialStd2D (float x, float y, float w=0.0F, float h=0.0F, std::string const &id="", std::string const &extra="") |
Send standardized 2D message for standardized coordinates. | |
template<typename T = int> | |
void | sendSerialContour2D (unsigned int camw, unsigned int camh, std::vector< cv::Point_< T > > points, std::string const &id="", std::string const &extra="") |
Send standardized 2D message for polygons in image coordinates. | |
void | sendSerialStd3D (float x, float y, float z, float w=0.0F, float h=0.0F, float d=0.0F, float q1=0.0F, float q2=0.0F, float q3=0.0f, float q4=0.0F, std::string const &id="", std::string const &extra="") |
Send standardized 3D message. | |
void | sendSerialStd3D (std::vector< cv::Point3f > points, std::string const &id="", std::string const &extra="") |
Send standardized 3D message. | |
void | sendSerialObjReco (std::vector< ObjReco > const &res) |
Send a standardized object recognition message. | |
void | sendSerialObjDetImg2D (unsigned int camw, unsigned int camh, float x, float y, float w, float h, std::vector< ObjReco > const &res) |
Send a standardized object detection + recognition message. | |
void | sendSerialObjDetImg2D (unsigned int camw, unsigned int camh, ObjDetect const &det) |
Send a standardized object detection + recognition message. | |
Public Member Functions inherited from jevois::Module | |
Module (std::string const &instance) | |
Constructor. | |
virtual | ~Module () |
Virtual destructor for safe inheritance. | |
virtual void | process (InputFrame &&inframe, OutputFrame &&outframe) |
Processing function, version that receives a frame from camera and sends a frame out over USB. | |
virtual void | process (InputFrame &&inframe) |
Processing function, version that receives a frame from camera and does not use USB. | |
virtual void | process (InputFrame &&inframe, GUIhelper &helper) |
Processing function, version that receives a frame from camera, no USB, but GUI output on JeVois-Pro. | |
virtual void | sendSerial (std::string const &str) |
Send a string over the 'serout' serial port. | |
virtual void | parseSerial (std::string const &str, std::shared_ptr< UserInterface > s) |
Receive a string from a serial port which contains a user command. | |
virtual void | supportedCommands (std::ostream &os) |
Human-readable description of this Module's supported custom commands. | |
Public Member Functions inherited from jevois::Component | |
Component (std::string const &instance) | |
Constructor. | |
virtual | ~Component () |
Virtual destructor for safe inheritance. | |
template<class Comp , typename... Args> | |
std::shared_ptr< Comp > | addSubComponent (std::string const &instance, Args &&...args) |
Pseudo-constructor: construct and add another component as a subcomponent of this one. | |
template<class Comp > | |
void | removeSubComponent (std::shared_ptr< Comp > &component) |
Remove a sub-Component from this Component, by shared_ptr. | |
void | removeSubComponent (std::string const &instance, bool warnIfNotFound=true) |
Remove a sub-Component from this Component, by instance name. | |
template<class Comp = jevois::Component> | |
std::shared_ptr< Comp > | getSubComponent (std::string const &instance) const |
Get a sub-component by instance name. | |
bool | isTopLevel () const |
Returns true if this component is top-level, i.e., its parent is jevois::Manager. | |
bool | initialized () const |
Has this component been initialized yet? | |
std::string const & | className () const |
The class name of this component. | |
std::string const & | instanceName () const |
The instance name of this component. | |
template<typename T > | |
std::vector< std::string > | setParamVal (std::string const ¶mdescriptor, T const &val) |
Set a parameter value. | |
template<typename T > | |
void | setParamValUnique (std::string const ¶mdescriptor, T const &val) |
Set a parameter value, simple version assuming only one parameter match. | |
template<typename T > | |
std::vector< std::pair< std::string, T > > | getParamVal (std::string const ¶mdescriptor) const |
Get parameter(s) value(s) by descriptor. | |
template<typename T > | |
T | getParamValUnique (std::string const ¶mdescriptor) const |
Get a parameter value, simple version assuming only one parameter match. | |
std::vector< std::string > | setParamString (std::string const ¶mdescriptor, std::string const &val) |
Set a parameter value, by string. | |
void | setParamStringUnique (std::string const ¶mdescriptor, std::string const &val) |
Set a parameter value by string, simple version assuming only one parameter match. | |
std::vector< std::pair< std::string, std::string > > | getParamString (std::string const ¶mdescriptor) const |
Get a parameter value, by string. | |
std::string | getParamStringUnique (std::string const ¶mdescriptor) const |
Get a parameter value by string, simple version assuming only one parameter match. | |
void | freezeParam (std::string const ¶mdescriptor, bool doit) |
Freeze/unfreeze a parameter, by name, see ParameterBase::freeze() | |
void | freezeAllParams (bool doit) |
Freeze all parameters. | |
std::string | descriptor () const |
Get our full descriptor (including all parents) as [Instancename]:[...]:[...]. | |
void | setParamsFromFile (std::string const &filename) |
Set some parameters from a file. | |
std::istream & | setParamsFromStream (std::istream &is, std::string const &absfile) |
Set some parameters from an open stream. | |
virtual void | paramInfo (std::shared_ptr< UserInterface > s, std::map< std::string, std::string > &categs, bool skipFrozen, std::string const &cname="", std::string const &pfx="") |
Get machine-oriented descriptions of all parameters. | |
void | foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="") |
Run a function on every param we hold. | |
template<typename T > | |
std::shared_ptr< DynamicParameter< T > > | addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ParameterCategory const &category) |
Add a new parameter after the Component has already been constructed. | |
template<typename T , template< typename > class ValidValuesSpec> | |
std::shared_ptr< DynamicParameter< T > > | addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ValidValuesSpec< T > const &validValuesSpec, ParameterCategory const &category) |
Add a new parameter after the Component has already been constructed. | |
template<typename T > | |
void | setDynamicParameterCallback (std::string const &name, std::function< void(T const &)> cb, bool callnow=true) |
Register a callback with a previously created dynamic parameter. | |
void | removeDynamicParameter (std::string const &name, bool throw_if_not_found=true) |
Remove a previously added dynamic parameter. | |
void | setPath (std::string const &path) |
Assign a filesystem path to this component. | |
std::filesystem::path | absolutePath (std::filesystem::path const &path="") |
If given path is relative (not starting with /), prepend the Component path to it. | |
Public Member Functions inherited from jevois::ParameterRegistry | |
virtual | ~ParameterRegistry () |
Virtual destructor for safe inheritance. | |
Protected Member Functions | |
void | sendSerialMarkStart () |
Send a message MARK START to indicate the beginning of processing. | |
void | sendSerialMarkStop () |
Send a message MARK STOP to indicate the end of processing. | |
std::string | getStamp () const |
Get a string with the frame/date/time stamp in it, depending on serstamp parameter. | |
Protected Member Functions inherited from jevois::Component | |
virtual void | preInit () |
Called before all sub-Components are init()ed. | |
virtual void | postInit () |
Called after all sub-Components are init()ed. | |
virtual void | preUninit () |
Called before all sub-Components are uninit()ed. | |
virtual void | postUninit () |
Called after all sub-Components are uninit()ed. | |
Protected Member Functions inherited from jevois::ParameterRegistry | |
void | addParameter (ParameterBase *const param) |
The Parameter class uses this method to register itself on construction with its owning Component. | |
void | removeParameter (ParameterBase *const param) |
The Parameter class uses this method to un-register itself on destruction with its owning Component. | |
void | callbackInitCall () |
For all parameters that have a callback which has never been called, call it with the default param value. | |
Friends | |
class | jevois::Engine |
Related Symbols | |
(Note that these are not member symbols.) | |
JEVOIS_DEFINE_ENUM_CLASS (SerStyle,(Terse)(Normal)(Detail)(Fine)) | |
Enum for Parameter. | |
JEVOIS_DECLARE_PARAMETER (serstyle, SerStyle, "Style for standardized serial messages as defined in " "http://jevois.org/doc/UserSerialStyle.html", SerStyle::Terse, SerStyle_Values, ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (serprec, unsigned int, "Number of decimal points in standardized serial messages as " "defined in http://jevois.org/doc/UserSerialStyle.html", 0U, jevois::Range< unsigned int >(0U, 10U), ParamCateg) | |
Parameter. | |
JEVOIS_DEFINE_ENUM_CLASS (SerStamp,(None)(Frame)(Time)(FrameTime)(FrameDateTime)) | |
Enum for Parameter. | |
JEVOIS_DECLARE_PARAMETER (serstamp, SerStamp, "Prepend standardized serial messages with a frame number, " "time, frame+time, or frame+date+time. See details in " "http://jevois.org/doc/UserSerialStyle.html", SerStamp::None, SerStamp_Values, ParamCateg) | |
Parameter. | |
JEVOIS_DEFINE_ENUM_CLASS (SerMark,(None)(Start)(Stop)(Both)) | |
Enum for Parameter. | |
JEVOIS_DECLARE_PARAMETER (sermark, SerMark, "Send serial message to mark the beginning (MARK START) of the " "processing of a video frame from the camera sensor, the end (MARK STOP), or both. " "Useful, among others, if one needs to know when no results were sent over serial " "on a given frame. Combine with parameter serstamp if you need to know the frame number.", SerMark::None, SerMark_Values, ParamCateg) | |
Parameter. | |
jevois::StdModule::StdModule | ( | std::string const & | instance | ) |
|
virtual |
|
protected |
template void jevois::StdModule::sendSerialContour2D | ( | unsigned int | camw, |
unsigned int | camh, | ||
std::vector< cv::Point_< T > > | points, | ||
std::string const & | id = "" , |
||
std::string const & | extra = "" |
||
) |
Send standardized 2D message for polygons in image coordinates.
Use this function if you have a polygon around your object, for example, one of the contours found with cv::findContours(), or if you have the 4 corners of a rectangular object. See Standardized serial messages formatting for more info. Coordinates should be in camera image pixels, this function will convert them to standardized coordinates as per Helper functions to convert coordinates from camera resolution to standardized. For Terse serial style, the center of gravity of the points will be computed and output; for Normal, an upright bounding rectangle will be computed and output; for Detailed, a rotated bounding rectangle will be computed and output; for Fine, all the given points will be output. Make sure you try to reduce the number of points so the message is not too long; for example see OpenCV approxPolyDP() or similar.
Definition at line 284 of file Module.C.
References jevois::coords::imgToStd(), and jevois::replaceWhitespace().
void jevois::StdModule::sendSerialImg1Dx | ( | unsigned int | camw, |
float | x, | ||
float | size = 0.0F , |
||
std::string const & | id = "" , |
||
std::string const & | extra = "" |
||
) |
Send standardized 1D message for an X image coordinate.
See Standardized serial messages formatting for more info. Coordinates should be in camera image pixels, this function will convert them to standardized coordinates as per Helper functions to convert coordinates from camera resolution to standardized.
Definition at line 124 of file Module.C.
References jevois::coords::imgToStdSize(), and jevois::coords::imgToStdX().
void jevois::StdModule::sendSerialImg1Dy | ( | unsigned int | camh, |
float | y, | ||
float | size = 0.0F , |
||
std::string const & | id = "" , |
||
std::string const & | extra = "" |
||
) |
Send standardized 1D message for an Y image coordinate.
See Standardized serial messages formatting for more info. Coordinates should be in camera image pixels, this function will convert them to standardized coordinates as per Helper functions to convert coordinates from camera resolution to standardized.
Definition at line 173 of file Module.C.
References jevois::coords::imgToStdSize(), and jevois::coords::imgToStdY().
void jevois::StdModule::sendSerialImg2D | ( | unsigned int | camw, |
unsigned int | camh, | ||
float | x, | ||
float | y, | ||
float | w = 0.0F , |
||
float | h = 0.0F , |
||
std::string const & | id = "" , |
||
std::string const & | extra = "" |
||
) |
Send standardized 2D message for image coordinates.
Use this function if you only know location and optionally size. Use the other variants if you have the corners. An upright rectangular shape will be assumed here. See Standardized serial messages formatting for more info. Coordinates should be in camera image pixels, this function will convert them to standardized coordinates as per Helper functions to convert coordinates from camera resolution to standardized.
Definition at line 221 of file Module.C.
References h, jevois::coords::imgToStd(), and jevois::coords::imgToStdSize().
|
protected |
Send a message MARK START to indicate the beginning of processing.
A stamp may be prepended depending on param serstamp
. Engine calls this automatically so users would normally not use this function. Note that this function may not send anything depending on the current value of parameter sermark
.
Definition at line 519 of file Module.C.
Referenced by jevois::Engine::mainLoop().
|
protected |
Send a message MARK STOP to indicate the end of processing.
A stamp may be prepended depending on param serstamp
. Engine calls this automatically so users would normally not use this function. Note that this function may not send anything depending on the current value of parameter sermark
.
Definition at line 527 of file Module.C.
Referenced by jevois::Engine::mainLoop().
void jevois::StdModule::sendSerialObjDetImg2D | ( | unsigned int | camw, |
unsigned int | camh, | ||
float | x, | ||
float | y, | ||
float | w, | ||
float | h, | ||
std::vector< ObjReco > const & | res | ||
) |
Send a standardized object detection + recognition message.
res should be a list of scores and category names, in descending order of scores. Note that no message is sent if the vector is empty. See sendSerialImg2D() for info about the object box.
Definition at line 572 of file Module.C.
References h, jevois::replaceWhitespace(), and jevois::sformat().
Referenced by jevois::dnn::PostProcessorDetect::report().
void jevois::StdModule::sendSerialObjDetImg2D | ( | unsigned int | camw, |
unsigned int | camh, | ||
jevois::ObjDetect const & | det | ||
) |
Send a standardized object detection + recognition message.
res should be a list of scores and category names, in descending order of scores. Note that no message is sent if the vector is empty. See sendSerialImg2D() for info about the object box.
Definition at line 602 of file Module.C.
References jevois::ObjDetect::brx, jevois::ObjDetect::bry, jevois::ObjDetect::reco, jevois::ObjDetect::tlx, and jevois::ObjDetect::tly.
void jevois::StdModule::sendSerialObjReco | ( | std::vector< ObjReco > const & | res | ) |
Send a standardized object recognition message.
res should be a list of scores and category names, in descending order of scores. Note that no message is sent if the vector is empty.
Definition at line 535 of file Module.C.
References jevois::replaceWhitespace().
Referenced by jevois::dnn::PostProcessorClassify::report().
void jevois::StdModule::sendSerialStd1Dx | ( | float | x, |
float | size = 0.0F , |
||
std::string const & | id = "" , |
||
std::string const & | extra = "" |
||
) |
Send standardized 1D message for a standardized X coordinate.
See Standardized serial messages formatting for more info. Coordinates should be in camera image pixels, this function will convert them to standardized coordinates as per Helper functions to convert coordinates from camera resolution to standardized.
Definition at line 138 of file Module.C.
References jevois::replaceWhitespace().
void jevois::StdModule::sendSerialStd1Dy | ( | float | y, |
float | size = 0.0F , |
||
std::string const & | id = "" , |
||
std::string const & | extra = "" |
||
) |
Send standardized 1D message for a standardized Y coordinate.
See Standardized serial messages formatting for more info. Coordinates should be in camera image pixels, this function will convert them to standardized coordinates as per Helper functions to convert coordinates from camera resolution to standardized.
Definition at line 186 of file Module.C.
References jevois::replaceWhitespace().
void jevois::StdModule::sendSerialStd2D | ( | float | x, |
float | y, | ||
float | w = 0.0F , |
||
float | h = 0.0F , |
||
std::string const & | id = "" , |
||
std::string const & | extra = "" |
||
) |
Send standardized 2D message for standardized coordinates.
Use this function if you only know location and optionally size. Use the other variants if you have the corners. An upright rectangular shape will be assumed here. See Standardized serial messages formatting for more info. Coordinates should be in camera image pixels, this function will convert them to standardized coordinates as per Helper functions to convert coordinates from camera resolution to standardized.
Definition at line 234 of file Module.C.
References h, and jevois::replaceWhitespace().
void jevois::StdModule::sendSerialStd3D | ( | float | x, |
float | y, | ||
float | z, | ||
float | w = 0.0F , |
||
float | h = 0.0F , |
||
float | d = 0.0F , |
||
float | q1 = 0.0F , |
||
float | q2 = 0.0F , |
||
float | q3 = 0.0f , |
||
float | q4 = 0.0F , |
||
std::string const & | id = "" , |
||
std::string const & | extra = "" |
||
) |
Send standardized 3D message.
Use this function if you only know location and optionally size and an orientation quaternion. Use the other variants if you have a bunch of vertices. See Standardized serial messages formatting for more info. Coordinates should be in millimeters.
Definition at line 385 of file Module.C.
References h, and jevois::replaceWhitespace().
void jevois::StdModule::sendSerialStd3D | ( | std::vector< cv::Point3f > | points, |
std::string const & | id = "" , |
||
std::string const & | extra = "" |
||
) |
Send standardized 3D message.
Use this function if you only know location and optionally size and an orientation quaternion. Use the other variants if you have a bunch of vertices. See Standardized serial messages formatting for more info. Coordinates should be in millimeters.
Definition at line 437 of file Module.C.
References jevois::replaceWhitespace().
|
friend |
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Enum for Parameter.
|
related |
Enum for Parameter.
|
related |
Enum for Parameter.