基于Matlab的meanshift结合颜色特征跟踪目标的程序

在这里插入图片描述

% 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;

完整代码链接:https://pan.baidu.com/s/1N6WBgxcDHDTJ9vJsTgQ93A

提取码:t861

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值