视频跟踪标记-SampleVideo.zip
简介
通过帧差法进行视频跟踪,并做标记。
代码
% By lyqmath @ Matlab中文论坛
clc; clear all; close all;
avi = mmreader;
for i = 1 : avi.NumberOfFrames
img = read;
pixels = img;
figure; imshow;
text, 'FontWeight', 'Bold', 'Color', 'r');
end
tracking;
复制代码
function d = tracking
if ischar
% 载入视频数据
for i = 1 : avi.NumberOfFrames
img = read;
pixels = img;
end
else
pixels = video;
end
nFrames = size;
rows = size;
cols = size;
% 转换成灰度图像
for i = 1 : nFrames
pixel = ));
end
for i = 2 : nFrames
d = - pixel));
bw = im2bw, 0.2);
% 寻找上下边界
cou=1;
for h = 1:rows
for w = 1:cols
if bw > 0.5
bottomEdge = h;
if cou == 1
topEdge = bottomEdge;
end
cou = cou 1;
break;
end
end
end
% 寻找左右边界
coun=1;
for w = 1:cols
for h = 1:rows
if bw > 0.5
rightEdge = w;
if coun == 1
leftEdge = rightEdge;
coun = coun 1;
end
break;
end
end
end
% 矩形框生成
wd = rightEdge-leftEdge;
hg = bottomEdge-topEdge;
widt = wd/2;
heit = hg/2;
cenx = leftEdge widt;
ceny = topEdge heit;
% 显示并标记
figure;
imshow, []);
hold on
rectangle;
plot;
text, 'FontWeight', 'Bold', 'Color', 'r');
hold off
end
复制代码
视频文件
SampleVideo.zip
2022-11-09 19:22:19
610KB
matlab
1