%% Tracking Pedestrians from a Moving Car
%
% This example shows how to track pedestrians using a camera mounted in a
% moving car.
%
% Copyright 2014 The MathWorks, Inc.
%% Overview
% This example shows how to perform automatic detection and tracking of
% people in a video from a moving camera. It demonstrates the flexibility
% of a tracking system adapted to a moving camera, which is ideal for
% automotive safety applications. Unlike the stationary camera
% example, <motion-based-multiple-object-tracking.html The Motion-Based
% Multiple Object Tracking>, this example contains several additional
% algorithmic steps. These steps include people detection, customized
% non-maximum suppression, and heuristics to identify and eliminate false
% alarm tracks. For more information please see
% <docid:vision_ug#buq9qny-1 Multiple Object Tracking>.
%
% This example is a function with the main body at the top and helper
% routines in the form of
% <docid:matlab_prog#f4-39708 nested functions>
% below.
function PedestrianTrackingFromMovingCameraExample()
% Create system objects used for reading video, loading prerequisite data file, detecting pedestrians, and displaying the results.
videoFile = 'vippedtracking.mp4';
scaleDataFile = 'pedScaleTable.mat'; % An auxiliary file that helps to determine the size of a pedestrian at different pixel locations.
obj = setupSystemObjects(videoFile, scaleDataFile);
detector = peopleDetectorACF('caltech');
% Create an empty array of tracks.
tracks = initializeTracks();
% ID of the next track.
nextId = 1;
% Set the global parameters.
option.ROI = [40 95 400 140]; % A rectangle [x, y, w, h] that limits the processing area to ground locations.
option.scThresh = 0.3; % A threshold to control the tolerance of error in estimating the scale of a detected pedestrian.
option.gatingThresh = 0.9; % A threshold to reject a candidate match between a detection and a track.
option.gatingCost = 100; % A large value for the assignment cost matrix that enforces the rejection of a candidate match.
option.costOfNonAssignment = 10; % A tuning parameter to control the likelihood of creation of a new track.
option.timeWindowSize = 16; % A tuning parameter to specify the number of frames required to stabilize the confidence score of a track.
option.confidenceThresh = 2; % A threshold to determine if a track is true positive or false alarm.
option.ageThresh = 8; % A threshold to determine the minimum length required for a track being true positive.
option.visThresh = 0.6; % A threshold to determine the minimum visibility value for a track being true positive.
% Detect people and track them across video frames.
stopFrame = 1629; % stop on an interesting frame with several pedestrians
for fNum = 1:stopFrame
frame = readFrame(obj.reader);
[centroids, bboxes, scores] = detectPeople();
predictNewLocationsOfTracks();
[assignments, unassignedTracks, unassignedDetections] = ...
detectionToTrackAssignment();
updateAssignedTracks();
updateUnassignedTracks();
deleteLostTracks();
createNewTracks();
displayTrackingResults();
% Exit the loop if the video player figure is closed.
if ~isOpen(obj.videoPlayer)
break;
end
end
%% Auxiliary Input and Global Parameters of the Tracking System
% This tracking system requires a data file that contains information that
% relates the pixel location in the image to the size of the bounding box
% marking the pedestrian's location. This prior knowledge is stored in a
% vector |pedScaleTable|. The n-th entry in |pedScaleTable| represents the
% estimated height of an adult person in pixels. The index |n| references
% the approximate Y-coordinate of the pedestrian's feet.
%
% To obtain such a vector, a collection of training images were taken from
% the same viewpoint and in a similar scene to the testing environment. The
% training images contained images of pedestrians at varying distances
% from the camera. Using the
% <docid:vision_ref#mw_96fe579b-b33c-4798-a463-6fdeee7cd214 imageLabeler>
% app, bounding boxes of the pedestrians in the images were manually
% annotated. The height of the bounding boxes together with the location of
% the pedestrians in the image were used to generate the scale data file
% through regression. Here is a helper function to show the algorithmic steps to
% fit the linear regression model:
% <matlab:edit(fullfile(matlabroot,'toolbox','vision','visiondemos','helperTableOfScales.m')) |helperTableOfScales.m|>
%
%
% There is also a set of global parameters that can be tuned to optimize
% the tracking performance. You can use the descriptions below to learn
% about how these parameters affect the tracking performance.
%
% * |ROI| : Region-Of-Interest in the form of
% [x, y, w, h]. It limits the processing area to
% ground locations.
% * |scThresh| : Tolerance threshold for scale estimation.
% When the difference between the detected scale
% and the expected scale exceeds the tolerance,
% the candidate detection is considered to be
% unrealistic and is removed from the output.
% * |gatingThresh| : Gating parameter for the distance measure. When
% the cost of matching the detected bounding box
% and the predicted bounding box exceeds the
% threshold, the system removes the association
% of the two bounding boxes from tracking
% consideration.
% * |gatingCost| : Value for the assignment cost matrix to
% discourage the possible tracking to detection
% assignment.
% * |costOfNonAssignment| : Value for the assignment cost matrix for
% not assigning a detection or a track. Setting
% it too low increases the likelihood of
% creating a new track, and may result in track
% fragmentation. Setting it too high may result
% in a single track corresponding to a series of
% separate moving objects.
% * |timeWindowSize| : Number of frames required to estimate the
% confidence of the track.
% * |confidenceThresh| : Confidence threshold to determine if the
% track is a true positive.
% * |ageThresh| : Minimum length of a track being a true positive.
% * |visThresh| : Minimum visibility threshold to determine if
% the track is a true positive.
%% Create System Objects for the Tracking System Initialization
% The |setupSystemObjects| function creates system objects used for reading
% and displaying the video frames and loads the scale data file.
%
% The |pedScaleTable| vector, which is stored in the scale data file,
% encodes our prior knowledge of the target and the scene. Once you have the
% regressor trained from your samples, you can compute the expected height
% at every possible Y-position in the image. These values are stored in the
% vector. The n-th entry in |pedScaleTable| represents our estimated height
% of an adult person in pixels. The index |n| references the approximate
% Y-coordinate of the pedestrian's feet.
function obj = setupSystemObjects(videoFile,scaleDataFile)
% Initialize Video I/O
% Create objects for reading a video from a file, drawing the
% detected and tracked people in each frame, and playing the video.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
此示例演示如何从移动摄像机对视频中的人员执行自动检测和跟踪。此跟踪系统需要一个数据文件,其中包含将图像中的像素位置与标记行人位置的边界框的大小相关联的信息。这种先验知识存储在向量中。中的第 n 个条目表示成人的估计身高(以像素为单位)。该指数参考了行人脚的近似 Y 坐标。
资源推荐
资源详情
资源评论
收起资源包目录
基于Matlab的汽车在行驶中摄像机跟踪行人的算法实现.rar (2个子文件)
基于Matlab的汽车在行驶中摄像机跟踪行人的算法实现
PedestrianTrackingFromMovingCameraExample.m 25KB
helperTableOfScales.m 2KB
共 2 条
- 1
资源评论
珞瑜·
- 粉丝: 10w+
- 资源: 500
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功