資源描述:
《車牌識別_MATLAB代碼》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、....clear;closeall;%Step1獲取圖像裝入待處理彩色圖像并顯示原始圖像Scolor=imread('C:UserslenovoDesktop程序chepail2.jpg');%將彩色圖像轉(zhuǎn)換為黑白并顯示Sgray=rgb2gray(Scolor);figure,imshow(Scolor),title('原始彩色圖像');figure,imshow(Sgray),title('原始灰度圖像');%bw3=medfilt2(Sgray,[55]);%figure,imshow(bw3);title('圖像中值濾波');%bw4=
2、imfilter(bw3,fspecial('laplacian'));%figure,imshow(bw4);title('圖像中值濾波');%Egray=imsubtract(bw3,bw4);%figure,imshow(Egray);%Step2圖像預(yù)處理對Sgray原始黑白圖像進(jìn)行開操作得到圖像背景s=strel('disk',10);Bgray=imopen(Sgray,s);figure,imshow(Bgray);title('背景圖像');%用原始圖像與背景圖像作減法,增強(qiáng)圖像Egray=imsubtract(Sgray,Bgray);fi
3、gure,imshow(Egray);title('增強(qiáng)黑白圖像');%Step3取得最佳閾值,將圖像二值化%fmax1=double(max(max(Egray)));%fmin1=double(min(min(Egray)));%level=(fmax1-(fmax1-fmin1)/3)/255;%level=graythresh(Egray);%%bw3=filter2(fspecial('average',3),Egray);%%Egray=medfilt2(Egray,[33]);%figure,imshow(Egray);title('圖像中值濾
4、波');bw2=im2bw(Egray,level);figure,imshow(bw2);title('圖像二值化');%bw4=im2bw(bw3,level);%figure,imshow(bw4);title('圖像二值化');專注專業(yè)....%Step4對得到二值圖像作開閉操作進(jìn)行濾波grd=edge(bw2,'canny');figure,imshow(grd);title('圖像邊緣提取');%bg1=imclose(grd,strel('rectangle',[5,19]));%figure,imshow(bg1);title('圖像閉運(yùn)算[
5、5,19]');bg2=bwareaopen(bg1,2000);figure,imshow(bg2);title('小對象');bg2=imclose(bg2,strel('rectangle',[20,50]));%bg3=imclose(bg2,strel('rectangle',[20,50]));bg2=imopen(bg2,strel('rectangle',[5,20]));figure,imshow(bg2);title('圖像開運(yùn)算[5,19]');bg2=imopen(bg2,strel('rectangle',[19,1]));figu
6、re,imshow(bg2);title('圖像開運(yùn)算[19,1]');%Step5對二值圖像進(jìn)行區(qū)域提取,并計(jì)算區(qū)域特征參數(shù)。進(jìn)行區(qū)域特征參數(shù)比較,提取車牌區(qū)域[L,num]=bwlabel(bg2,8);Feastats=regionprops(L,'basic');Area=[Feastats.Area];BoundingBox=[Feastats.BoundingBox];%[xywidthheight]RGB=label2rgb(L,'spring','k','shuffle');figure,imshow(RGB);title('圖像彩色標(biāo)記')
7、;lx=0;%Getok=zeros(1,5);forl=1:numwidth=BoundingBox((l-1)*4+3);hight=BoundingBox((l-1)*4+4);if(width>250&&width<500&&hight>70&&hight<150)lx=lx+1;Getok(lx)=l;endendfork=1:lxl=Getok(k);startcol=BoundingBox((l-1)*4+1);%開始列startrow=BoundingBox((l-1)*4+2);%開始行width=BoundingBox((l-1)*4+3
8、);%車牌寬專注專業(yè)....hight=Boundi