动态背景下目标跟踪算法目标跟踪

该博客详细介绍了在动态背景下使用MATLAB实现的目标跟踪算法,特别是针对网球的跟踪。程序通过图像处理技术,包括灰度转换、中值滤波、阈值处理和区域属性分析来识别和定位网球。通过调整窗口大小和位置,算法能够适应网球在不同帧间的运动变化,并计算网球的速度。此外,程序还考虑了不同阶段网球运动速度的变化,以提高跟踪准确性。
摘要由CSDN通过智能技术生成

1.问题描述:

 动态背景下目标跟踪算法目标跟踪

2.部分程序:

 

% Programming By ALireza Fasih
% Email: ar_fasih@yahoo.com
% Please copy images (*.ppm) to work directory, then push F5 to view results.

clc;       % clear consul
clear all; % clear all variable

% Ball Threshold Min & Max Values
th_min_ball=80;
th_max_ball=214;

% number of frams
frams = 88;

% Ball Pos initialize
old_ball_pos_x=0;
old_ball_pos_y=0;
Ball_speed_list(2,10)=0;
ball_vel_x=0;
ball_vel_y=0;

delta_x=25;
delta_y=25;


counter=0;
for i = 21: frams
 fname=strcat('stennis.',int2str(i),'.ppm'); % Incrimental String Variable for Indexing file name

 
 if (i<35)
  delta_x=35;
  delta_y=35;
 else
  delta_x=25;
  delta_y=25;     
 end
 
 if (i>80)
  delta_x=30;
  delta_y=15;
 end
 
 
 k=imread(fname);       % Load Image to 'k' Matrix 
 k1=k;
 if (old_ball_pos_x ~=0)
   k1=imcrop(k,[ round(old_ball_pos_x-delta_x) round(old_ball_pos_y-delta_y) delta_x.*2 delta_y.*2 ]);
 end
 
 I=rgb2gray(k1);        % Converting RGB Image to Gray Scale Image
 I=im2double(I);        % Converting Gray scale Image to Double type

  J = medfilt2(I,[3 3]); % Median Filter , 3x3 Convolution on Image 
 I2 = imadjust(J);       % Improve to quality of Image and adjusting contrast and brightness values
 Ib = I2> 0.8627;        %(220./255); % Binary Threshold for Ball
 

 [labeled,numObjects] = bwlabel(Ib,4);              % Indexing segments by binary label function
 graindata = regionprops(labeled,'all');            % extracting properties from regions, 'all' means we need to all attributes
 display(i); % show cycle

  %---------------------- Ball Area,  Filter --------------- 
  a_f = find( [graindata.Area] > th_min_ball & [graindata.Area] < th_max_ball); % Because Ball area is in range of 80 and 211  
  c1=length(a_f);
  %---------------------- Ball W/H Ratio,  Filter --------------- 
  sel=1;     % default value
  for j = 1 : c1   
    
    Ma=graindata(a_f(j)).MajorAxisLength;
    Mi=graindata(a_f(j)).MinorAxisLength;
    ratio_w_h =   Ma./Mi;
    
     if (ratio_w_h<1.7)  % Ball or semi circle ratio range = ratio>0.6 & ratio<1.7  
        sel = a_f(j);
     end
  end
  

 imshow(k); %k
 hold on;
 
 set(findobj(gca,'Type','line','Color',[0 0 1]),...
    'Color','Blue',...
    'LineWidth',3)

 % Draw point on Ball Center
 c1=graindata(sel).Centroid;

 pos_list(1,i+1)=c1(1);
 pos_list(2,i+1)=240-c1(2);
 plot(c1(1)+old_ball_pos_x-delta_x,c1(2)+old_ball_pos_y-delta_y,'rx');
 
 for tt=0:0.05:(2*pi)
  plot(c1(1)+old_ball_pos_x-delta_x+40*cos(tt),c1(2)+old_ball_pos_y-delta_y+40*sin(tt),'g');
 end
 

  if (i>0)
    ball_vel_x = (old_ball_pos_x - c1(1))./24; % 24 frame in second    velocity = variation of position in delta time    
    ball_vel_y = (old_ball_pos_y - c1(2))./24;
  end
    
  Ball_speed_list(1,i+1)=ball_vel_x;
  Ball_speed_list(2,i+1)=ball_vel_y;


 if (counter>0)
  old_ball_pos_x=old_ball_pos_x-delta_x+c1(1);
  old_ball_pos_y=old_ball_pos_y-delta_y+c1(2);  
 else
  old_ball_pos_x=c1(1);
  old_ball_pos_y=c1(2);       
 end
 counter=counter+1;
 
 pause(0.1);
 
end            


 

3.仿真结论:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fpga和matlab

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值