姜富寬
?
基于MATLAB的身份證號識別
姜富寬1,2
1.天津職業技術師范大學,天津 300222 2.駐馬店技師學院,河南 駐馬店 463000
對身份證進行自動識別與手工錄入相比較,能夠有效提高工作效率。以居民身份證為研究對象,從身份證圖像中提取身份證號碼數字0~9的空間分布特征和結構特征,應用Matlab軟件結合模板匹配法實現對身份證號碼進行快速識別。
Matlab;身份證號; 字符識別
由于我國第二代身份證是彩色的,而且是大小固定的,身份證右下方有18位號碼,字體類型是OCR-B10BT。基于以上這些特點,進行身份證圖像采集、圖像預處理、定位、字符分割、字符識別等過程最后輸出身份證號碼[1]。
身份正號的提取和識別,使用圖像處理的方法進行提取。首先需要做的是,采集獲取高質量的身份證圖像信息,考慮到現在的第二代身份證是彩色的,所以推薦使用彩色的CCD相機采集獲取圖像。將身份證,放置在黑色背景的平板桌邊上面,進行采集,并且光照盡量均勻。這樣方便后續的處理。將采集到的身份證圖像保存至C:UserscarrothsDesktop。命名為1.jpg。
3.1 載入圖像
R=imread('C:UsersadminDesktopmatlab圖片1.jpg');
figure(1);
imshow(R);title('圖像載入');將待識別身份證的原圖顯示出來。
3.2 將彩色圖像轉換為灰度圖并繪制直方圖
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算子進行邊緣檢測和腐蝕操作
I2=edge(I1,'roberts',0.08,'both');
figure(3);imshow(I2);title('roberts算子邊緣檢測');
se=[1;1;1];
I3=imerode(I2,se);
figure(4);imshow(I3);title('圖像腐蝕操作');
3.4 平滑圖像及刪除二值圖像的小對象
se=strel('rectangle',[40,40]);
I4=imclose(I3,se);
figure(5);imshow(I4);title('平滑圖像');
I5=bwareaopen(I4,2000);
figure(6);imshow(I5);title('刪除二值圖像的小對象');[2]平滑圖像及刪除二值圖像最小值后的結果。
[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('行方向區域確定'); figure(7),subplot(1,2,2),imshow(dw),title('定位后的身份證號碼輸出');結果如圖2所示。 圖2 定位后的身份證號碼輸出 [1]王家文,曹宇.MATLAB6.5圖形圖像處理[M].北京:國防工業出版社,2004. [2]張稷,基于圖像處理的字符識別系統研究[D].保定:河北農業大學,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