____________________________________________________________tools;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,, ExtCtrls, StdCtrls, ComCtrls, Grids, md5Hash, DB, mySQLDbTables,, DBCtrls, mySQLDirectQuery,MySQLBatch;Perimeter(SG:TStringGrid; col, row:integer):bool;Centroid(SG:TStringGrid; col, row:integer):bool;CheckVoidSG(SG:TStringGrid):bool;cleanTable(SG:TStringGrid);Extrema(SG:TStringGrid; col, row:integer):bool;Area(col, row, max_x, max_y, min_x, min_y:integer):bool;GetAllBMPFiles( Path: string; Lb: TListBox );getValCentroid(SG:TStringGrid):string;getValP(SG:TStringGrid):string;getValS(SG:TStringGrid):string;getValHash(SG:TStringGrid):string;getValVertex(SG:TStringGrid):string;getValExtrems(SG:TStringGrid):string;MaxP(m:array of real):integer;LoadBitmap(path:String; img:TImage);ImgToBin(M:TStringGrid; img:TImage);StringToHex(S: String): String;Vertex(SG:TStringGrid; col, row:integer):bool;SmoothResize(Src, Dst: TBitmap);xy_max_and_min(SG:TStringGrid; var max_x, max_y, min_x, min_y:integer);= array[Word] of TRGBTriple;= ^TRGBArray;Perimeter(SG:TStringGrid; col, row:integer):bool;c1,c2,c3,c4,c5:string;:=False;(col <> 0) and (row <> 0) and (col <> SG.ColCount - 1) and (row <> SG.RowCount - 1) then:= SG.Cells[col, row - 1];:= SG.Cells[col + 1, row];:= SG.Cells[col, row + 1];:= SG.Cells[col - 1, row];:= SG.Cells[col, row];((c1 = '1') or (c2 = '1') or (c3 = '1') or (c4 = '1')) and (c5 = '0') then:= True;SG.Cells[col, row] = '0' then:= True;;;xy_max_and_min(SG:TStringGrid; var max_x, max_y, min_x, min_y:integer);i,j:integer;_x := 65;_y := 65;_x := -1;_y := -1;j:=0 to SG.RowCount - 1 doi:=0 to SG.ColCount - 1 doExtrema(SG, j, i) = True theni > max_x then_x:=i;i < min_x then_x:=i;j > max_y then_y:=j;j < min_y then_y:=j;;;Area(col, row, max_x, max_y, min_x, min_y:integer):bool;:= False;((col >= min_x) and (col <= max_x)) and ((row >= min_y) and (row <= max_y)) then:= True;;;Vertex(SG:TStringGrid; col, row:integer):bool; //определение вершины образаc1,c2,c3,c4,c5,c6,c7,c8,c9:integer;:=False;Perimeter(SG, col, row) = True then(col <> 0) and (row <> 0) and (col <> SG.ColCount - 1) and (row <> SG.RowCount - 1) then:= strtoint(SG.Cells[col, row]);:= strtoint(SG.Cells[col, row - 1]);:= strtoint(SG.Cells[col + 1, row - 1]);:= strtoint(SG.Cells[col + 1, row]);:= strtoint(SG.Cells[col + 1, row + 1]);:= strtoint(SG.Cells[col, row + 1]);:= strtoint(SG.Cells[col - 1, row + 1]);:= strtoint(SG.Cells[col - 1, row]);:= strtoint(SG.Cells[col - 1, row - 1]);c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 = 5 then:=True;((row = 0) and (col = 0)) or ((row = 0) and (col = SG.ColCount - 1)) or ((row = SG.RowCount - 1) and (col = 0)) or ((row = SG.RowCount - 1) and (col = SG.ColCount - 1)) then:=True;:= strtoint(SG.Cells[col, row]);row = 0 then:= strtoint(SG.Cells[col - 1, row]);:= strtoint(SG.Cells[col, row + 1]);:= strtoint(SG.Cells[col + 1, row]);;col = 0 then:= strtoint(SG.Cells[col, row - 1]);:= strtoint(SG.Cells[col, row + 1]);:= strtoint(SG.Cells[col + 1, row]);;row = SG.RowCount - 1 then:= strtoint(SG.Cells[col - 1, row]);:= strtoint(SG.Cells[col + 1, row]);:= strtoint(SG.Cells[col, row -1]);;col = SG.ColCount - 1 then:= strtoint(SG.Cells[col, row - 1]);:= strtoint(SG.Cells[col, row + 1]);:= strtoint(SG.Cells[col - 1, row]);;(c2 = 1) or (c3 = 1) or (c4 = 1) then:= True;;;;Extrema(SG:TStringGrid; col, row:integer):bool;i,k:integer;:= False;Vertex(SG, col, row) = True then(row <> 0) and (col <> 0) and (row <> SG.RowCount-1) and (col <> SG.ColCount - 1) then:= 0;i := 0 to SG.ColCount - 1 do:= k + strtoint(SG.Cells[i, row + 1]);k = SG.ColCount then:= True;:= 0;i := 0 to SG.ColCount - 1 do:= k + strtoint(SG.Cells[i, row - 1]);k = SG.ColCount then:= True;Result = False then:= 0;i := 0 to SG.RowCount - 1 do:= k + strtoint(SG.Cells[col + 1, i]);k = SG.RowCount then:= True;:= 0;i := 0 to SG.RowCount - 1 do:= k + strtoint(SG.Cells[col - 1, i]);k = SG.RowCount then:= True;;:= True;; CheckVoidSG(SG:TStringGrid):bool; //проверка отсутствия значений в таблице
var r,i,j:integer;:=False;:=0;i := 0 to SG.RowCount - 1 doj := 0 to SG.ColCount - 1 doSG.Cells[j,i] <>'' then:= r + 1;r = (SG.ColCount * SG.RowCount) then:= True;;SmoothResize(Src, Dst: TBitmap); //сжатие изображения, y: Integer;, yP: Integer;, yP2: Integer;, SrcLine2: pRGBArray;: Integer;, z2, iz2: Integer;: pRGBArray;: Integer;, w2, w3, w4: Integer;.PixelFormat := pf24Bit;.PixelFormat := pf24Bit;(Src.Width = Dst.Width) and (Src.Height = Dst.Height) then.Assign(Src):= Dst.ScanLine[0];:= Integer(Dst.ScanLine[1]) - Integer(DstLine);:= MulDiv(pred(Src.Width), $10000, Dst.Width);:= MulDiv(pred(Src.Height), $10000, Dst.Height);:= 0;y := 0 to pred(Dst.Height) do:= 0;:= Src.ScanLine[yP shr 16];(yP shr 16 < pred(Src.Height)) then:= Src.ScanLine[succ(yP shr 16)]:= Src.ScanLine[yP shr 16];:= succ(yP and $FFFF);:= succ((not yp) and $FFFF);x := 0 to pred(Dst.Width) do:= xP shr 16;:= xP and $FFFF;:= MulDiv(z, iz2, $10000);:= iz2 - w2;:= MulDiv(z, z2, $10000);:= z2 - w4;[x].rgbtRed := (SrcLine1[t3].rgbtRed * w1 +[t3 + 1].rgbtRed * w2 +[t3].rgbtRed * w3 + SrcLine2[t3 + 1].rgbtRed * w4) shr 16;[x].rgbtGreen :=
(SrcLine1[t3].rgbtGreen * w1 + SrcLine1[t3 + 1].rgbtGreen * w2 +[t3].rgbtGreen * w3 + SrcLine2[t3 + 1].rgbtGreen * w4) shr 16;[x].rgbtBlue := (SrcLine1[t3].rgbtBlue * w1 +[t3 + 1].rgbtBlue * w2 +[t3].rgbtBlue * w3 +[t3 + 1].rgbtBlue * w4) shr 16;(xP, xP2);; {for}(yP, yP2);:= pRGBArray(Integer(DstLine) + DstGap);; {for}; {if}; {SmoothResize}GetAllBMPFiles( Path: string; Lb: TListBox ); //выбор изображения: TSearchRec;: boolean;:= FindFirst( Path + '\*.bmp', faAnyFile, sRec ) = 0;isFound do( sRec.Name <> '.' ) and ( sRec.Name <> '..' ) then( sRec.Attr and faDirectory ) = faDirectory then( Path + '\' + sRec.Name, Lb );.Items.Add( Path + '\' + sRec.Name );;.ProcessMessages;:= FindNext( sRec ) = 0;;( sRec );; MaxP(m:array of real):integer; // определение необходимости данной функции
var, i:integer;, max:real;:= 0;:= 0;i:= 0 to Length(m) -1 dom[i] > max then:= m[i];:= i;;;:= maxNO;;cleanTable(SG:TStringGrid);i,j:integer;i:=0 to SG.RowCount - 1 doj:=0 to SG.ColCount - 1 do.Cells[j,i]:='';;LoadBitmap(path:String; img:TImage); // загрузка изображенияbm: TBitmap;:= TBitmap.Create;.LoadFromFile(path);(bm, Img.Picture.Bitmap);.Refresh();;ImgToBin(M:TStringGrid; img:TImage); // преобразование изображения вx,y,p,s: integer; // таблицуy := 0 to Img.Height - 1 do beginx := 0 to Img.Width - 1 do beginImg.Canvas.Pixels[x,y]<>0 then p:=1 else p:=0;.Cells[x,y]:=IntToStr(p);;;;StringToHex(S: String): String; //преобразование в 16, в строкуI: Integer;:= '';I := 1 to length (S) do:= Result+IntToHex(ord(S[i]),2);;Centroid(SG:TStringGrid; col, row:integer):bool;x,y,buff,xc,yc:integer;,sumx,sumy:cardinal;:=False;:=0;sumy:=0;N:=0;
// Алгоритм вычисления центра масс образа
for y := 0 to SG.RowCount - 1 dox := 0 to SG.ColCount - 1 do:= strtoint(SG.Cells[y,x]);buff = 0 then buff := 1 else buff := 0;:= sumx + x * buff;:= sumy + y * buff; := N + buff;
end;
// получение координат центра масс образа
xc:= round(sumx/N);:= round(sumy/N);(col = xc) and (row = yc) then:=True;;getValCentroid(SG:TStringGrid):string; //возвращение координаты центраi,j:integer;i:=0 to SG.RowCount - 1 doj:=0 to SG.ColCount - 1 doCentroid(SG, j, i) = True then:= 'x: ' + inttostr(j) + ' / y: '+ inttostr(i);;;getValExtrems(SG:TStringGrid):string;i,j,e:integer;:=0;i:=0 to SG.RowCount - 1 doj:=0 to SG.ColCount - 1 doExtrema(SG, j, i) = True then:= e + 1;:= inttostr(e);;getValVertex(SG:TStringGrid):string;i,j,v:integer;:=0;i:=0 to SG.RowCount - 1 doj:=0 to SG.ColCount - 1 doVertex(SG, j, i) = True then:= v + 1;:= inttostr(v);;getValP(SG:TStringGrid):string; //получение значения периметраi,j,p:integer;:=0;i:=0 to SG.RowCount - 1 doj:=0 to SG.ColCount - 1 doPerimeter(SG, j, i) = True then:= p + 1;:= inttostr(p);;getValS(SG:TStringGrid):string; //получение значения площадиi,j,s:integer;:=0;i:=0 to SG.RowCount - 1 doj:=0 to SG.ColCount - 1 doSG.Cells[j,i] = '0' then:= s + 1;:= inttostr(s);;getValHash(SG:TStringGrid):string; // получение хэша таблицыstr_for_hash:string;,j:integer;_x, max_y, min_x, min_y:integer;_max_and_min(SG, max_x, max_y, min_x, min_y);_for_hash:='';i:=0 to SG.RowCount - 1 doj:=0 to SG.ColCount - 1 doArea(j,i,max_x, max_y, min_x, min_y) = True then
//SG.Cells[i,j]:='0';_for_hash := str_for_hash + SG.Cells[i,j];;str_for_hash <> '' then:=md5(StringToHex(str_for_hash));;.md5Hash;, SysUtils;md5(S: String): String;= Array of Byte;= Array of DWORD;= Array[0..3] of DWORD;= 4;= 16;= 64;LRot32(A: DWORD; B: Byte): DWORD;:= (A shl B) or (A shr (32-B));;Compressor(Hash, Buffer: Pointer; IV: LongWord = 0);, B, C, D: DWORD;:= TArrayOfDWORD(Hash)[0];:= TArrayOfDWORD(Hash)[1];:= TArrayOfDWORD(Hash)[2];:= TArrayOfDWORD(Hash)[3];:= Pointer(DWORD(Buffer) + IV);:= B + LRot32(A + (D xor (B and (C xor D))) + TArrayOfDWORD(Buffer)[ 0] + $D76AA478, 7);:= A + LRot32(D + (C xor (A and (B xor C))) + TArrayOfDWORD(Buffer)[ 1] + $E8C7B756, 12);:= D + LRot32(C + (B xor (D and (A xor B))) + TArrayOfDWORD(Buffer)[ 2] + $242070DB, 17);:= C + LRot32(B + (A xor (C and (D xor A))) + TArrayOfDWORD(Buffer)[ 3] + $C1BDCEEE, 22);:= B + LRot32(A + (D xor (B and (C xor D))) + TArrayOfDWORD(Buffer)[ 4] + $F57C0FAF, 7);:= A + LRot32(D + (C xor (A and (B xor C))) + TArrayOfDWORD(Buffer)[ 5] + $4787C62A, 12);:= D + LRot32(C + (B xor (D and (A xor B))) + TArrayOfDWORD(Buffer)[ 6] + $A8304613, 17);:= C + LRot32(B + (A xor (C and (D xor A))) + TArrayOfDWORD(Buffer)[ 7] + $FD469501, 22);:= B + LRot32(A + (D xor (B and (C xor D))) + TArrayOfDWORD(Buffer)[ 8] + $698098D8, 7);:= A + LRot32(D + (C xor (A and (B xor C))) + TArrayOfDWORD(Buffer)[ 9] + $8B44F7AF, 12);:= D + LRot32(C + (B xor (D and (A xor B))) + TArrayOfDWORD(Buffer)[10] + $FFFF5BB1, 17);:= C + LRot32(B + (A xor (C and (D xor A))) + TArrayOfDWORD(Buffer)[11] + $895CD7BE, 22);:= B + LRot32(A + (D xor (B and (C xor D))) + TArrayOfDWORD(Buffer)[12] + $6B901122, 7);:= A + LRot32(D + (C xor (A and (B xor C))) + TArrayOfDWORD(Buffer)[13] + $FD987193, 12);:= D + LRot32(C + (B xor (D and (A xor B))) + TArrayOfDWORD(Buffer)[14] + $A679438E, 17);:= C + LRot32(B + (A xor (C and (D xor A))) + TArrayOfDWORD(Buffer)[15] + $49B40821, 22);:= B + LRot32(A + (C xor (D and (B xor C))) + TArrayOfDWORD(Buffer)[ 1] + $F61E2562, 5);:= A + LRot32(D + (B xor (C and (A xor B))) + TArrayOfDWORD(Buffer)[ 6] + $C040B340, 9);:= D + LRot32(C + (A xor (B and (D xor A))) + TArrayOfDWORD(Buffer)[11] + $265E5A51, 14);:= C + LRot32(B + (D xor (A and (C xor D))) + TArrayOfDWORD(Buffer)[ 0] + $E9B6C7AA, 20);:= B + LRot32(A + (C xor (D and (B xor C))) + TArrayOfDWORD(Buffer)[ 5] + $D62F105D, 5);:= A + LRot32(D + (B xor (C and (A xor B))) + TArrayOfDWORD(Buffer)[10] + $02441453, 9);:= D + LRot32(C + (A xor (B and (D xor A))) + TArrayOfDWORD(Buffer)[15] + $D8A1E681, 14);:= C + LRot32(B + (D xor (A and (C xor D))) + TArrayOfDWORD(Buffer)[ 4] + $E7D3FBC8, 20);:= B + LRot32(A + (C xor (D and (B xor C))) + TArrayOfDWORD(Buffer)[ 9] + $21E1CDE6, 5);:= A + LRot32(D + (B xor (C and (A xor B))) + TArrayOfDWORD(Buffer)[14] + $C33707D6, 9);:= D + LRot32(C + (A xor (B and (D xor A))) + TArrayOfDWORD(Buffer)[ 3] + $F4D50D87, 14);:= C + LRot32(B + (D xor (A and (C xor D))) + TArrayOfDWORD(Buffer)[ 8] + $455A14ED, 20);:= B + LRot32(A + (C xor (D and (B xor C))) + TArrayOfDWORD(Buffer)[13] + $A9E3E905, 5);:= A + LRot32(D + (B xor (C and (A xor B))) + TArrayOfDWORD(Buffer)[ 2] + $FCEFA3F8, 9);:= D + LRot32(C + (A xor (B and (D xor A))) + TArrayOfDWORD(Buffer)[ 7] + $676F02D9, 14);:= C + LRot32(B + (D xor (A and (C xor D))) + TArrayOfDWORD(Buffer)[12] + $8D2A4C8A, 20);:= B + LRot32(A + (B xor C xor D) + TArrayOfDWORD(Buffer)[ 5] + $FFFA3942, 4);:= A + LRot32(D + (A xor B xor C) + TArrayOfDWORD(Buffer)[ 8] + $8771f681, 11);:= D + LRot32(C + (D xor A xor B) + TArrayOfDWORD(Buffer)[11] + $6D9D6122, 16);:= C + LRot32(B + (C xor D xor A) + TArrayOfDWORD(Buffer)[14] + $FDE5380C, 23);:= B + LRot32(A + (B xor C xor D) + TArrayOfDWORD(Buffer)[ 1] + $A4BEEA44, 4);:= A + LRot32(D + (A xor B xor C) + TArrayOfDWORD(Buffer)[ 4] + $4BDECFA9, 11);:= D + LRot32(C + (D xor A xor B) + TArrayOfDWORD(Buffer)[ 7] + $F6BB4B60, 16);:= C + LRot32(B + (C xor D xor A) + TArrayOfDWORD(Buffer)[10] + $BEBFBC70, 23);:= B + LRot32(A + (B xor C xor D) + TArrayOfDWORD(Buffer)[13] + $289B7EC6, 4);:= A + LRot32(D + (A xor B xor C) + TArrayOfDWORD(Buffer)[ 0] + $EAA127FA, 11);:= D + LRot32(C + (D xor A xor B) + TArrayOfDWORD(Buffer)[ 3] + $D4EF3085, 16);:= C + LRot32(B + (C xor D xor A) + TArrayOfDWORD(Buffer)[ 6] + $04881D05, 23);:= B + LRot32(A + (B xor C xor D) + TArrayOfDWORD(Buffer)[ 9] + $D9D4D039, 4);:= A + LRot32(D + (A xor B xor C) + TArrayOfDWORD(Buffer)[12] + $E6DB99E5, 11);:= D + LRot32(C + (D xor A xor B) + TArrayOfDWORD(Buffer)[15] + $1FA27CF8, 16);:= C + LRot32(B + (C xor D xor A) + TArrayOfDWORD(Buffer)[ 2] + $C4AC5665, 23);:= B + LRot32(A + (C xor (B or (not D))) + TArrayOfDWORD(Buffer)[ 0] + $F4292244, 6);:= A + LRot32(D + (B xor (A or (not C))) + TArrayOfDWORD(Buffer)[ 7] + $432AFF97, 10);:= D + LRot32(C + (A xor (D or (not B))) + TArrayOfDWORD(Buffer)[14] + $AB9423A7, 15);:= C + LRot32(B + (D xor (C or (not A))) + TArrayOfDWORD(Buffer)[ 5] + $FC93A039, 21);:= B + LRot32(A + (C xor (B or (not D))) + TArrayOfDWORD(Buffer)[12] + $655B59C3, 6);:= A + LRot32(D + (B xor (A or (not C))) + TArrayOfDWORD(Buffer)[ 3] + $8F0CCC92, 10);:= D + LRot32(C + (A xor (D or (not B))) + TArrayOfDWORD(Buffer)[10] + $FFEFF47D, 15);:= C + LRot32(B + (D xor (C or (not A))) + TArrayOfDWORD(Buffer)[ 1] + $85845DD1, 21);:= B + LRot32(A + (C xor (B or (not D))) + TArrayOfDWORD(Buffer)[ 8] + $6FA87E4F, 6);:= A + LRot32(D + (B xor (A or (not C))) + TArrayOfDWORD(Buffer)[15] + $FE2CE6E0, 10);:= D + LRot32(C + (A xor (D or (not B))) + TArrayOfDWORD(Buffer)[ 6] + $A3014314, 15);:= C + LRot32(B + (D xor (C or (not A))) + TArrayOfDWORD(Buffer)[13] + $4E0811A1, 21);:= B + LRot32(A + (C xor (B or (not D))) + TArrayOfDWORD(Buffer)[ 4] + $F7537E82, 6);:= A + LRot32(D + (B xor (A or (not C))) + TArrayOfDWORD(Buffer)[11] + $BD3AF235, 10);:= D + LRot32(C + (A xor (D or (not B))) + TArrayOfDWORD(Buffer)[ 2] + $2AD7D2BB, 15);:= C + LRot32(B + (D xor (C or (not A))) + TArrayOfDWORD(Buffer)[ 9] + $EB86D391, 21);(TArrayOfDWORD(Hash)[0], A);(TArrayOfDWORD(Hash)[1], B);(TArrayOfDWORD(Hash)[2], C);(TArrayOfDWORD(Hash)[3], D);;HashToStr(Hash: Pointer): String;: Byte;:= '';i := 0 to HashSize - 1 do:= Result + IntToHex(TArrayOfByte(Hash)[i], 2);;md5(S: String): String;: THash;, LenHI, LenLO: LongWord;: LongWord;:= '';:= Length(S);:= Len shr 29;:= Len * 8;:= S + #$80;(Len);i := 0 to BuffSize - (Len mod BuffSize) - 1 do S := S + #0;(Len mod BuffSize > 56) theni := 0 to BuffSize - 1 do S := S + #0;(S)[(Length(S) div BlockSize) - 1] := LenHI;(S)[(Length(S) div BlockSize) - 2] := LenLO;[0] := $67452301;[1] := $EFCDAB89;[2] := $98BADCFE;[3] := $10325476;i := 0 to (Length(S) div BuffSize) - 1 do(@CurrentHash, PChar(S), i * BuffSize);:= LowerCase(HashToStr(@CurrentHash));;.