-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo_meanshift.m
46 lines (41 loc) · 1.46 KB
/
demo_meanshift.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
% ===============================================================================
% This demo is about meanshift tracking
% Author: Shuo Chang
% E-mail: changshuo@bupt.edu.cn
% ===============================================================================
clear; close all; clc
% Load video
mov = VideoReader('./data/Homework_video.mp4');
num_bin = 256;
kernel = 'normal';
dim = 2;
frame_index = 1;
while hasFrame(mov)
if frame_index == 1 % First frame, create GUI
fig_handle = figure('Name', 'MeanShift-Tracking');
frame_data = readFrame(mov);
imshow(frame_data);
rect = getrect(fig_handle);
hold on;
rectangle('Position', rect, 'EdgeColor', 'g', 'LineWidth',2);
true_target_distribution = generate_target_distribution(rect, frame_data, dim, num_bin, kernel);
text(10, 10, int2str(frame_index), 'color', [0 1 1]);
hold off;
axis off;
axis image;
set(gca, 'Units', 'normalized', 'Position', [0 0 1 1]);
frame_index = frame_index + 1;
else
figure(fig_handle);
frame_data = readFrame(mov);
rect = mean_shift(rect, true_target_distribution, frame_data, dim, num_bin, 100, 30);
imshow(frame_data);
hold on;
rectangle('Position', rect, 'EdgeColor', 'g', 'LineWidth', 2);
text(10, 10, int2str(frame_index), 'color', [0 1 1]);
hold off;
frame_index = frame_index + 1;
end
drawnow;
end
close all;