JeVoisBase  1.21
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
Kalman1D Class Reference

Simple component to track a moving 2D point over time using a Kalman filter. More...

#include <jevoisbase/Components/Tracking/Kalman1D.H>

Inheritance diagram for Kalman1D:
Collaboration diagram for Kalman1D:

Public Member Functions

 Kalman1D (std::string const &instance)
 Constructor.
 
virtual ~Kalman1D ()
 Destructor.
 
void set (float x)
 Function to call each time you have a new measurement.
 
float get (float const eps=0.01F)
 Function to call each time you want to get the Kalman-filtered coordinates.
 
- Public Member Functions inherited from jevois::Component
 Component (std::string const &instance)
 
virtual ~Component ()
 
std::shared_ptr< Comp > addSubComponent (std::string const &instance, Args &&...args)
 
void removeSubComponent (std::shared_ptr< Comp > &component)
 
void removeSubComponent (std::string const &instance, bool warnIfNotFound=true)
 
std::shared_ptr< Comp > getSubComponent (std::string const &instance) const
 
bool isTopLevel () const
 
bool initialized () const
 
std::string const & className () const
 
std::string const & instanceName () const
 
std::vector< std::string > setParamVal (std::string const &paramdescriptor, T const &val)
 
void setParamValUnique (std::string const &paramdescriptor, T const &val)
 
std::vector< std::pair< std::string, T > > getParamVal (std::string const &paramdescriptor) const
 
getParamValUnique (std::string const &paramdescriptor) const
 
std::vector< std::string > setParamString (std::string const &paramdescriptor, std::string const &val)
 
void setParamStringUnique (std::string const &paramdescriptor, std::string const &val)
 
std::vector< std::pair< std::string, std::string > > getParamString (std::string const &paramdescriptor) const
 
std::string getParamStringUnique (std::string const &paramdescriptor) const
 
void freezeParam (std::string const &paramdescriptor, bool doit)
 
void freezeAllParams (bool doit)
 
std::string descriptor () const
 
void setParamsFromFile (std::string const &filename)
 
std::istream & setParamsFromStream (std::istream &is, std::string const &absfile)
 
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="")
 
void foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="")
 
std::shared_ptr< DynamicParameter< T > > addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ParameterCategory const &category)
 
std::shared_ptr< DynamicParameter< T > > addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ValidValuesSpec< T > const &validValuesSpec, ParameterCategory const &category)
 
void setDynamicParameterCallback (std::string const &name, std::function< void(T const &)> cb, bool callnow=true)
 
void removeDynamicParameter (std::string const &name, bool throw_if_not_found=true)
 
void setPath (std::string const &path)
 
std::filesystem::path absolutePath (std::filesystem::path const &path="")
 
std::shared_ptr< Comp > addSubComponent (std::string const &instance, Args &&...args)
 
void removeSubComponent (std::shared_ptr< Comp > &component)
 
void removeSubComponent (std::string const &instance, bool warnIfNotFound=true)
 
std::shared_ptr< Comp > getSubComponent (std::string const &instance) const
 
bool isTopLevel () const
 
bool initialized () const
 
std::string const & className () const
 
std::string const & instanceName () const
 
std::vector< std::string > setParamVal (std::string const &paramdescriptor, T const &val)
 
void setParamValUnique (std::string const &paramdescriptor, T const &val)
 
std::vector< std::pair< std::string, T > > getParamVal (std::string const &paramdescriptor) const
 
getParamValUnique (std::string const &paramdescriptor) const
 
std::vector< std::string > setParamString (std::string const &paramdescriptor, std::string const &val)
 
void setParamStringUnique (std::string const &paramdescriptor, std::string const &val)
 
std::vector< std::pair< std::string, std::string > > getParamString (std::string const &paramdescriptor) const
 
std::string getParamStringUnique (std::string const &paramdescriptor) const
 
void freezeParam (std::string const &paramdescriptor, bool doit)
 
void freezeAllParams (bool doit)
 
std::string descriptor () const
 
void setParamsFromFile (std::string const &filename)
 
std::istream & setParamsFromStream (std::istream &is, std::string const &absfile)
 
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="")
 
void foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="")
 
std::shared_ptr< DynamicParameter< T > > addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ParameterCategory const &category)
 
std::shared_ptr< DynamicParameter< T > > addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ValidValuesSpec< T > const &validValuesSpec, ParameterCategory const &category)
 
void setDynamicParameterCallback (std::string const &name, std::function< void(T const &)> cb, bool callnow=true)
 
void removeDynamicParameter (std::string const &name, bool throw_if_not_found=true)
 
void setPath (std::string const &path)
 
std::filesystem::path absolutePath (std::filesystem::path const &path="")
 
- Public Member Functions inherited from jevois::ParameterRegistry
virtual ~ParameterRegistry ()
 

Protected Member Functions

void postInit () override
 
void onParamChange (kalman1d::usevel const &param, bool const &newval) override
 
void onParamChange (kalman1d::procnoise const &param, float const &newval) override
 
void onParamChange (kalman1d::measnoise const &param, float const &newval) override
 
void onParamChange (kalman1d::postnoise const &param, float const &newval) override
 
- Protected Member Functions inherited from jevois::Component
virtual void preInit ()
 
virtual void preUninit ()
 
virtual void postUninit ()
 
virtual void preInit ()
 
virtual void preUninit ()
 
virtual void postUninit ()
 
- Protected Member Functions inherited from jevois::ParameterRegistry
void addParameter (ParameterBase *const param)
 
void removeParameter (ParameterBase *const param)
 
void callbackInitCall ()
 

Protected Attributes

cv::KalmanFilter itsKF
 
cv::Mat itsState
 (x, y, xdot, ydot)
 
cv::Mat itsProcessNoise
 
cv::Mat itsMeasurement
 
cv::Mat itsLatest
 
bool itsFresh
 

Related Symbols

(Note that these are not member symbols.)

 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (usevel, bool, "Use velocity tracking, in addition to position", false, ParamCateg)
 Parameter.
 
 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (procnoise, float, "Process noise standard deviation", 0.003F, ParamCateg)
 Parameter.
 
 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (measnoise, float, "Measurement noise standard deviation", 0.05F, ParamCateg)
 Parameter.
 
 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (postnoise, float, "A posteriori error estimate standard deviation", 0.3F, ParamCateg)
 Parameter.
 

Detailed Description

Simple component to track a moving 2D point over time using a Kalman filter.

A Kalman filter allows one to filter noisy data over time. Here, it is used to filter the possibly noisy results of some machine vision algorith that is trying to detect a particular item in the camera's video stream. On occasion, the detection might abruptly jump to an erroneous location. Such jumps are filtered out by the Kalman filter.

Note that, unlike Kalman2D, this class does not perform any normalization or range transformation.

This code loosely inspired by https://github.com/abreheret/kalman-mouse/blob/master/src/main.cpp

Definition at line 54 of file Kalman1D.H.

Constructor & Destructor Documentation

◆ Kalman1D()

Kalman1D::Kalman1D ( std::string const &  instance)

Constructor.

Definition at line 23 of file Kalman1D.C.

References itsKF.

◆ ~Kalman1D()

Kalman1D::~Kalman1D ( )
virtual

Destructor.

Definition at line 31 of file Kalman1D.C.

Member Function Documentation

◆ get()

float Kalman1D::get ( float const  eps = 0.01F)

Function to call each time you want to get the Kalman-filtered coordinates.

It is ok to call get() multiple times with no intervening set(), if you have no new measurements but still want to use the filter output.

eps is used for rounding of returned value, which is convenient to avoid sending very long floating point values over serial port.

Definition at line 78 of file Kalman1D.C.

References itsFresh, itsKF, and itsLatest.

◆ onParamChange() [1/4]

void Kalman1D::onParamChange ( kalman1d::measnoise const &  param,
float const &  newval 
)
overrideprotected

◆ onParamChange() [2/4]

void Kalman1D::onParamChange ( kalman1d::postnoise const &  param,
float const &  newval 
)
overrideprotected

◆ onParamChange() [3/4]

void Kalman1D::onParamChange ( kalman1d::procnoise const &  param,
float const &  newval 
)
overrideprotected

◆ onParamChange() [4/4]

void Kalman1D::onParamChange ( kalman1d::usevel const &  param,
bool const &  newval 
)
overrideprotected

◆ postInit()

void Kalman1D::postInit ( )
overrideprotectedvirtual

Reimplemented from jevois::Component.

Definition at line 35 of file Kalman1D.C.

References itsKF.

◆ set()

void Kalman1D::set ( float  x)

Function to call each time you have a new measurement.

Definition at line 70 of file Kalman1D.C.

References itsFresh, itsKF, itsLatest, and itsMeasurement.

Friends And Related Symbol Documentation

◆ JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK() [1/4]

JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK ( measnoise  ,
float  ,
"Measurement noise standard deviation"  ,
0.  05F,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK() [2/4]

JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK ( postnoise  ,
float  ,
"A posteriori error estimate standard deviation"  ,
0.  3F,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK() [3/4]

JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK ( procnoise  ,
float  ,
"Process noise standard deviation"  ,
0.  003F,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK() [4/4]

JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK ( usevel  ,
bool  ,
"Use velocity  tracking,
in addition to position"  ,
false  ,
ParamCateg   
)
related

Parameter.

Member Data Documentation

◆ itsFresh

bool Kalman1D::itsFresh
protected

Definition at line 88 of file Kalman1D.H.

Referenced by get(), and set().

◆ itsKF

cv::KalmanFilter Kalman1D::itsKF
protected

Definition at line 83 of file Kalman1D.H.

Referenced by get(), Kalman1D(), postInit(), and set().

◆ itsLatest

cv::Mat Kalman1D::itsLatest
protected

Definition at line 87 of file Kalman1D.H.

Referenced by get(), and set().

◆ itsMeasurement

cv::Mat Kalman1D::itsMeasurement
protected

Definition at line 86 of file Kalman1D.H.

Referenced by set().

◆ itsProcessNoise

cv::Mat Kalman1D::itsProcessNoise
protected

Definition at line 85 of file Kalman1D.H.

◆ itsState

cv::Mat Kalman1D::itsState
protected

(x, y, xdot, ydot)

Definition at line 84 of file Kalman1D.H.


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