資源簡介
交通流中機動車輛的輪廓提取與標識 附帶視頻

代碼片段和文件信息
clc;clear?all
mov=mmreader(‘Noname.avi‘);
nframe=get(mov‘NumberOfframes‘);
I=read(mov1);%讀取第一幀
??%批量讀圖并處理
??
for?k?=?1:3:nframe-180
Im{k}?=read(movk);
Imgray{k}=rgb2gray(Im{k});
gray{k}=Imgray{k};
[Imgray{k}t]=edge(Imgray{k}‘canny‘);%canny邊緣檢測
???i?=?k?;
??if?(i==1);
???sub{1}=Imgray{1i};%把元素從cell中提取出來
???n=i;
???else
????sub{i}=Imgray{1i}-Imgray{1n};%幀差法提取輪廓
????n=i;
????H?=?fspecial(‘unsharp‘);
????sub{i}=imfilter(sub{i}H‘replicate‘);
???sub{i}=bwperim(sub{i}4);
???%figure?imshow(sub{i}?)
???se90=strel(‘line‘390);%增強
???se0=strel(‘line‘30);
???sub{i}=imdilate(sub{i}[se90?se0]);
???%figure?imshow(sub{i}?)
???sub{i}=imfill(sub{i}‘holes‘);%填充
???seD=strel(‘rectangle‘[33]);
????sub{i}=imerode(sub{i}seD);
????sub{i}=imopen(sub{i}seD);
????sub{i}=imclose(sub{i}seD);
????%?figure?imshow(sub{i}?)
?????
?????
?????[Lnum]?=?bwlabel(sub{i}8)?;%L==sub{i}是與圖像相同大小的矩陣,num是圖像中連通區域的個數;
?????stats?=?regionprops(L‘boundingbox‘‘filledArea‘‘centroid‘);
?????taggedCars(?::?)=gray{k};
?????if?any(?L(:)?)
??????for?i=1:length(stats)
???????????if?((stats(i).FilledArea?>?350?&&stats(i).FilledArea<6000));
??????????????centroid=stats(i).Centroid;
???????????????box?=stats(i).BoundingBox;
???????????????area=stats(i).FilledArea;
???????????????left=round(box(1));
????????????????top=round(box(2));
????????????????right=round(box(1)+box(3)-1);
????????????????bottom=round(box(2)+box(4)-1);
????????????????if(?abs(top?-?bottom)/abs(right?-?left)?>?3?||?abs(right?-?left)/abs(top?-?bottom)?>?3?)
???????????????????continue;
????????????????end?
????????????????taggedCars(topleft:right)=255;????????????????????????????????????%畫矩形框%
????????????????taggedCars(bottomleft:right)=255;
????????????????taggedCars(top:bottomleft)=255;
????????????????taggedCars(top:bottomright)=255;
???????????end
????????end
?????end
??????%figureimshow(taggedCars);
???
????
??end
end
frameRate=get(mov‘frameRate‘);
implay(taggedCarsframeRate);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2030??2011-04-30?01:45??cheliangjiance\growcut.m
?????文件????1977716??2011-04-28?09:30??cheliangjiance\Noname.avi
?????目錄??????????0??2011-04-30?14:27??cheliangjiance
-----------?---------??----------?-----??----
??????????????1979746????????????????????3
- 上一篇:GA算法求最大值
- 下一篇:信號調制識別論文含matlab程序
評論
共有 條評論