JeVoisBase  1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
Kalman1D.H
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
19#include <opencv2/video/tracking.hpp> // for kalman filter
20
21#pragma once
22
23namespace kalman1d
24{
25 static jevois::ParameterCategory const ParamCateg("Kalman1D Options");
26
27 //! Parameter \relates Kalman1D
28 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(usevel, bool, "Use velocity tracking, in addition to position",
29 false, ParamCateg);
30
31 //! Parameter \relates Kalman1D
32 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(procnoise, float, "Process noise standard deviation",
33 0.003F, ParamCateg);
34
35 //! Parameter \relates Kalman1D
36 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(measnoise, float, "Measurement noise standard deviation",
37 0.05F, ParamCateg);
38
39 //! Parameter \relates Kalman1D
40 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(postnoise, float, "A posteriori error estimate standard deviation",
41 0.3F, ParamCateg);
42}
43
44//! Simple component to track a moving 2D point over time using a Kalman filter
45/*! A Kalman filter allows one to filter noisy data over time. Here, it is used to filter the possibly noisy results of
46 some machine vision algorith that is trying to detect a particular item in the camera's video stream. On occasion,
47 the detection might abruptly jump to an erroneous location. Such jumps are filtered out by the Kalman filter.
48
49 Note that, unlike Kalman2D, this class does not perform any normalization or range transformation.
50
51 This code loosely inspired by https://github.com/abreheret/kalman-mouse/blob/master/src/main.cpp
52
53 \ingroup components */
55 public jevois::Parameter<kalman1d::usevel, kalman1d::procnoise,
56 kalman1d::measnoise, kalman1d::postnoise>
57{
58 public:
59 //! Constructor
60 Kalman1D(std::string const & instance);
61
62 //! Destructor
63 virtual ~Kalman1D();
64
65 //! Function to call each time you have a new measurement
66 void set(float x);
67
68 //! Function to call each time you want to get the Kalman-filtered coordinates
69 /*! It is ok to call get() multiple times with no intervening set(), if you have no new measurements but still want
70 to use the filter output.
71
72 eps is used for rounding of returned value, which is convenient to avoid sending very long floating point
73 values over serial port. */
74 float get(float const eps = 0.01F);
75
76 protected:
77 void postInit() override;
78 void onParamChange(kalman1d::usevel const & param, bool const & newval) override;
79 void onParamChange(kalman1d::procnoise const & param, float const & newval) override;
80 void onParamChange(kalman1d::measnoise const & param, float const & newval) override;
81 void onParamChange(kalman1d::postnoise const & param, float const & newval) override;
82
83 // state is (x, xdot)
84 cv::KalmanFilter itsKF;
87 cv::Mat itsLatest;
89
90}; // class Kalman1D
91
Simple component to track a moving 2D point over time using a Kalman filter.
Definition Kalman1D.H:57
cv::Mat itsMeasurement
Definition Kalman1D.H:86
cv::Mat itsLatest
Definition Kalman1D.H:87
void onParamChange(kalman1d::postnoise const &param, float const &newval) override
cv::Mat itsProcessNoise
Definition Kalman1D.H:85
void onParamChange(kalman1d::measnoise const &param, float const &newval) override
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(usevel, bool, "Use velocity tracking, in addition to position", false, ParamCateg)
Parameter.
void onParamChange(kalman1d::procnoise const &param, float const &newval) override
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(procnoise, float, "Process noise standard deviation", 0.003F, ParamCateg)
Parameter.
void postInit() override
Definition Kalman1D.C:35
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(measnoise, float, "Measurement noise standard deviation", 0.05F, ParamCateg)
Parameter.
float get(float const eps=0.01F)
Function to call each time you want to get the Kalman-filtered coordinates.
Definition Kalman1D.C:78
bool itsFresh
Definition Kalman1D.H:88
virtual ~Kalman1D()
Destructor.
Definition Kalman1D.C:31
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(postnoise, float, "A posteriori error estimate standard deviation", 0.3F, ParamCateg)
Parameter.
cv::KalmanFilter itsKF
Definition Kalman1D.H:84
void onParamChange(kalman1d::usevel const &param, bool const &newval) override
void set(float x)
Function to call each time you have a new measurement.
Definition Kalman1D.C:70