class cv::KalmanFilter

Overview

Kalman filter class. More…

#include <tracking.hpp>

class KalmanFilter
{
public:
    // fields

    Mat controlMatrix;
    Mat errorCovPost;
    Mat errorCovPre;
    Mat gain;
    Mat measurementMatrix;
    Mat measurementNoiseCov;
    Mat processNoiseCov;
    Mat statePost;
    Mat statePre;
    Mat temp1;
    Mat temp2;
    Mat temp3;
    Mat temp4;
    Mat temp5;
    Mat transitionMatrix;

    // construction

    KalmanFilter();

    KalmanFilter(
        int dynamParams,
        int measureParams,
        int controlParams = 0,
        int type = CV_32F
        );

    // methods

    const Mat&
    correct(const Mat& measurement);

    void
    init(
        int dynamParams,
        int measureParams,
        int controlParams = 0,
        int type = CV_32F
        );

    const Mat&
    predict(const Mat& control = Mat());
};

Detailed Documentation

Kalman filter class.

The class implements a standard Kalman filter http://en.wikipedia.org/wiki/Kalman_filter, [91]. However, you can modify transitionMatrix, controlMatrix, and measurementMatrix to get an extended Kalman filter functionality. See the OpenCV sample kalman.cpp.

  • An example using the standard Kalman filter can be found at opencv_source_code/samples/cpp/kalman.cpp

Fields

Mat controlMatrix

control matrix (B) (not used if there is no control)

Mat errorCovPost

posteriori error estimate covariance matrix (P(k)): P(k)=(I-K(k)*H)*P’(k)

Mat errorCovPre

priori error estimate covariance matrix (P’(k)): P’(k)=A*P(k-1)*At + Q)*/

Mat gain

Kalman gain matrix (K(k)): K(k)=P’(k)*Ht*inv(H*P’(k)*Ht+R)

Mat measurementMatrix

measurement matrix (H)

Mat measurementNoiseCov

measurement noise covariance matrix (R)

Mat processNoiseCov

process noise covariance matrix (Q)

Mat statePost

corrected state (x(k)): x(k)=x’(k)+K(k)*(z(k)-H*x’(k))

Mat statePre

predicted state (x’(k)): x(k)=A*x(k-1)+B*u(k)

Mat transitionMatrix

state transition matrix (A)

Construction

KalmanFilter()

The constructors.

In C API when CvKalman* kalmanFilter structure is not needed anymore, it should be released with cvReleaseKalman(&kalmanFilter)

KalmanFilter(
    int dynamParams,
    int measureParams,
    int controlParams = 0,
    int type = CV_32F
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

dynamParams Dimensionality of the state.
measureParams Dimensionality of the measurement.
controlParams Dimensionality of the control vector.
type Type of the created matrices that should be CV_32F or CV_64F.

Methods

const Mat&
correct(const Mat& measurement)

Updates the predicted state from the measurement.

Parameters:

measurement The measured system parameters
void
init(
    int dynamParams,
    int measureParams,
    int controlParams = 0,
    int type = CV_32F
    )

Re-initializes Kalman filter. The previous content is destroyed.

Parameters:

dynamParams Dimensionality of the state.
measureParams Dimensionality of the measurement.
controlParams Dimensionality of the control vector.
type Type of the created matrices that should be CV_32F or CV_64F.
const Mat&
predict(const Mat& control = Mat())

Computes a predicted state.

Parameters:

control The optional input control