Kalman Filter笔记(2)
来源:互联网 发布:拆分复利源码 编辑:程序博客网 时间:2024/05/18 01:34
Kalman Filter分为两大部分,Predict和Correction。为了更好地理解Kalman Filter Tracking,我在Matlab File Exchange上找到了一个.m的仿真,看了半天发现作者取的是state_post,应该是将Kalman Filter做轨迹滤波用?
我将这个文件修改了一下,改成:
clear,clc
% compute the background image
Imzero = zeros(240,320,3);
for i = 1:5
Im{i} = double(imread(['DATA/',int2str(i),'.jpg']));
Imzero = Im{i}+Imzero;
end
Imback = Imzero/5;
[MR,MC,Dim] = size(Imback);
% Kalman filter initialization
R=[[0.2845,0.0045]',[0.0045,0.0455]'];
H=[[1,0]',[0,1]',[0,0]',[0,0]'];
Q=0.01*eye(4);
P = 100*eye(4);
dt=1;
A=[[1,0,0,0]',[0,1,0,0]',[dt,0,1,0]',[0,dt,0,1]'];
%g = 6; % pixels^2/time step
g = 0;
Bu = [0,0,0,g]';
kfinit=0;
x=zeros(100,4);
% loop over all images
for i = 1 : 60
% load image
Im = (imread(['DATA/',int2str(i), '.jpg']));
imshow(Im)
imshow(Im)
Imwork = double(Im);
% Kalman predict
i
if kfinit==0
xp = [MC/2,MR/2,0,0]'
else
xp=A*x(i-1,:)' + Bu
end
kfinit=1;
pred_pos = H*xp;
recorded_pred_pos(i,1) = pred_pos(1);
recorded_pred_pos(i,2) = pred_pos(2);
%extract ball
[cc(i),cr(i),radius,flag] = extractball(Imwork,Imback,i);
if flag==0
continue
end
hold on
for c = -1*radius: radius/20 : 1*radius
r = sqrt(radius^2-c^2);
%plot(x(i,1)+c,x(i,2)+r,'r.')
%plot(x(i,1)+c,x(i,2)-r,'r.')
plot(pred_pos(1)+c,pred_pos(2)+r,'r.')
plot(pred_pos(1)+c,pred_pos(2)-r,'r.')
end
hold on
for c = -1*radius: radius/20 : 1*radius
r = sqrt(radius^2-c^2);
plot(cc(i)+c,cr(i)+r,'g.')
plot(cc(i)+c,cr(i)-r,'g.')
end
% kalman update
PP = A*P*A' + Q
K = PP*H'*inv(H*PP*H'+R)
x(i,:) = (xp + K*([cc(i),cr(i)]' - H*xp))';
x(i,:)
[cc(i),cr(i)]
P = (eye(4)-K*H)*PP
pause(0.3)
end
% show positions
figure
plot(cc(10:60),'r*')
hold on
%plot(cr,'g*')
plot(recorded_pred_pos(10:60,1), 'go');
title('detected x position and predicted x position');
%end
figure
plot(cr(10:60),'r*')
hold on
%plot(cr,'g*')
plot(recorded_pred_pos(10:60,2), 'go');
title('detected y position and predicted y position');
在Matlab下运行,可以得到下面的结果:
- Kalman Filter笔记(2)
- Kalman Filter笔记(1)
- Kalman filter
- Kalman filter
- Kalman Filter
- Kalman Filter
- kalman filter
- Kalman Filter
- SLAM学习笔记2:Kalman Filter(卡尔曼滤波) 与Least Square(最小二乘法) 的比较
- SLAM笔记四——Extended Kalman Filter
- SLAM笔记六——Unscented Kalman Filter
- 有关Kalman Filter
- The Kalman Filter
- The Kalman Filter
- 【MATLAB】Extended Kalman Filter
- Kalman Filter介绍
- Kalman filter Intro - wiki
- Kalman Filter算法入门
- 解决了ConceptDraw PRO 8.0.7.0对中文支持不好的问题
- js时间比较
- 存储过程和函数
- quartz 关联多个 JobDetail和SimpleTrigger 多任务调度
- Android GSM驱动模块详细分析
- Kalman Filter笔记(2)
- 哦,第一次我。。。。
- 中小SAP项目中的人员编制{转载}
- Oracle JOB 使用方法
- 关于const,static,extern,volatile的用法
- 编写安全的代码--学习笔记(1)
- 开始→运行→输入的命令集锦
- 三层结构下多数据库大量用户访问怎么处理?
- C/C++中全局变量和全局文件的访问作用域