资源简介
通过matlab实现RPCA,能够快速的读取avi视频并生成对应的前景视频
代码片段和文件信息
function multiobjectTracking()
% 创建用于读取视频,检测运动物体的系统对象,
%显示结果。
obj = setupSystemobjects();
tracks = initializeTracks(); % Create an empty array of tracks.
nextId = 1; % ID of the next track
% Detect moving objects and track them across video frames.
while ~isDone(obj.reader)
frame = readframe();
[centroids bboxes mask] = detectobjects(frame);
predictNewLocationsOfTracks();
[assignments unassignedTracks unassignedDetections] = ...
detectionToTrackAssignment();
updateAssignedTracks();
updateUnassignedTracks();
deleteLostTracks();
createNewTracks();
displayTrackingResults();
end
function obj = setupSystemobjects()
% 初始化视频 I/O
%创建对象用于读取视频 绘制每一帧的跟踪目标 播放视频
% 创建视频读取器.
obj.reader = vision.VideoFileReader(‘C:\Users\Traecherous\Documents\MATLAB\美赛模拟\Problem B Attch 1 static background video\airport\input.avi‘);
% 创建两个 视频播放窗口 一个用于播放视频
% 一个用于播放前景掩模.
obj.videoPlayer = vision.VideoPlayer(‘Position‘ [20 400 700 400]);
obj.maskPlayer = vision.VideoPlayer(‘Position‘ [740 400 700 400]);
%创建用于前景检测和斑点分析的系统对象
% The foreground detector is used to segment moving objects from
% the background. 它输出二值掩模 前景为1 背景为0.
obj.detector = vision.ForegroundDetector(‘NumGaussians‘ 3 ...
‘NumTrainingframes‘ 5 ‘MinimumBackgroundRatio‘ 0.7);
% Connected groups of foreground pixels are likely to correspond to moving
% objects. The blob analysis System object is used to find such groups
% (called ‘blobs‘ or ‘connected components‘) and compute their
% characteristics such as area centroid and the bounding box.
obj.blobAnalyser = vision.BlobAnalysis(‘BoundingBoxOutputPort‘ true ...
‘AreaOutputPort‘ true ‘CentroidOutputPort‘ true ...
‘MinimumBlobArea‘ 400);
end
function tracks = initializeTracks()
% create an empty array of tracks
tracks = struct(...
‘id‘ {} ...
‘bbox‘ {} ...
‘kalmanFilter‘ {} ...
‘age‘ {} ...
‘totalVisibleCount‘ {} ...
‘consecutiveInvisibleCount‘ {});
end
function frame = readframe()
frame = obj.reader.step();
end
function [centroids bboxes mask] = detectobjects(frame)
% Detect foreground.
mask = obj.detector.step(frame);
% Apply morphological operations to 清除噪声 填补空洞.
mask = imopen(mask strel(‘rectangle‘ [33]));
mask = imclose(mask strel(‘rectangle‘ [15 15]));
mask = imfill(mask ‘holes‘);
% 进行斑点分析 找到连接部件.
[~ centroids bboxes] = obj.blobAnalyser.step(mask);
end
function predictNewLocationsOfTracks()
for i = 1:length(tracks)
bbox = tracks(i).bbox;
% 预测轨道当前位置.
predictedCentroid = pred
- 上一篇:数字水印技术matlab代码
- 下一篇:平面桁架有限元分析matlab程序
评论
共有 条评论