JeVois  1.20
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.

Definition at line 232 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...
 
void sendSerialObjReco (std::vector< ObjReco > const &res)
 Send a standardized object recognition message. More...
 
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. More...
 
void sendSerialObjDetImg2D (unsigned int camw, unsigned int camh, ObjDetect const &det)
 Send a standardized object detection + recognition 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 process (InputFrame &&inframe, GUIhelper &helper)
 Processing function, version that receives a frame from camera, no USB, but GUI output on JeVois-Pro. 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...
 
- Public Member Functions inherited from jevois::Component
 Component (std::string const &instance)
 Constructor. More...
 
virtual ~Component ()
 Virtual destructor for safe inheritance. More...
 
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...
 
Engineengine () const
 Get a handle to our Engine, or throw if we do not have an Engine as root ancestor. More...
 
bool initialized () const
 Has this component been initialized yet? More...
 
const std::string & className () const
 The class name of this component. More...
 
const std::string & 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 foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="")
 Run a function on every param we hold. More...
 
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. More...
 
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. More...
 
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. More...
 
void removeDynamicParameter (std::string const &name)
 Remove a previously added dynamic parameter. More...
 
void setPath (std::string const &path)
 Assign a filesystem path to this component. More...
 
std::filesystem::path absolutePath (std::filesystem::path 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

void sendSerialMarkStart ()
 Send a message MARK START to indicate the beginning of processing. More...
 
void sendSerialMarkStop ()
 Send a message MARK STOP to indicate the end of processing. More...
 
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...
 

Friends

class jevois::Engine
 

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, jevois::Range< unsigned int >(0U, 10U), ParamCateg)
 Parameter. More...
 
 JEVOIS_DEFINE_ENUM_CLASS (SerStamp,(None)(Frame)(Time)(FrameTime)(FrameDateTime)) JEVOIS_DECLARE_PARAMETER(serstamp
 Enum for Parameter. More...
 
 JEVOIS_DEFINE_ENUM_CLASS (SerMark,(None)(Start)(Stop)(Both)) JEVOIS_DECLARE_PARAMETER(sermark
 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 73 of file Module.C.

◆ ~StdModule()

jevois::StdModule::~StdModule ( )
virtual

Virtual destructor for safe inheritance.

Definition at line 78 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 82 of file Module.C.

References jevois::imu::get(), jevois::module::time, and jevois::to_string().

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

References jevois::imu::get(), jevois::coords::imgToStd(), and jevois::replaceWhitespace().

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

References jevois::imu::get(), jevois::coords::imgToStdSize(), and jevois::coords::imgToStdX().

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

References jevois::imu::get(), jevois::coords::imgToStdSize(), and jevois::coords::imgToStdY().

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

References jevois::imu::get(), h, jevois::coords::imgToStd(), and jevois::coords::imgToStdSize().

◆ sendSerialMarkStart()

void jevois::StdModule::sendSerialMarkStart ( )
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 520 of file Module.C.

References jevois::imu::get(), and jevois::module::SerMark.

Referenced by jevois::Engine::mainLoop().

◆ sendSerialMarkStop()

void jevois::StdModule::sendSerialMarkStop ( )
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 528 of file Module.C.

References jevois::imu::get(), and jevois::module::SerMark.

Referenced by jevois::Engine::mainLoop().

◆ sendSerialObjDetImg2D() [1/2]

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.

Parameters
resshould 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 573 of file Module.C.

References jevois::imu::get(), h, jevois::replaceWhitespace(), jevois::sformat(), and jevois::to_string().

Referenced by jevois::dnn::PostProcessorDetect::report().

◆ sendSerialObjDetImg2D() [2/2]

void jevois::StdModule::sendSerialObjDetImg2D ( unsigned int  camw,
unsigned int  camh,
jevois::ObjDetect const &  det 
)

Send a standardized object detection + recognition message.

Parameters
resshould 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 603 of file Module.C.

References jevois::ObjDetect::brx, jevois::ObjDetect::bry, jevois::ObjDetect::reco, jevois::ObjDetect::tlx, and jevois::ObjDetect::tly.

◆ sendSerialObjReco()

void jevois::StdModule::sendSerialObjReco ( std::vector< ObjReco > const &  res)

Send a standardized object recognition message.

Parameters
resshould 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 536 of file Module.C.

References jevois::imu::get(), and jevois::replaceWhitespace().

Referenced by jevois::dnn::PostProcessorClassify::report().

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

References jevois::imu::get(), and jevois::replaceWhitespace().

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

References jevois::imu::get(), and jevois::replaceWhitespace().

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

References jevois::imu::get(), h, and jevois::replaceWhitespace().

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

References jevois::imu::get(), h, and jevois::replaceWhitespace().

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

References jevois::imu::get(), and jevois::replaceWhitespace().

Friends And Related Function Documentation

◆ jevois::Engine

friend class jevois::Engine
friend

Definition at line 327 of file Module.H.

◆ 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  ,
jevois::Range< unsigned int >  0U, 10U,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DEFINE_ENUM_CLASS() [1/3]

JEVOIS_DEFINE_ENUM_CLASS ( SerMark  ,
(None)(Start)(Stop)(Both)   
)
related

Enum for Parameter.

Parameter

◆ JEVOIS_DEFINE_ENUM_CLASS() [2/3]

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

Enum for Parameter.

Parameter

◆ JEVOIS_DEFINE_ENUM_CLASS() [3/3]

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

Enum for Parameter.

Parameter


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