資源簡(jiǎn)介

代碼片段和文件信息
%?創(chuàng)建系統(tǒng)對(duì)象,用于讀入待處理視頻
filename?=?‘viptraffic.avi‘;
hvfr?=?vision.VideoFileReader(filename?‘ImageColorSpace‘?‘RGB‘);
%?創(chuàng)建系統(tǒng)對(duì)象,用于色彩空間轉(zhuǎn)換
hcsc?=?vision.ColorSpaceConverter(‘Conversion‘?‘RGB?to?intensity‘);
%?創(chuàng)建系統(tǒng)對(duì)象,用于用高斯混合模型檢測(cè)背景
hfdet?=?vision.ForegroundDetector(...
????????‘NumTrainingframes‘?5?...?????%?取連續(xù)五幀進(jìn)行檢測(cè)背景
????????‘InitialVariance‘?(30/255)^2);???%?初始標(biāo)準(zhǔn)差為?30/255
%?創(chuàng)建系統(tǒng)對(duì)象,用于檢測(cè)出包含汽車運(yùn)動(dòng)的圖像塊
hblob?=?vision.BlobAnalysis(?...
????????????????????‘CentroidOutputPort‘?false?...
????????????????????‘AreaOutputPort‘?true?...
????????????????????‘BoundingBoxOutputPort‘?true?...
????????????????????‘OutputDataType‘?‘single‘?...
????????????????????‘MinimumBlobArea‘?250?...
????????????????????‘MaximumBlobArea‘?3600?...
????????????????????‘MaximumCount‘?80);
%?創(chuàng)建系統(tǒng)對(duì)象,用于對(duì)檢測(cè)出的運(yùn)動(dòng)車輛進(jìn)行框畫
hshapeins?=?vision.ShapeInserter(?...
????????????‘BorderColor‘?‘Custom‘?...
????????????‘CustomBorderColor‘?[0?255?0]);
%?創(chuàng)建系統(tǒng)對(duì)象,用于標(biāo)注檢測(cè)到車輛的個(gè)數(shù)
htextins?=?vision.TextInserter(?...
????????‘Text‘?‘%4d‘?...
????????‘Location‘??[1?1]?...
????????‘Color‘?[255?255?255]?...
????????‘FontSize‘?12);
%?創(chuàng)建系統(tǒng)對(duì)象,用于顯示結(jié)果
sz?=?get(0‘ScreenSize‘);
pos?=?[20?sz(4)-300?200?200];
hVideoOrig?=?vision.VideoPlayer(‘Name‘?‘Original‘?‘Position‘?pos);
pos(1)?=?pos(1)+220;??%在右側(cè)建立下一個(gè)視窗
hVideoFg?=?vision.VideoPlayer(‘Name‘?‘Foreground‘?‘Position‘?pos);
pos(1)?=?pos(1)+220;
hVideoRes?=?vision.VideoPlayer(‘Name‘?‘Results‘?‘Position‘?pos);
line_row?=?23;?%?定義感興趣區(qū)域(ROI)
%?以下的程序段為對(duì)輸入的視頻圖像進(jìn)行處理
while?~isDone(hvfr)
????image?=?step(hvfr);??????%?讀入視頻的每一幀
????y?=?step(hcsc?image);????%?將彩色圖像轉(zhuǎn)換成灰度圖像
%?采用自動(dòng)白平衡算法去除灰度突變
y?=?y-mean(y(:));
????fg_image?=?step(hfdet?y);?%?檢驗(yàn)背景
????%?采用數(shù)學(xué)形態(tài)學(xué),在前景圖像中檢測(cè)變化的聯(lián)通圖像塊區(qū)域的面積
????[area?bbox]?=?step(hblob?fg_image);
????image_out?=?image;
????image_out(22:23::)?=?255;??%?僅對(duì)經(jīng)過(guò)白線后的車輛進(jìn)行計(jì)數(shù)
????image_out(1:151:30:)?=?0;??%?將背景置為黑色
????Idx?=?bbox(:2)?>?line_row;????%選擇感興趣區(qū)域.
???%?當(dāng)在感興趣區(qū)域中,聯(lián)通圖像塊的比例占整個(gè)變化區(qū)域的40%以上時(shí),便認(rèn)為是車輛
????ratio?=?zeros(length(Idx)1);
????ratio(Idx)?=?single(area(Idx1))./single(bbox(Idx3).*bbox(Idx4));
????ratiob?=?ratio?>?0.4;
????count?=?int32(sum(ratiob));????%?車輛的數(shù)量
????bbox(~ratiob:)?=?int32(-1);
????%?將檢測(cè)出的車輛圈畫出來(lái)
????image_out?=?step(hshapeins?image_out?bbox);
????%?顯示檢測(cè)汽車的數(shù)量
????image_out?=?step(htextins?image_out?count);
????step(hVideoOrig?image);??????????%?原始視頻
????step(hVideoFg???fg_image);???????%?前景
????step(hVideoRes??image_out);??????%?用方框勾畫檢測(cè)出的車輛
end
%關(guān)閉視頻文件
release(hvfr);
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????2913??2012-05-11?17:14??基于視頻的車流量統(tǒng)計(jì)\example6.m
?????文件?????208896??2005-04-04?13:17??基于視頻的車流量統(tǒng)計(jì)\viptraffic.avi
?????文件?????????35??2015-03-17?11:12??基于視頻的車流量統(tǒng)計(jì)\代碼說(shuō)明.txt
?????目錄??????????0??2015-03-17?11:11??基于視頻的車流量統(tǒng)計(jì)
-----------?---------??----------?-----??----
???????????????211844????????????????????4
評(píng)論
共有 條評(píng)論