資源簡介
ViBe是一種像素級視頻背景建模或前景檢測的算法,效果優(yōu)于所熟知的幾種算法,對硬件內(nèi)存占用也少。

代碼片段和文件信息
%%?Parameters
numberOfSamples?????????=?param.numberOfSamples;
matchingThreshold???????=?param.matchingThreshold;
matchingNumber??????????=?param.matchingNumber;
updateFactor????????????=?param.updateFactor;
numberOfHistoryImages???=?param.numberOfHistoryImages;
%%?Initialize?ViBe
%?originalImage=vidframe;%%開辟一塊存儲用于保存各像素點(diǎn)的原始背景模型
%?flags=unit8(zeros(height?width));%%為每一個(gè)像素設(shè)置一個(gè)標(biāo)志只是該像素點(diǎn)是否保存有原始背景模型,1為保存了原始背景模型,初始化為0
%?counters=unit8(zeros(heightwidth));%%為每一個(gè)像素點(diǎn)設(shè)置一個(gè)計(jì)數(shù)器,用來統(tǒng)計(jì)該像素點(diǎn)連續(xù)被判為前景的幀數(shù)
historyImages?=?cell(1?numberOfHistoryImages);
for?ii?=?1:length(historyImages)
????historyImages{ii}?=?vidframe;
end
hsvImage=hsvframe;
historyBuffer?=?cell(1?numberOfSamples?-?numberOfHistoryImages);
for?ii?=?1:length(historyBuffer)??%%??通過人為地對圖像加入一定范圍內(nèi)的隨機(jī)噪聲構(gòu)建樣本集,這也時(shí)官網(wǎng)代碼中的做法。
%?????historyBuffer{ii}?=?vidframe?+?double(floor(rand(height?width))*20?-?10);
????historyBuffer{ii}?=?vidframe?+?double(floor(rand(height?width)*20-?10)?);
end
%%?Random?Part
%?對于時(shí)間取樣和空間鄰域更新策略,在官網(wǎng)代碼實(shí)現(xiàn)的時(shí)候確實(shí)很巧妙,
%?個(gè)人覺得很體現(xiàn)代碼功力。實(shí)現(xiàn)的時(shí)候,如果對每一個(gè)點(diǎn)都進(jìn)行概率判斷,
%?就相當(dāng)于遍歷了每一個(gè)像素點(diǎn),復(fù)雜度為O(height*width);換個(gè)角度思考,
%?每個(gè)點(diǎn)都有一定概率(比如1/rate)才更新,等同于整幅圖圖像每次會更新
%?一定概率部分個(gè)點(diǎn),即1/rate*height*width個(gè)點(diǎn)更新,這樣整體的計(jì)算復(fù)
%?雜度就會降到O(1/rate*height*width)。
size?=2*max(height?width)?+?1;?
%?jump[]?from?1?to?2*updateFactor
%?官網(wǎng)在實(shí)現(xiàn)的時(shí)候是通過隨機(jī)步長的方式,
%?比如,步長為1~(2*rate?-?1)之間的一個(gè)隨機(jī)數(shù),
%?每次更新一個(gè)點(diǎn)就向前移動一定步長。(假設(shè)整幅
%?圖像存儲為一個(gè)一維數(shù)組,每次通過加步長計(jì)算索
%?引)這樣計(jì)算下來,平均每次移動的步長約等于rate,
%?那么整幅圖像就會有1/rate*height*width進(jìn)行更新,等價(jià)實(shí)現(xiàn)
jump?=?floor(rand(1?size)*2*updateFactor)?+?1;%%隨機(jī)步長
%?neighborX?Y?represent?the?neighbor?index
neighborX?=?floor(rand(1?size)*3)?-?1;%?-1~1
neighborY?=?floor(rand(1?size)*3)?-?1;
%?position[]?from?1?to?numberOfSamples
position?=?floor(rand(1?size)*numberOfSamples)?+?1;??%1~20
disp(‘Initialize?ViBe‘)
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????2460??2017-02-21?18:00??vibeSegmentation.m
?????文件???????4330??2017-02-21?17:08??vibeUpdate.m
?????文件???????2187??2017-02-21?11:00??initViBe.m
?????文件???????2676??2017-05-10?09:18??main.m
-----------?---------??----------?-----??----
????????????????11653????????????????????4
評論
共有 條評論