% meanshift tarcking (color based)
clear all
% -------------------------- read avi --------------------------
source = VideoReader('1.avi');
len = source.NumberOfFrames; % number of frames
for i = 1: len
Im = read(source,i);
imshow(Im);%顯示每一幀
end
[s1,s2] = size(Im); % height and width of a frame
% figure(1);imshow(Im);
grade = 16*16*16; % grade of feature(color)
% ------------------------------- crop a model -------------------------------
figure(1);
[modle,rect] = imcrop(Im);
[height,width,color] = size(modle);
rect(4) = height; % do some modification to rect
rect(3) = width;
rect(1) = round(rect(1));
rect(2) = round(rect(2));
x0 = width/2;
y0 = height/2; % coordinate of the central point
k = zeros(height,width); % value of a kernel function
h2 = x0^2+y0^2; % radius^2
for i = 1:height
for j = 1:width
k(i,j) = 1-((i-y0)^2+(j-x0)^2)/h2; % Epanechnikov kernel
end
end
c = 1/sum(sum(k)); % for normalization
p = zeros(1,grade); % color distribution
q = zeros(1,grade);
for i = 1:height
for j = 1:width
r = fix(double(modle(i,j,1))/16);
g = fix(double(modle(i,j,2))/16);
b = fix(double(modle(i,j,3))/16);
p(b*256+g*16+r+1) = p(b*256+g*16+r+1)+k(i,j);
end
end
p = p*c;
q = p;
提取码:t861
© 著作权归作者所有