目标跟踪 matlab,matlab实现视频中的目标跟踪,求大神帮忙翻译下代码!!

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

代码如下,请各位大神有事没事来看看~代码不多~应该不难的~在下感激不尽!!

0ee15b971fd07cebd6391aa6f2f63e15.png

clear,clc

%读入背景

Imzero = zeros(240,360,3);

Imzero=imread('background.jpg');

Imback=double(Imzero);

[MR,MC,Dim] = size(Imback);

%求出Vx 和 Vy

I0 = imread(strcat('man',int2str(0)) ,'jpg');

Imwork = double(I0);

[cc(1),cr(1),~, ~,~,index] = extractman(Imwork,Imback,1);

I79 = imread(strcat('man',int2str(79)) ,'jpg');

Imwork = double(I79);

[cc(80),cr(80),flag, stats,labeled,index] = extractman(Imwork,Imback,80);

Sx = cc(1)-cc(80);

Sy = cr(1)-cr(80);

Vx = Sx/80;

Vy = Sy/80;

% Kalman filter initialization

dt=1;

A=[[1,0,0,0]',[0,1,0,0]',[-Vx*dt,0,1,0]',[0,-Vy*dt,0,1]'];

C=[[1,0]',[0,1]',[0,0]',[0,0]'];

Q=0.5*eye(4);

R=[[0.2845,0.0045]',[0.0045,0.0455]'];

x=zeros(80,4);

P = 80*eye(4);

I = eye(4);

firstinit=1;

% loop over all images

h = 1;

for i = 1 : 20

% 装入各帧

Im = imread(strcat('man',int2str(i*4-1)) ,'jpg');

if h > 0

figure(h);

clf;

end

imshow(Im)

Imwork = double(Im);

%目标检测

[cc(i),cr(i),flag, stats,labeled,index] = extractman(Imwork,Imback,i);

%判断是否提取到目标特征

if flag==0

continue

end

%绘制检测结果的矩形框

rectangle('Position', round(stats(index).BoundingBox),'EdgeColor','g');

% 卡尔曼滤波

if firstinit == 1;

xp = [280,145,0,0]';

fristinit = 0;

else

xp=A*x(i-1,:)';

end

PP = A*P*A'+Q;

K = PP*C'*inv(C*PP*C'+R);

x(i,:) = (xp + K*([cc(i),cr(i)]' - C*xp))';

x(i,:)

[cc(i),cr(i)]

P = (eye(4)-K*C)*PP;

%P = (I - K*C)*PP*(I - K*C)' + K*R*K';

%inv(P) = inv(PP) + C'*inv(R)*K;

%绘制跟踪矩形框

[row, col, v] = find(labeled == index);

width = abs(max(col)-min(col));

hight = abs(max(row)-min(row));

xdownleft = x(i,1)-width/2;

ydownleft = x(i,2)-hight/2;

hold on

if width > 0 && hight > 0

rectangle('Position',[xdownleft,ydownleft,width, hight],'EdgeColor', 'r');

%plot(x(i,1),x(i,2),'r*');

end

%各帧之间的延迟

pause(0.3)

end

%显示检测中心点的轨迹

figure

plot(cc,'r*')

hold on

plot(cr,'g*')

%显示跟踪中心点的轨迹

figure

plot(x(:,1),'rx')

hold on

plot(x(:,2),'gx')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值