姜富寬
?
基于MATLAB的身份證號(hào)識(shí)別
姜富寬1,2
1.天津職業(yè)技術(shù)師范大學(xué),天津 300222 2.駐馬店技師學(xué)院,河南 駐馬店 463000
對(duì)身份證進(jìn)行自動(dòng)識(shí)別與手工錄入相比較,能夠有效提高工作效率。以居民身份證為研究對(duì)象,從身份證圖像中提取身份證號(hào)碼數(shù)字0~9的空間分布特征和結(jié)構(gòu)特征,應(yīng)用Matlab軟件結(jié)合模板匹配法實(shí)現(xiàn)對(duì)身份證號(hào)碼進(jìn)行快速識(shí)別。
Matlab;身份證號(hào); 字符識(shí)別
由于我國第二代身份證是彩色的,而且是大小固定的,身份證右下方有18位號(hào)碼,字體類型是OCR-B10BT?;谝陨线@些特點(diǎn),進(jìn)行身份證圖像采集、圖像預(yù)處理、定位、字符分割、字符識(shí)別等過程最后輸出身份證號(hào)碼[1]。
身份正號(hào)的提取和識(shí)別,使用圖像處理的方法進(jìn)行提取。首先需要做的是,采集獲取高質(zhì)量的身份證圖像信息,考慮到現(xiàn)在的第二代身份證是彩色的,所以推薦使用彩色的CCD相機(jī)采集獲取圖像。將身份證,放置在黑色背景的平板桌邊上面,進(jìn)行采集,并且光照盡量均勻。這樣方便后續(xù)的處理。將采集到的身份證圖像保存至C:UserscarrothsDesktop。命名為1.jpg。
3.1 載入圖像
R=imread('C:UsersadminDesktopmatlab圖片1.jpg');
figure(1);
imshow(R);title('圖像載入');將待識(shí)別身份證的原圖顯示出來。
3.2 將彩色圖像轉(zhuǎn)換為灰度圖并繪制直方圖
I1=rgb2gray(R);
figure(2);
subplot(1,2,1);imshow(I1);title('灰度圖');
figure(2);
subplot(1,2,2);imhist(I1);title('灰度直方圖');灰度圖與繪制的灰度直方圖如圖1所示。
圖1 灰度圖與繪制的灰度直方圖。
3.3 用roberts算子進(jìn)行邊緣檢測(cè)和腐蝕操作
I2=edge(I1,'roberts',0.08,'both');
figure(3);imshow(I2);title('roberts算子邊緣檢測(cè)');
se=[1;1;1];
I3=imerode(I2,se);
figure(4);imshow(I3);title('圖像腐蝕操作');
3.4 平滑圖像及刪除二值圖像的小對(duì)象
se=strel('rectangle',[40,40]);
I4=imclose(I3,se);
figure(5);imshow(I4);title('平滑圖像');
I5=bwareaopen(I4,2000);
figure(6);imshow(I5);title('刪除二值圖像的小對(duì)象');[2]平滑圖像及刪除二值圖像最小值后的結(jié)果。
[y,x,z]=size(I5);
myI=double(I5);
tic
Blue_y=zeros(y,1);
for i=1:y
for j=1:x
if(myI(i,j,1)==1)
Blue_y(i,1)=Blue_y(i,1)+1;
end
end
end
[temp MaxY]=max(Blue_y);
PY1=MaxY;
while ((Blue_y(PY1,1)>=5)&&(PY1>1))
PY1=PY1-1;
end
PY2=MaxY;
while (Blue_y(PY2,1)>=5)&&(PY2 PY2=PY2+1; end IY=R(PY1:PY2,:,:); Blue_x=zeros(1,x); for j=1:x for i=PY1:PY2 if(myI(i,j,1)==1) Blue_x(1,j)=Blue_x(1,j)+1; end end end PX1=1; while (Blue_x(1,PX1)<3)&&(PX1 PX1=PX1+1; end PX2=x; while (Blue_x(1,PX2)<3)&&(PX2>PX1) PX2=PX2-1; end PX1=PX1-2; PX2=PX2+2; dw=R(PY1:PY2,PX1:PX2,:); t=toc; figure(7),subplot(1,2,1),imshow(IY),title('行方向區(qū)域確定'); figure(7),subplot(1,2,2),imshow(dw),title('定位后的身份證號(hào)碼輸出');結(jié)果如圖2所示。 圖2 定位后的身份證號(hào)碼輸出 [1]王家文,曹宇.MATLAB6.5圖形圖像處理[M].北京:國防工業(yè)出版社,2004. [2]張稷,基于圖像處理的字符識(shí)別系統(tǒng)研究[D].保定:河北農(nóng)業(yè)大學(xué),2007. Identification number identification based on MATLAB Jiang Fukuan1、2 1.Tianjin Vocational Technical Normal University,Tianjin 300222 2.Technician College Zhumadian,Zhumadian 463000 The automatic identification card and manual entry in comparison,can effectively improve work efficiency. In this paper,the research object identity card, extract from the ID card number digits 0 to 9 image space distribution and structural features,applications achieve identification number for quick identification Matlab software combines template matching. Matlab;ID number;character recognition TP391.41 A 1009-6434(2016)09-0149-02