资源简介
MATLAB程序,背景建模,高斯模型,等等
代码片段和文件信息
clear all
% source = aviread(‘C:\Video\Source\traffic\san_fran_traffic_30sec_QVGA‘);
source = mmreader(‘E:\study\source\IndoorGTTest1.AVI‘);
frameQYT=get(source‘NumberOfframes‘);
% ----------------------- frame size variables -----------------------
fr = read(source1); % 读取第一帧作为背景
fr_bw = rgb2gray(fr); % 将背景转换为灰度图像
fr_size = size(fr); %取帧大小
width = fr_size(2);
height = fr_size(1);
fg = zeros(height width);
bg_bw = zeros(height width);
% --------------------- mog variables -----------------------------------
C = 4; % 组成混合高斯的单高斯数目 (一般3-5)
M = 0; % 组成背景的数目
D = 2.5; % 阈值(一般2.5个标准差)
alpha = 0.01; % learning rate 学习率决定更新速度(between 0 and 1) (from paper 0.01)
thresh = 0.75; % foreground threshold 前景阈值(0.25 or 0.75 in paper)
sd_init = 6; % initial standard deviation 初始化标准差(for new components) var = 36 in paper
w = zeros(heightwidthC); % initialize weights array 初始化权值数组
mean = zeros(heightwidthC); % pixel means 像素均值
sd = zeros(heightwidthC); % pixel standard deviations 像素标准差
u_diff = zeros(heightwidthC); % difference of each pixel from mean 与均值的差
p = alpha/(1/C); % initial p variable 参数学习率(used to update mean and sd)
rank = zeros(1C); % rank of components (w/sd)
% ------initialize component means and weights 初始化均值和权值----------
pixel_depth = 8; % 8-bit resolution 像素深度为8位
pixel_range = 2^pixel_depth -1; % pixel range 像素范围2的7次方0—255(# of possible values)
for i=1:height
for j=1:width
for k=1:C
mean(ijk) = rand*pixel_range; % means random (0-255之间的随机数)
w(ijk) = 1/C; % weights uniformly dist
sd(ijk) = sd_init; % initialize to sd_init
end
end
end
%----- process frames -处理帧--,这里去第八帧
n = 8;
fr = read(sourcen); % read in frame 读取帧
fr_bw = rgb2gray(fr); % convert frame to grayscale 转换为灰度图像
% calculate difference of pixel values from mean 计算像素差值
for m=1:C
u_diff(::m) = abs(double(fr_bw) - double(mean(::m)));
end
% update gaussian components for each pixel 更新每个像素的背景模型
for i=1:height
- 上一篇:四元数法计算两个物体之间的相对位姿参数
- 下一篇:matlab2014b
评论
共有 条评论