您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 模板/表格 > 用Matlab实现身份证号码快速识别
2009.91,。,,、、、、、,。,。,0~9,,Matlab。21。,8.6cm,5.4cm,,366,233,。,0~9,。2。,。:P,Pr、g、b,0.299*r+0.587*g+0.114*b0.5,,。,10、。:0,。3。:,。,。,。2.1,1,0。,x1x2,x1;x2。、,x3x4;x5x6。、,x7x8;x9x10Matlab:。0~910,;;,Matlab。:;;Matlab;;;123722009.9GRAPHICSPROGRAM。;。10:x=(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)T。,。2.2“1”、“2”、“4”、“5”、“7”,“0”、“3”、“6”、“8”、“9”。,,“0”“6”“9”;“3”;“8”。,“1”、“2”、“4”、“5”、“7”。Matlabbweuler。,,48。1。8,,E(10)。2.3digital(10,10)E(10)。(18),,,obj(18,10)objE(18)。x=(x1,x2,,..,x10)T,y=(y1,y2,...,y10)T,:,10,:,。3Matlab6.5(releaseR13),WindowsXP。4,:350426198107282635。,。:clear%RGB=im2double(imread('Digital.jpg'));[height,width,n]=size(RGB);BW=zeros(height,width);fori=1:heightforj=1:widthr=RGB(i,j,1);g=RGB(i,j,2);b=RGB(i,j,3);if(0.299*r+0.587*g+0.114*b0.5)BW(i,j)=1;elseBW(i,j)=0;endendend%width=width/10;N=zeros(10,5);digital=zeros(10,10);E=zeros(1,10);fork=0:9A=BW(:,1+k*width:width+k*width);14732009.9B=[];fori=1:widtha=A(:,i);ifsum(a)~=0B=[Ba];endendSample=[];forj=1:heightb=B(j,:);ifsum(b)~=0Sample=[Sample;b];endendE(k+1)=bweuler(Sample,8);%[m,n]=size(Sample);fori=1:mforj=1:nifSample(i,j)==1N(k+1,1)=N(k+1,1)+1;%digital(k+1,1)=digital(k+1,1)+i;%digital(k+1,2)=digital(k+1,2)+j;%ifim/2N(k+1,2)=N(k+1,2)+1;%digital(k+1,3)=digital(k+1,3)+i;%digital(k+1,4)=digital(k+1,4)+j;%endifim/2N(k+1,3)=N(k+1,3)+1;%digital(k+1,5)=digital(k+1,5)+i;%digital(k+1,6)=digital(k+1,6)+j;%endifjn/2N(k+1,4)=N(k+1,4)+1;%digital(k+1,7)=digital(k+1,7)+i;%digital(k+1,8)=digital(k+1,8)+j;%endifjn/2N(k+1,5)=N(k+1,5)+1;%digital(k+1,9)=digital(k+1,9)+i;%digital(k+1,10)=digital(k+1,10)+j;%endendendenddigital(k+1,1)=digital(k+1,1)/N(k+1,1);%digital(k+1,2)=digital(k+1,2)/N(k+1,1);%digital(k+1,3)=digital(k+1,3)/N(k+1,2);%digital(k+1,4)=digital(k+1,4)/N(k+1,2);%digital(k+1,5)=digital(k+1,5)/N(k+1,3);%digital(k+1,6)=digital(k+1,6)/N(k+1,3);%digital(k+1,7)=digital(k+1,7)/N(k+1,4);%digital(k+1,8)=digital(k+1,8)/N(k+1,4);%digital(k+1,9)=digital(k+1,9)/N(k+1,5);%digital(k+1,10)=digital(k+1,10)/N(k+1,5);%end%I=im2double(imread('IDCard01.jpg'));figure,imshow(I);x1=127;x2=127+11;y1=190;y2=210;IDRGB=I(y1:y2,x1:x2,:,:,:);fori=1:17x1=127+11*i;x2=127+11*(i+1);C=I(y1:y2,x1:x2,:,:,:);IDRGB=[IDRGBC];end[IDheight,IDwidth,k]=size(IDRGB);IDBW=zeros(IDheight,IDwidth);fori=1:IDheightforj=1:IDwidthr=IDRGB(i,j,1);g=IDRGB(i,j,2);b=IDRGB(i,j,3);if(0.299*r+0.587*g+0.114*b0.5)IDBW(i,j)=1;elseIDBW(i,j)=0;endend742009.9GRAPHICSPROGRAMend%IDwidth=IDwidth/18;obj=zeros(18,10);objN=zeros(18,5);objE=zeros(1,18);fork=1:18IDA=IDBW(:,1+(k-1)*IDwidth:k*IDwidth);IDB=[];fori=1:IDwidthIDa=IDA(:,i);ifsum(IDa)~=0IDB=[IDBIDa];endendObject=[];forj=1:IDheightIDb=IDB(j,:);ifsum(IDb)~=0Object=[Object;IDb];endendobjE(k)=bweuler(Object,8);%[m,n]=size(Object);fori=1:mforj=1:nifObject(i,j)==1objN(k,1)=objN(k,1)+1;obj(k,1)=obj(k,1)+i;obj(k,2)=obj(k,2)+j;ifim/2objN(k,2)=objN(k,2)+1;obj(k,3)=obj(k,3)+i;obj(k,4)=obj(k,4)+j;endifim/2objN(k,3)=objN(k,3)+1;obj(k,5)=obj(k,5)+i;obj(k,6)=obj(k,6)+j;endifjn/2objN(k,4)=objN(k,4)+1;obj(k,7)=obj(k,7)+i;obj(k,8)=obj(k,8)+j;endifjn/2objN(k,5)=objN(k,5)+1;obj(k,9)=obj(k,9)+i;obj(k,10)=obj(k,10)+j;endendendendobj(k,1)=obj(k,1)/objN(k,1);obj(k,2)=obj(k,2)/objN(k,1);obj(k,3)=obj(k,3)/objN(k,2);obj(k,4)=obj(k,4)/objN(k,2);obj(k,5)=obj(k,5)/objN(k,3);obj(k,6)=obj(k,6)/objN(k,3);obj(k,7)=obj(k,7)/objN(k,4);obj(k,8)=obj(k,8)/objN(k,4);obj(k,9)=obj(k,9)/objN(k,5);obj(k,10)=obj(k,10)/objN(k,5);end%String='0123456789';IDCardNO='';fork=1:18R=0.0;j=0;x=obj(k,:);fori=0:9y=digital(i+1,:);r=sum(x.*y)/sqrt(sum(x.*x)*sum(y.*y));%ifrR&objE(k)==E(i+1)%R=r;j=i;endendIDCardNO=strcat(IDCardNO,String(j+1));enddisp(IDCardNO);%、,,,(IDCard01.jpg),、。[1],,..,2004;21(3):65-67.[2],.MATLAB7.0.,2004.[3],..,2006.(:200948)75
本文标题:用Matlab实现身份证号码快速识别
链接地址:https://www.777doc.com/doc-3506986 .html