In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how the simple implementation of the Kalman filter is, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
In the field of target tracking, Kalman filter is a very common method.
Taking tracking the position and velocity of an object in a two-dimensional plane as an example, this paper illustrates how to implement a simple Kalman tracker.
It is implemented using the KalmanFilter class in OpenCV.
1. Parameter initialization kalman = cv2.KalmanFilter (4primer 2)
Indicates that the transfer matrix dimension of the Kalman filter is 4 and the measurement matrix dimension is 2.
Because the state variables include four (displacements and velocities in x and y directions, respectively), two quantities can be observed (displacements in x and y directions, respectively).
Kalman.measurementMatrix = np.array ([[1jc0pj0d0d0re0], [0rect 1d0d0re0]], np.float32)
The measurement matrix and its meaning are:
Kalman.transitionMatrix = np.array ([[1rect 0rem 1je 0], [0rect 1je 0je 1], [0je 0re 0re 1je 0], [0je 0je 0je 0st]], np.float32)
The transfer matrix and its meaning are:
Kalman.processNoiseCov = np.array (np.float32) * 0.003kalman.measurementNoiseCov = np.array ([[1rect 0rect 0je 0], [0rect 1je 0je 0je 0], [0je 0re 0je 1je 0], np.float32) * 0.003kalman.measurementNoiseCov = np.array ([[1jue 0], [0je 1]], np.float32) * 0.5)
Process noise and measurement noise are estimated by an empirical value.
two。 Generate test data
The trigonometric function is used to superimpose random disturbance to generate test data.
Def data_generator (length=100): dxy = [] xy = [] last_xy = [0 0] for i in range (length): x_base = 5-5 * math.cos (2 * I * math.pi / length) y_base = 50-50 * math.cos (2 * I * math.pi / length) x_noise = 1 * (random ()-0.5) y_noise = 20 * (random ()-0.5) dx_base = math.sin (2 * I * Math.pi / length) dy_base = 30 * math.sin (2 * I * math.pi / length) dx_noise = 1 * (random ()-0.5) dy_noise = 5 * (random ()-0.5) cur_xy = [x_base + x_noise + dx_base + dx_noise \ y_base + y_noise + dy_base + dy_noise] cur_dxy = [cur_xy [0]-last_xy [0], cur_xy [1]-last_xy [1]] xy.append (cur_xy) dxy.append (cur_dxy) last_xy = cur_xy return np.array (dxy, dtype=np.float32),\ np.array (xy, dtype=np.float32) 3. Running
The core is the two methods of kalman:
Correct updates current measurements
Predict predicts the value of the next frame.
Length = 100dxy, xy = data_generator2 (length) dxy_pred = [] xy_pred = [] for i in range (length): kalman.correct (XYY [I]) current_prediction = kalman.predict () xy_pred.append (current_prediction [: 2,0]) dxy_pred.append (current_prediction [2xy]) dxy_pred = np.stack (dxy_pred, axis=0) xy_pred = np.stack (xy_pred, axis=0) 4. Visualization
Using Matplotlib to visualize the result
The visualization part of the code is as follows:
Plot_image ((xy, dxy, xy_pred, dxy_pred) def plot_image (inputs): xy, dxy, xy_pred, dxy_pred = inputs fig, axes = plt.subplots (2,2) fig.set_size_inches (18,9) axes [0,0] .plot (xy [:, 0], color='red', label='Measured') axes [0,0] .plot (xy_pred [:, 0], color='blue' Label='Predicted') axes [0,1] .plot (xy [:, 1], color='red', label='Measured') axes [0,1] .plot (xy_pred [:, 1], color='blue', label='Predicted') axes [1,0] .plot (dxy [:, 0], color='red', label='Measured') axes [1,0] .plot (dxy_pred [:, 0], color='blue', label='Predicted') axes [1 1] .plot (dxy [:, 1], color='red', label='Measured') axes [1,1] .plot (dxy_pred [:, 1], color='blue', label='Predicted') axes [0,0] .Set _ title ('Distance-Xerox title title') axes [0,1] .plot [1,0] .set _ title ('Speed-X' Loc='center',fontstyle='normal') axes [1,1] .Set _ title ('Speed-Yanzhidagi localizedcenterprising paramedics Fontstylewritten filters') axes [0,0] .circle () axes [0,1] .benchmark () axes [1,0] .plt.show () plt.show () return's simple implementation of the Kalman filter is shared here. I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.