JeVois  1.8
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
jevois::StdModule Class Reference

#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. core

Definition at line 445 of file Module.H.

Inheritance diagram for jevois::StdModule:
Collaboration diagram for jevois::StdModule:

Public Member Functions

 StdModule (std::string const &instance)
 Constructor. More...
 
virtual ~StdModule ()
 Virtual destructor for safe inheritance. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void sendSerialStd3D (std::vector< cv::Point3f > points, std::string const &id="", std::string const &extra="")
 Send standardized 3D message. More...
 
- Public Member Functions inherited from jevois::Module
 Module (std::string const &instance)
 Constructor. More...
 
virtual ~Module ()
 Virtual destructor for safe inheritance. More...
 
virtual void process (InputFrame &&inframe, OutputFrame &&outframe)
 Processing function, version that receives a frame from camera and sends a frame out over USB. More...
 
virtual void process (InputFrame &&inframe)
 Processing function, version that receives a frame from camera and does not use USB. More...
 
virtual void sendSerial (std::string const &str)
 Send a string over the 'serout' serial port. More...
 
virtual void parseSerial (std::string const &str, std::shared_ptr< UserInterface > s)
 Receive a string from a serial port which contains a user command. More...
 
virtual void supportedCommands (std::ostream &os)
 Human-readable description of this Module's supported custom commands. More...
 
size_t frameNum () const
 Get frame number from the Engine. More...
 
- Public Member Functions inherited from jevois::Component
 Component (std::string const &instance)
 Constructor. More...
 
virtual ~Component ()
 Virtual destructor for safe inheritance. More...
 
template<>
std::shared_ptr< ComponentgetSubComponent (std::string const &instance) const
 
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. More...
 
template<class Comp >
void removeSubComponent (std::shared_ptr< Comp > &component)
 Remove a sub-Component from this Component, by shared_ptr. More...
 
void removeSubComponent (std::string const &instance, bool warnIfNotFound=true)
 Remove a sub-Component from this Component, by instance name. More...
 
template<class Comp = jevois::Component>
std::shared_ptr< Comp > getSubComponent (std::string const &instance) const
 Get a sub-component by instance name. More...
 
bool isTopLevel () const
 Returns true if this component is top-level, i.e., its parent is jevois::Manager. More...
 
bool initialized () const
 Has this component been initialized yet? More...
 
std::string const & className () const
 The class name of this component. More...
 
std::string const & instanceName () const
 The instance name of this component. More...
 
template<typename T >
std::vector< std::string > setParamVal (std::string const &paramdescriptor, T const &val)
 Set a parameter value. More...
 
template<typename T >
void setParamValUnique (std::string const &paramdescriptor, T const &val)
 Set a parameter value, simple version assuming only one parameter match. More...
 
template<typename T >
std::vector< std::pair< std::string, T > > getParamVal (std::string const &paramdescriptor) const
 Get parameter(s) value(s) by descriptor. More...
 
template<typename T >
getParamValUnique (std::string const &paramdescriptor) const
 Get a parameter value, simple version assuming only one parameter match. More...
 
std::vector< std::string > setParamString (std::string const &paramdescriptor, std::string const &val)
 Set a parameter value, by string. More...
 
void setParamStringUnique (std::string const &paramdescriptor, std::string const &val)
 Set a parameter value by string, simple version assuming only one parameter match. More...
 
std::vector< std::pair< std::string, std::string > > getParamString (std::string const &paramdescriptor) const
 Get a parameter value, by string. More...
 
std::string getParamStringUnique (std::string const &paramdescriptor) const
 Get a parameter value by string, simple version assuming only one parameter match. More...
 
void freezeParam (std::string const &paramdescriptor)
 Freeze a parameter, by name, see ParameterBase::freeze() More...
 
void unFreezeParam (std::string const &paramdescriptor)
 Unfreeze a parameter, by name, see ParameterBase::unFreeze() More...
 
void freezeAllParams ()
 Freeze all parameters. More...
 
void unFreezeAllParams ()
 Unfreeze all parameters. More...
 
std::string descriptor () const
 Get our full descriptor (including all parents) as [Instancename]:[...]:[...]. More...
 
void setParamsFromFile (std::string const &filename)
 Set some parameters from a file. More...
 
std::istream & setParamsFromStream (std::istream &is, std::string const &absfile)
 Set some parameters from an open stream. More...
 
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. More...
 
void setPath (std::string const &path)
 Assign a filesystem path to this component. More...
 
std::string absolutePath (std::string const &path="")
 If given path is relative (not starting with /), prepend the Component path to it. More...
 
- Public Member Functions inherited from jevois::ParameterRegistry
virtual ~ParameterRegistry ()
 Virtual destructor for safe inheritance. More...
 

Protected Member Functions

std::string getStamp () const
 Get a string with the frame/date/time stamp in it, depending on serstamp parameter. More...
 
- Protected Member Functions inherited from jevois::Component
virtual void preInit ()
 Called before all sub-Components are init()ed. More...
 
virtual void postInit ()
 Called after all sub-Components are init()ed. More...
 
virtual void preUninit ()
 Called before all sub-Components are uninit()ed. More...
 
virtual void postUninit ()
 Called after all sub-Components are uninit()ed. More...
 
- 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. More...
 
void removeParameter (ParameterBase *const param)
 The Parameter class uses this method to un-register itself on destruction with its owning Component. More...
 
void callbackInitCall ()
 For all parameters that have a callback which has never been called, call it with the default param value. More...
 

Related Functions

(Note that these are not member functions.)

 JEVOIS_DEFINE_ENUM_CLASS (SerStyle,(Terse)(Normal)(Detail)(Fine)) JEVOIS_DECLARE_PARAMETER(serstyle
 Enum for Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (serprec, unsigned int, "Number of decimal points in standardized serial messages as " "defined in http://jevois.org/doc/UserSerialStyle.html", 0U, ParamCateg)
 Parameter. More...
 
 JEVOIS_DEFINE_ENUM_CLASS (SerStamp,(None)(Frame)(Time)(FrameTime)(FrameDateTime)) JEVOIS_DECLARE_PARAMETER(serstamp
 Enum for Parameter. More...
 

Constructor & Destructor Documentation

◆ StdModule()

jevois::StdModule::StdModule ( std::string const &  instance)

Constructor.

the instance is a user-defined string that may be used to differentiate between several instances of the same module.

Definition at line 277 of file Module.C.

◆ ~StdModule()

jevois::StdModule::~StdModule ( )
virtual

Virtual destructor for safe inheritance.

Definition at line 282 of file Module.C.

Member Function Documentation

◆ getStamp()

std::string jevois::StdModule::getStamp ( ) const
protected

Get a string with the frame/date/time stamp in it, depending on serstamp parameter.

Definition at line 286 of file Module.C.

References jevois::Module::frameNum(), jevois::module::time, and jevois::to_string().

Referenced by sendSerialContour2D(), sendSerialStd1Dx(), sendSerialStd1Dy(), sendSerialStd2D(), and sendSerialStd3D().

◆ sendSerialContour2D()

template<typename T >
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 489 of file Module.C.

References getStamp(), jevois::coords::imgToStd(), jevois::replaceWhitespace(), jevois::Module::sendSerial(), and sendSerialImg2D().

◆ sendSerialImg1Dx()

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 329 of file Module.C.

References jevois::coords::imgToStdSize(), jevois::coords::imgToStdX(), and sendSerialStd1Dx().

◆ sendSerialImg1Dy()

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 378 of file Module.C.

References jevois::coords::imgToStdSize(), jevois::coords::imgToStdY(), and sendSerialStd1Dy().

◆ sendSerialImg2D()

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 426 of file Module.C.

References jevois::coords::imgToStd(), jevois::coords::imgToStdSize(), and sendSerialStd2D().

Referenced by sendSerialContour2D().

◆ sendSerialStd1Dx()

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 343 of file Module.C.

References getStamp(), jevois::replaceWhitespace(), and jevois::Module::sendSerial().

Referenced by sendSerialImg1Dx().

◆ sendSerialStd1Dy()

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 391 of file Module.C.

References getStamp(), jevois::replaceWhitespace(), and jevois::Module::sendSerial().

Referenced by sendSerialImg1Dy().

◆ sendSerialStd2D()

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 439 of file Module.C.

References getStamp(), jevois::replaceWhitespace(), and jevois::Module::sendSerial().

Referenced by sendSerialImg2D().

◆ sendSerialStd3D() [1/2]

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 590 of file Module.C.

References getStamp(), jevois::replaceWhitespace(), and jevois::Module::sendSerial().

Referenced by sendSerialStd3D().

◆ sendSerialStd3D() [2/2]

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 642 of file Module.C.

References getStamp(), jevois::replaceWhitespace(), jevois::Module::sendSerial(), and sendSerialStd3D().

Friends And Related Function Documentation

◆ JEVOIS_DECLARE_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  ,
ParamCateg   
)
related

◆ JEVOIS_DEFINE_ENUM_CLASS() [1/2]

JEVOIS_DEFINE_ENUM_CLASS ( SerStyle  ,
(Terse)(Normal)(Detail)(Fine)   
)
related

Enum for Parameter.

Parameter

◆ JEVOIS_DEFINE_ENUM_CLASS() [2/2]

JEVOIS_DEFINE_ENUM_CLASS ( SerStamp  ,
(None)(Frame)(Time)(FrameTime)(FrameDateTime)   
)
related

Enum for Parameter.

Parameter


The documentation for this class was generated from the following files: