資源簡介

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