Opencv learning notes () -- Kalman Filter for Moving Object Tracking

Source: Internet
Author: User

Everyone is familiar with Kalman filtering. The basic idea is to get the estimated values of state variables and output signals without considering the effects of input signals and observed noise, after weighting the estimation error of the output signal, the estimation value of the state variable is corrected to minimize the mean variance of the estimation error of the state variable. I don't want to worry about the specific principle and implementation of it here, but this theoretical basis must be: To use Kalman Filter for tracking, you mustFirst, create a motion model and an observation model.It is not intended to be used. If you cannot create a motion model, it means that you cannot solve the problem with Kalman filter.

I will take a look at the built-in opencvKalman. cppThis routine describes how to use Kalman filter in opencv. opencv has encapsulated Kalman filter into a class of kalmanfilter. It is very convenient to use, but the various matrices are easy to understand. One thing you need to know here is:To use Kalman filter, you need to know the state estimation value x of the previous moment, and the current observed value y, you also need to establish the state equation and measurement equation.With this, you can use Kalman filter.

Opencv comes with a routine to track the motion of a one-dimensional point. Although this point is moving in a two-dimensional plane, because it is moving on an arc, there is only one degree of freedom, angle, so it is still one-dimensional. Or a uniform motion. If the state variable X = [x1, x2] = [angle, angular velocity] is set, the motion model is

X1 (k + 1) = x1 (k) + X2 (k) * t

X2 (k + 1) = x2 (k)

The state transition equation is

X * = AX + W

If the noise is a Gaussian random noise, the measurement equation is:

Z = cx + V

ReadCode, Corresponding to the above items:

State estimation value x --> state

Current observed value Z --> Measurement

The member variable transitionmatrix in the kalmanfilter class is matrix A in the state transition equation.

The member variable measurementmatrix in the kalmanfilter class is the matrix C in the measurement equation.

Mat statepre ;//! <Predicted state (x' (k): X (K) = A * X (k-1) + B * U (k) mat statepost ;//! <Corrected state (x (k): X (K) = x' (k) + K (k) * (Z (k)-H * x' (k )) mat transitionmatrix ;//! <State transition matrix (a) mat controlmatrix ;//! <Control matrix (B) (not used if there is no control) mat measurementmatrix ;//! <Measurement Matrix (h) mat processnoisecov ;//! <Process noise covariance matrix (q) mat measurementnoisecov ;//! <Measurement noise covariance matrix (r) 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 errorcovpost ;//! <Posteriori Error Estimate covariance matrix (P (k): p (K) = (I-K (k) * h) * P' (k)

I don't want to translate it any more. I believe that with the above comments, everyone can find their corresponding items.

In addition to initializing the transitionmatrix and measurementmatrix that I just initializedProcessnoisecov, measurementnoisecov and errorcovpost.

After they are initialized, the next action will be very simple, in two steps,The first step is to call the member function predict to obtain the estimated value of the current state variable. The second step is to call the member function correct to use the observed value to correct the state variable.. Update the status variable for the next estimation. The code won't be uploaded.Opencv2.3.1 \ samples \ CPP \ Kalman. cpp.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.