Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Kalman filter by opencv

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how opencv implements Kalman filtering". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to implement Kalman filter in opencv"!

Kalman filter is to fuse the data predicted by the model and the observation data to filter out the observation error, and then get more accurate data.

For example, if a car is moving on a plane, the car is programmed to move forward with an initial velocity of V0 and an acceleration of a, but due to various errors and reasons (such as wind, uphill, etc.), our car does not follow this model strictly, and there is noise (and assumes Gaussian distribution).

And we constantly use sensors to measure the position of the car, but the sensor also has Gaussian noise distribution.

Kalman filter has five main formulas, based on this example, we look at it in turn.

The first formula:

Xk: Current state description matrix

Fk: State transition matrix

Bk: Control matrix

Uk: control vector

For a car, the state description is its one-dimensional position x and velocity v:

The state transition matrix is the transition from one moment to the next:

Multiplying Fk and Xk − 1 yields:

Obviously, the state of the car under constant motion has changed.

But our car is accelerating uniformly, and we think of acceleration as a control vector Uk, because acceleration is caused by stepping on the accelerator or something.

Since we only have one control variable and acceleration a,

The control matrix Bk is to transform the control vector and embody the control variable on the state Xk:

So far, we have derived the ideal change of state of the car from the last moment to the present moment using the first formula.

The second formula:

Pk: describes the cross-correlation between state variables, is the covariance matrix of Xk, that is, Cov(Xk)

Fk: State transition matrix

Qk: covariance of external noise

Pk is the covariance of Xk, our first formula updates the state vector Xk, and our second formula updates the covariance Pk of Xk, plus an external noise Qk.

Since we are using Kalman filtering, the states of our target objects are Gaussian, so we have two variables to look at: the mean and the covariance. So we need to update Xk, which includes the mean and variance, and we need to update the covariance to pay attention to the degree of correlation between the state variables.

The third formula:

K: Kalman gain matrix

Hk: Sensor data

Pk: covariance of noise measured by sensor

The meaning of the third formula is to find K, and K is for use in Formula 45. It has no intuitive meaning to take it out alone.

We know that Kalman filtering is to fuse the observation data of the sensor with the prediction data of the model, and what Equation 1 does is to give the prediction data of the model, and Equation 345 does is to fuse the prediction data with the observation data to obtain a new and more accurate data.

In between, there is the step of collecting observation data, but this is not part of the Kalman filter algorithm.

Then how do we fuse them? Our predicted and observed data are Gaussian distributions, and the relationship between them is roughly as follows:

And obviously the overlap between the two is the optimal most likely distribution. How do you get to the middle one? is to multiply two Gaussian distributions.

After multiplying the two (that is, after merging), the result is roughly as follows:

For simplicity, let's simplify with a k:

This k is the Kalman gain we seek from Formula 3! (in one dimension)

The latter two formulas are one-dimensional expressions of our formula 45, but because our actual problem may be multidimensional, our actual formula is expressed in matrix, which may be more complicated.

The fourth formula:

Xk': State distribution after data fusion

Xk: model-predicted Xk state distribution

Zk: Mean of Xk

HkXk: Mean of sensor observations

The fifth formula:

Update the cross-correlation of state descriptors.

At this point, I believe everyone has a deeper understanding of "how to implement Kalman filter in opencv," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report