⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainunit.~pas

📁 用Delphi写的车牌字符各种特征提取实验系统
💻 ~PAS
📖 第 1 页 / 共 3 页
字号:
        begin
          bitp.Canvas.Pixels[x1,y1]:=ClassNum;
          inc(m);STX[m]:=x1;STY[m]:=y1;
        end;
        if MAXST<m then MaxST:=m;
      end;//end while
      if MaxNumber<MaxST then
      begin
        MaxColor:=ClassNum;
        MaxNumber:=MaxST;
      end;
    end;//end for x
  end;//end for y
 for y:=0 to bitp.Height-1 do
  begin
    for x:=0 to bitp.Width-1 do
    begin
      if bitp.Canvas.Pixels[x,y]=MaxColor then
        bitp.Canvas.Pixels[x,y]:=Clblack
      else bitp.Canvas.Pixels[x,y]:=clwhite;
    end;
  end;
  Img2.Picture.Bitmap.Assign(bitp);
  bitp.Free;
end;
function TTextForm.Thin(Bitmap: TBitmap): Boolean;
var
   bmp: TBitmap;
   X, Y: integer;
   O, T, C, B: pRGBArray;
   nb: array[1..3, 1..3] of integer;
   c1, c2, c3, c4: boolean;
   OB1,NB1,ncount: integer;
begin
   bmp := TBitmap.Create;
   bmp.PixelFormat:=pf24bit;
   // Create bmp
   OB1:=0;NB1:=1;
   while OB1<>NB1 do begin
   NB1:=0;OB1:=0;
   bmp.Assign(bitmap);
   //  获取bitmap 赋给bmp
   for Y := 1 to bmp.Height - 2 do
   begin
      O := bmp.ScanLine[Y];
      T := bitmap.ScanLine[Y - 1];
      C := bitmap.ScanLine[Y];
      B := bitmap.ScanLine[Y + 1];
      for X := 1 to bmp.Width - 2 do
      begin   ;
         if O[x].rgbtBlue=255 then begin continue;end;
         inc(OB1);
         c1 := false;
         c2 := false;
         c3 := false;
         c4 := false;
         // 设立四个条件的初始值
         nb[1, 1] := T[X - 1].rgbtRed div 255;
         nb[1, 2] := T[X].rgbtRed div 255;
         nb[1, 3] := T[X + 1].rgbtRed div 255;
         nb[2, 1] := C[X - 1].rgbtRed div 255;
         nb[2, 2] := C[X].rgbtRed div 255;
         nb[2, 3] := C[X + 1].rgbtRed div 255;
         nb[3, 1] := B[X - 1].rgbtRed div 255;
         nb[3, 2] := B[X].rgbtRed div 255;
         nb[3, 3] := B[X + 1].rgbtRed div 255;
         //将[x,y]周围的八个象素点和它自己0-1化
         nCount := nb[1, 1] + nb[1, 2] + nb[1, 3]
            + nb[2, 1] + nb[2, 3]
            + nb[3, 1] + nb[3, 2] + nb[3, 3];
         // 获得ncount的值
         if (ncount >= 2) and (ncount <= 6) then
            c1 := True;
         //condition1
         ncount := 0;
         if (nb[1, 1] = 0) and (nb[1, 2] = 1) then
            inc(ncount);
         if (nb[1, 2] = 0) and (nb[1, 3] = 1) then
            inc(ncount);
         if (nb[1, 3] = 0) and (nb[2, 3] = 1) then
            inc(ncount);
         if (nb[2, 3] = 0) and (nb[3, 3] = 1) then
            inc(ncount);
         if (nb[3, 3] = 0) and (nb[3, 2] = 1) then
            inc(ncount);
         if (nb[3, 2] = 0) and (nb[3, 1] = 1) then
            inc(ncount);
         if (nb[3, 1] = 0) and (nb[2, 1] = 1) then
            inc(ncount);
         if (nb[2, 1] = 0) and (nb[1, 1] = 1) then
            inc(ncount);
         if ncount = 1 then
            c2 := true;
         //condition2
         if (nb[1, 2] * nb[3, 2] * nb[2, 3] = 0) then
            c3 := true;
         // condition3
         if (nb[2, 1] * nb[2, 3] * nb[3, 2] = 0) then
            c4 := true;
         //condition4
         if (c1 and c2 and c3 and c4) then
         begin
            O[X].rgbtRed := 255;
            O[X].rgbtGreen := 255;
            O[X].rgbtBlue := 255;
            //设置O[X]为白色
            
         end else
         begin
            O[X].rgbtRed := 0;
            O[X].rgbtGreen := 0;
            O[X].rgbtBlue := 0;
            inc(NB1);
         end;
      end;
   end;
   bitmap.Assign(bmp);
  end;
   bmp.Free;
   //释放bmp
   Result := True;
   // 返回值为boolean,True表示细化成功
end;
procedure TTextForm.SubThinFrame(bmp:TBitMap;Ord:XOrder;XFlag:boolean);
var //具体的细化子程序
  bitp,Bitp2:TBitmap;
  OldPix,NewPix,x,y:integer;
  N:array[0..8] of integer;
  p:array[1..3] of pbytearray;
  q:pbytearray;
begin
   bitp:=TBitmap.Create;
   bitp2:=TBitmap.Create;
   bitp.Assign(bmp);
   bitp2.Assign(bmp);
   for y:=1 to bitp.Height-2 do
   begin
    p[1]:=bitp.ScanLine[y-1];    //  3   2   1
    p[2]:=bitp.ScanLine[y];      //  4   p   0
    p[3]:=bitp.ScanLine[y+1];     //  5   6   7
    q:=bitp2.ScanLine[y];
    for x:=2 to bitp2.Width-2 do
    begin
      if p[2][3*x]=255 then continue;
      N[0]:=1-p[2][3*(x+1)] div 255;
      N[1]:=1-p[1][3*(x+1)] div 255;
      N[2]:=1-p[1][3*x]     div 255;
      N[3]:=1-p[1][3*(x-1)] div 255;
      N[4]:=1-p[2][3*(x-1)] div 255;
      N[5]:=1-p[3][3*(x-1)] div 255;
      N[6]:=1-p[3][3*x]     div 255;
      N[7]:=1-p[3][3*(x+1)] div 255;
        if Ord[9]=7 then
       NewPix:=(N[Ord[1]])and((N[Ord[2]])or(N[Ord[3]])or(N[Ord[4]])or(N[Ord[5]]))and(N[Ord[6]]or(not N[Ord[7]]))and( N[Ord[8]]or not N[Ord[9]])
       else
       NewPix:=(N[Ord[1]])and((N[Ord[2]])or(N[Ord[3]])or(N[Ord[4]])or(N[Ord[5]]))and(N[Ord[6]]or(not N[Ord[7]]))and(not N[Ord[8]]or N[Ord[9]]);
      if NewPix=1 then
      begin
        q[3*x]:=255;q[3*x+2]:=255;q[3*x+1]:=255;
        XFlag:=False;
      end;//end IF
    end;//END FOR X
  end;//END FOR Y
  bmp.Assign(bitp2);
  bitp.Free;
  bitp2.Free;
end;
procedure TTextForm.ThinFrame(bmp,bmp2:TBitMap);
var  //细化程序
  OldPix,NewPix,x,y:integer;
  XN:Xorder;
  XChangeFlag:boolean;
  bitp,bitp2:TBitmap;
  p,q:pbytearray;
begin
  XCHangeFlag:=False;
    //0 1 2 6 7 2 3 5 6
    //4 2 3 5 6 6 7 1 2
    //6 0 4 5 7 0 1 3 4
    //2 0 1 3 4 4 5 0 7
  while XChangeFlag=False do
  begin
  XChangeFlag:=True;
  XN[1]:=4;XN[2]:=2;XN[3]:=3;XN[4]:=5;XN[5]:=6;XN[6]:=6;XN[7]:=7;XN[8]:=1;XN[9]:=2;XN[10]:=0;
  SubThinFrame(bmp,XN,XChangeFlag);
  XN[1]:=0;XN[2]:=1;XN[3]:=2;XN[4]:=6;XN[5]:=7;XN[6]:=2;XN[7]:=3;XN[8]:=5;XN[9]:=6;XN[10]:=4;
  SubThinFrame(bmp,XN,XChangeFlag);
  end;//END While
  XCHangeFlag:=False;
  while XChangeFlag=False do
  begin
    XChangeFlag:=True;
    XN[1]:=2;XN[2]:=0;XN[3]:=1;XN[4]:=3;XN[5]:=4;XN[6]:=4;XN[7]:=5;XN[8]:=0;XN[9]:=7;XN[10]:=6;
    SubThinFrame(bmp2,XN,XChangeFlag);
    XN[1]:=6;XN[2]:=0;XN[3]:=4;XN[4]:=5;XN[5]:=7;XN[6]:=0;XN[7]:=1;XN[8]:=3;XN[9]:=4;XN[10]:=2;
    SubThinFrame(bmp2,XN,XChangeFlag); //具体的细化子程序
  end;//END While
  bitp:=TBitmap.Create;
  Bitp2:=TBitmap.Create;
  bitp.Assign(bmp);
  bitp2.Assign(bmp2);
  for y:=0 to bitp.Height-1 do
  begin
    p:=bitp.ScanLine[y];
    q:=bitp2.ScanLine[y];
    for x:=0 to bitp.Height-1 do
    begin
      if q[3*x]=255 then continue;
      p[3*x]:=0;p[3*x+1]:=0;p[3*x+2]:=0;
    end;
  end;
  bmp.Assign(bitp);
  bitp.Free;
  bitp2.Free;
end;
procedure TTextForm.GetBone(Img1,Img2:TImage);
var
dis,Mindis,minnum,num,JSdistance,x,y,ds,i,j,x0,y0,k:Integer;
  bitp1,bitp2:TBitmap;
  find:boolean;
  JSDis:array[1..34,1..34] of integer;
  Found:boolean;
  m:integer;
begin
 // Edit1.Text:=IntToStr(img1.Picture.Bitmap.Height)+'  '+IntToStr(img1.Picture.Bitmap.Width);
  bitp1:=TBitmap.Create;
  bitp2:=TBitmap.Create;
  bitp1.Assign(Img1.Picture.Bitmap);
  bitp2.Assign(Img1.Picture.Bitmap);
  Found:=False;
  k:=240; m:=0;
  for i:=1 to 32 do
    for j:=1 to 32 do JSDis[i,j]:=-1;
  While Found=False do
  begin
    Found:=True;
    for y:=0 to bitp1.Height-1 do
    begin
      for x:=0 to bitp1.Width-1 do
      begin
        if bitp1.Canvas.Pixels[x,y]=clwhite then continue;
        if JSDis[x+1,y+1]<>-1 then continue;
        Mindis:=1000000;
        for i:=-1 to 1 do
        begin
          for j:=-1 to 1 do
          begin
             x0:=x+i;y0:=y+j;
             if (i=0)and(j=0)then continue;
          //   if ((x0<0)or(y0<0)or(x0>=32)or(y0>=32))then continue;
             if bitp1.Canvas.Pixels[x0,y0]=clblack then continue;
             if bitp1.Canvas.Pixels[x0,y0]=RGB(k,k,k) then continue;
             if (JSDis[x0+1,y0+1]=-1) then
               dis:=abs(x-x0)+abs(y-y0)
             else dis:=abs(x-x0)+abs(y-y0)+JSDis[x0+1,y0+1];
             if dis<Mindis then Mindis:=dis;
          end;//end for j
        end;//end for i
        if Mindis<1000000 then
        begin
          inc(m);
         JSDis[x+1,y+1]:=Mindis;
         bitp1.Canvas.Pixels[x,y]:=RGB(k,k,k);
         Found:=False;
        end;
      end;//end for x
    end;//end for y
    k:=k-10;
  end;//end while
  //img2.Picture.Bitmap.Assign(bitp1);
  for y:=1 to 32 do
  begin
    for x:=1 to 32 do
    begin
      if jsdis[x,y]=-1 then continue;
      minnum:=0;num:=0;
      for i:=-1 to 1 do
        for j:=-1 to 1 do
        begin
          if (i=0)and(j=0)then continue;
          x0:=x+i;y0:=y+j;
          if (x0<1)or(x0>64)or(y0<1)or(y0>64)then continue;
          inc(num);
          if jsdis[x,y]>=jsdis[x0,y0] then inc(minnum);
        end;
        if minnum=num then
          bitp2.Canvas.Pixels[x-1,y-1]:=clblack
        else bitp2.Canvas.Pixels[x-1,y-1]:=clwhite;
    end;
  end;
  Img2.picture.bitmap.Assign(bitp2);
 bitp1.Free;
 bitp2.Free;
end;
procedure TTextForm.ImageTeZheng(Img:TImage);
var
  BW,k,m,x,y,i,j,JumpTemp:integer;
  p:pbytearray;
  bmp:TBitmap;
  JumpEnd:boolean;
  LineJumpEnd:array[1..34] of boolean;
begin
  bmp:=TBitmap.Create;
  bmp.Assign(Img.Picture.Bitmap);
  k:=0;m:=0;
  for x:=0 to bmp.Width-1 do begin
     LineSum[x+1]:=0;//列统计值归零
     LineJumpEnd[x+1]:=False;
     LineColorJmpE[x+1]:=0;
  end;
  for x:=1 to 4 do begin
     FourColorCenterx[x]:=0;
     FourColorCentery[x]:=0;
  end;
  BW:=0;
  for y:=0 to bmp.Height-1 do
  begin
    p:=bmp.ScanLine[y];
    JumpTemp:=0;    //最后跳跃归零
    RowSum[y+1]:=0; //行统计值归零
    JumpEnd:=False;
    for x:=0 to bmp.Width-1 do
    begin
      if p[3*x]=255 then continue;
      inc(BW); BlackWhiteX[BW]:=x;BlackWhiteY[BW]:=y;
      i:=(y div 16);j:=(x div 16); ////////
      FourColorCenterx[i*2+j+1]:=FourColorCenterx[i*2+j+1]+x;     // 统计四个中心点数
      FourColorCentery[i*2+j+1]:=FourColorCentery[i*2+j+1]+y;     // 统计四个中心点数
      RowSum[y+1]:=RowSum[y+1]+1;;LineSum[x+1]:=LineSum[x+1]+1;//统计行列颜色值
      if JumpEnd=False then//////////////////////////////////
      begin                                                //
        RowColorJmpS[y+1]:=x; JumpEnd:=True;               //行起终点统计
      end;                                                 //
      JumpTemp:=x;///////////////////////////////////////////
      if LineJumpEnd[x+1]=False then ////////////////////////
      begin                                                //
         LineColorJmpS[x+1]:=y;LineJumpEnd[x+1]:=True;     //列起终点统计
      end;                                                 //
      if LineColorJmpE[x+1]<y then LineColorJmpE[x+1]:=y;////
    end;//end for x
    RowColorJmpE[y+1]:=JumpTemp;
  end;//end for y
  for i:=1 to 4 do
  begin
    FourColorCenterx[i]:=FourColorCenterx[i]/256;
    FourColorCentery[i]:=FourColorCentery[i]/256;
  end;
  TeZhengBiaoZhun(LineSum,32);
  TeZhengBiaoZhun(RowSum,32);
  TeZhengBiaoZhun(RowColorJmpS,32);
  TeZhengBiaoZhun(RowColorJmpE,32);
  TeZhengBiaoZhun(LineColorJmpS,32);
  TeZhengBiaoZhun(LineColorJmpE,32);
  TeZhengBiaoZhun(FourColorCenterx,4);
  TeZhengBiaoZhun(FourColorCentery,4);
  BlackWhite:=BW;
  bmp.Free;
  //NetForm.ListBox1.Items.Add(IntTOStr(123));
end;
procedure  TTextForm.ViewData;
var
  i:integer;
  Data:array[1..201] of double;
  Label Loop;
begin
  TextViewForm.EditLTX.Text:=floatToStr(FourColorCenterx[1]);
  TextViewForm.EditRTX.Text:=floatToStr(FourColorCenterx[2]);
  TextViewForm.EditLBX.Text:=floatToStr(FourColorCenterx[3]);
  TextViewForm.EditRBX.Text:=floatToStr(FourColorCenterx[4]);
  TextViewForm.EditLTY.Text:=floatToStr(FourColorCentery[1]);
  TextViewForm.EditRTY.Text:=floatToStr(FourColorCentery[2]);
  TextViewForm.EditLBY.Text:=floatToStr(FourColorCentery[3]);
  TextViewForm.EditRBY.Text:=floatToStr(FourColorCentery[4]);
  for i:=1 to 7 do
  begin
   TextViewForm.StringGridLine.Cells[0,i-1]:=floatTOstr(LineColorJmpS[i]);
   TextViewForm.StringGridLine.Cells[1,i-1]:=floatTOstr(LineColorJmpE[i]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -