【目标跟踪】基于卡尔曼滤波实现多车辆路径跟踪含Matlab源码
【目标跟踪】基于卡尔曼滤波实现多车辆路径跟踪含Matlab源码
TT_Matlab
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,完整matlab代码或者程序定制加qq1575304183。
1 简介
卡尔曼滤波器是目标状态估计算法中常用的 滤波器,通过建立目标的状态模型并估计目标的运 动速度及加速度,可以对目标质心的未来点进行预 测, 从而缩小搜索区域, 克服由于目标被局部遮挡 时造成的跟踪丢失问题 。
基于卡尔曼滤波器的运动目标跟踪算法通常 有以下步骤 。
1)计算运动目标的特征信息。为了对运动目标进行跟踪, 首先用外接矩形对运动目标进行标 定 ,然后计算运动目标的质心和外接矩形的宽和高
2)用得到的特征信息初始化卡尔曼滤波器。由于初始化时对目标的速度以及目标外接矩形的 变化速度未知 ,所以对于这几个量初始化为 0。
3)用卡尔曼滤波器对下一帧中对应的目标区 域进行预测, 当下一帧到来后 , 在预测区域内进行 目标匹配 。
4)如果匹配, 则更新卡尔曼滤波器, 并记录下当前帧中的目标信息。基于卡尔曼滤波器的运动目标跟踪算法模型 如图 1所示。下面将详细讨论其主要步骤。
2 部分代码
function varargout = MainTrack(varargin)
% MAINTRACK MATLAB code
for
MainTrack.fig
% MAINTRACK, by itself, creates a new MAINTRACK
or
raises the existing
% singleton*.
%
% H = MAINTRACK returns the handle to a new MAINTRACK
or
the handle to
% the existing singleton*.
%
%进行扑拓处理
mask = imopen(mask, strel(
’rectangle’
, [
3
,
3
]));
mask = imclose(mask, strel(
’rectangle’
, [
15
,
15
]));
mask = imfill(mask,
’holes’
);
%获取分析图像
[~, centroids, bboxes] = obj.blobAnalyser.step(mask);
%预测新的路径
for
i =
1
:length
(tracks)
numAssignedTracks = size(assignments,
1
);
for
i =
1
:numAssignedTracks
trackIdx = assignments(i,
1
);
detectionIdx = assignments(i,
2
);
centroid = centroids(detectionIdx,
:
);
uttongroup2_CreateFcn(hObject, eventdata, handles)
% hObject handle to uibuttongroup2 (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
%set(handles.radioCam,
’value’
,
’1’
);
%set(handles.radioVideo,
’value’
,
’0’
);
% --- Executes on button press
in
snapShot.
function snapShot_Callback(hObject, eventdata, handles)
% hObject handle to snapShot (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
camSwitch=get(handles.radioCam,
’value’
);%获取radioWecam的数字,
1
或者
0
switch camSwitch
case
1
frame=snapshot(handles.cam);
%delete(handles.h);
axes(handles.main);
imshow(frame);
case
0
;
[fileName,pathName]=uigetfile({
’*.avi’
;
’*.mpeg’
;
’*.mov’
},
’读入视频’
);
if
(fileName ==
0
)
return
;
end
str=[pathName,fileName];
set(handles.videoPath,
’String’
,str);
set(handles.videoPath,
’visible’
,
’on’
);
% handles.video = vision.VideoFileReader(str);
handles.video = VideoReader(str);
set(handles.timeLimit,
’String’
,num2str(handles.video.Duration));
frame=readFrame(handles.video);
axes(handles.main);
imshow(frame);
end
handles.frame=frame;
set(handles.uiSelection,
’Visible’
,
’on’
);
guidata(hObject,handles);%更新数据
% n=
0
.
5
;
%
while
n<get(handles.radioCam,
’value’
)
% frame=snapshot(cam);
% imshow(frame);
% drawnow;
%
end
%
while
n>get(handles.radioCam,
’value’
)
% frame=step(handles.video);
% imshow(frame);
% drawnow;
%
end
% --- Executes
when
selected object is changed
in
uiSelection.
function uiSelection_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object
in
uiSelection
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function radioFull_CreateFcn(hObject, eventdata, handles)
% hObject handle to radioFull (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
handles.areaSwitch=
0
;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function selectArea_CreateFcn(hObject, eventdata, handles)
% hObject handle to selectArea (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
% --- Executes during object creation, after setting all properties.
function radiobutton5_CreateFcn(hObject, eventdata, handles)
% hObject handle to radiobutton5 (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
%
Hints:
get(hObject,
’Value’
) returns position of slider
% get(hObject,
’Min’
)
and
get(hObject,
’Max’
) to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
%
Hint:
slider controls usually have a light gray background.
if
isequal(get(hObject,
’BackgroundColor’
), get(
0
,
’defaultUicontrolBackgroundColor’
))
set(hObject,
’BackgroundColor’
,[.
9
.
9
.
9
]);
end
function saveName_Callback(hObject, eventdata, handles)
% hObject handle to saveName (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
%
Hints:
get(hObject,
’String’
) returns contents of saveName as text
% str2double(get(hObject,
’String’
)) returns contents of saveName as a double
% --- Executes during object creation, after setting all properties.
function saveName_CreateFcn(hObject, eventdata, handles)
% hObject handle to saveName (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
%
Hint:
edit controls usually have a white background on Windows.
% See ISPC
and
COMPUTER.
if
ispc && isequal(get(hObject,
’BackgroundColor’
), get(
0
,
’defaultUicontrolBackgroundColor’
))
set(hObject,
’BackgroundColor’
,
’white’
);
end
% --- Executes on button press
in
checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
%
Hint:
get(hObject,
’Value’
) returns toggle state of checkbox1
% --- Executes on button press
in
radiobutton9.
function radiobutton9_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton9 (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
%
Hint:
get(hObject,
’Value’
) returns toggle state of radiobutton9
saveSwitch=get(hObject,
’Value’
);
if
saveSwitch>
0
.
5
handles.saveSwitch=
1
;
set(handles.saveName,
’Visible’
,
’on’
)
else
handles.saveSwitch=
0
;
set(handles.saveName,
’Visible’
,
’off’
)
end
guidata(hObject,handles);
function timeLimit_Callback(hObject, eventdata, handles)
% hObject handle to timeLimit (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
%
Hints:
get(hObject,
’String’
) returns contents of timeLimit as text
% str2double(get(hObject,
’String’
)) returns contents of timeLimit as a double
% --- Executes during object creation, after setting all properties.
function timeLimit_CreateFcn(hObject, eventdata, handles)
% hObject handle to timeLimit (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
%
Hint:
edit controls usually have a white background on Windows.
% See ISPC
and
COMPUTER.
if
ispc && isequal(get(hObject,
’BackgroundColor’
), get(
0
,
’defaultUicontrolBackgroundColor’
))
set(hObject,
’BackgroundColor’
,
’white’
);
end
% --- Executes during object creation, after setting all properties.
function uibuttongroup4_CreateFcn(hObject, eventdata, handles)
% hObject handle to uibuttongroup4 (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
handles.f=[];%对figure的handles进行初始化
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function radiobutton9_CreateFcn(hObject, eventdata, handles)
% hObject handle to radiobutton9 (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
handles.saveSwitch=
0
;
guidata(hObject,handles);
function unitH_Callback(hObject, eventdata, handles)
% hObject handle to unitH (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
%
Hints:
get(hObject,
’String’
) returns contents of unitH as text
% str2double(get(hObject,
’String’
)) returns contents of unitH as a double
% --- Executes during object creation, after setting all properties.
function unitH_CreateFcn(hObject, eventdata, handles)
% hObject handle to unitH (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
%
Hint:
edit controls usually have a white background on Windows.
% See ISPC
and
COMPUTER.
if
ispc && isequal(get(hObject,
’BackgroundColor’
), get(
0
,
’defaultUicontrolBackgroundColor’
))
set(hObject,
’BackgroundColor’
,
’white’
);
end
3 仿真结果
4 参考文献
[1]武建, 张雷, 刘艋,等. 基于卡尔曼滤波器的运动目标跟踪的实现[J]. 硅谷, 2013(10):2.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。
-
2023年血糖新标准公布,不是3.9-6.1,快来看看你的血糖正常吗? 2023-02-07
-
2023年各省最新电价一览!8省中午执行谷段电价! 2023-01-03
-
GB 55009-2021《燃气工程项目规范》(含条文说明),2022年1月1日起实施 2021-11-07
-
PPT导出高分辨率图片的四种方法 2022-09-22
-
2023年最新!国家电网27家省级电力公司负责人大盘点 2023-03-14
-
全国消防救援总队主官及简历(2023.2) 2023-02-10
-
盘点 l 中国石油大庆油田现任领导班子 2023-02-28
-
我们的前辈!历届全国工程勘察设计大师完整名单! 2022-11-18
-
关于某送变电公司“4·22”人身死亡事故的快报 2022-04-26
