动态背景下目标跟踪算法目标跟踪
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.仿真结论:
相关文章
- 扑克牌魔术里面的算法
- 算法思想
- 【算法】【递归与动态规划模块】纸牌博弈问题(多线路型递归)
- 【算法】【递归与动态规划模块】字符串之间转换的最小代价
- 关于动态规划算法的总结
- 算法笔记之动态规划
- 算法手撕代码21~25
- 蚁群算法搜索个体适应度值
- C#,动态规划(DP)模拟退火(Simulated Annealing)算法与源代码
- C#,插入排序算法(Insert Sort Algorithm)的源代码与数据可视化
- python动态规划算法的使用过程
- baselines算法库baselines/common/input.py模块分析
- js快速排序算法
- LeetCode055,045之跳跃游戏(相关话题:动态规划,贪心算法)
- 129、【动态规划/贪心算法】leetcode ——53. 最大子数组和(C++版本)
- 华为OD机试 - 英文输入法单词联想(Python) | 机试题+算法思路+考点+代码解析 【2023】
- 华为OD机试 -内存资源分配(Java) | 机试题+算法思路+考点+代码解析 【2023】
- 秒懂算法 | 子集树模型——0-1背包问题的回溯算法及动态规划改进
- hdu5289 Assignment (区间查询最大值最小值,st算法...)
- 蓝桥杯 之 算法训练 排序
- 我的算法学习之路(转载)
- 31数据结构与算法分析之---图的基本概念
- 检测模型改进—OHEM与Focal-Loss算法总结