Scanning methode:
Step1(Button:Analyze 4):
Put every color of the first selection in an array.
Put all the coordinates of the colors in an array
The coordinates are spread over diffrent arrays.
The first array poses the coordinates points that are not within a selection.
The rest of the arrays are the different selections.
Step2(Button:Analyze 4b): :
Find out which color comes most in the selection with the lowest count of that color.
Do this for another 2 colors.
Step3(Button:Analyze 4c): :
Put all coordinates of the 3 best colors in a stringgrid.
Make every possible combination of 2 coordinates and count the amount of that found DTM.
Remember the DTM with the highest good/bad ratio.
Step1:
procedure TForm1.Button8Click(Sender: TObject);
var
myFile : TextFile;
text : string;
//gkleur, fkleur: array[0..2550] of integer;
rowcount: integer;
xt:integer;
startpixelcolor,pixel2color:integer;
startpixelx,startpixely,pixelsy2,pixelsx2,pixel2y,pixel2x:integer;
goedgevonden,slechtgevonden,verschil1x,verschil1y:integer;
zoeky,zoekx,zoekx2,zoeky2:integer;
tempprocent,tempprocent2,procent: variant;
tempje,color: integer;
color2: array[0..10000] of integer;
startpixx,startpixy,startpixcol : integer;
directory : string;
selecs,tempje2, tempje3,i, error:integer;
bestaat: Boolean;
fout: Boolean;
aantalkleuren: array of integer;
goedeselectie: integer;
k:integer;
begin
xt:=Form1.PageControl1.TabIndex+1;
DelTree('c:/tmp/berekend');
CreateDir('c:/tmp/berekend');
SetLength(aantalkleuren, numforma+1); //[selectie(0= niet selctie; >1 = selecties)](aatal kleuren)
SetLength(kleurreeksx, numforma+1);
SetLength(kleurreeksy, numforma+1);
SetLength(kleurreeks, numforma+1);
//SetLength(kleurreeks, 1); //[selectie][kleuren]
//SetLength(kleurreeksx,1); //[selectie][kleur][hoeveelste x]
//SetLength(kleurreeksy,1); //[selectie][kleur][hoeveelste y]
tempje2:= 0;
//DelTree('c:\tmp');
//CreateDir('C:\tmp');
//CreateDir('C:\tmp\goed');
//CreateDir('C:\tmp\fout');
for selecs:=0 to numforma-1 do
begin
//CreateDir('C:\tmp\goed'+inttostr(selecs));
//ChDir('C:\tmp\goed'+inttostr(selecs));
end;
for zoeky2 := forma[0].top to forma[0].top+forma[0].Height-1 do
begin
for zoekx2 := forma[0].left to forma[0].left+forma[0].Width-1 do
begin
color2[tempje2] := img[xt].Canvas.Pixels[zoekx2, zoeky2];
tempje3:= 0;
for i:=0 to tempje2-1 do
begin
if(color2[i] = color2[tempje2])then tempje3:= 1;
end;
if(tempje3 =1)then tempje2:=tempje2-1;
tempje2:= tempje2+1;
end;
end;
//tempje2:= 0;
ShowMessage(inttostr(tempje2));
for zoeky := img[xt].top to img[xt].top+img[xt].Height-1 do
begin
for zoekx := img[xt].left to img[xt].left+img[xt].width-1 do
begin
Gauge1.Progress:= floor((zoeky*img[xt].width+zoekx)/(img[xt].Height*img[xt].Width)*100);
color:= img[xt].Canvas.Pixels[zoekx, zoeky];
bestaat := false;
for i:=0 to tempje2-1 do
begin
if(color2[i] = color)then bestaat:= true;
end;
if(bestaat)then begin
//dir:='C:\tmp\fout';
//CreateDir('C:\tmp\fout');
goedeselectie:= 0;
fout:= true;
//ChDir('C:\tmp\fout');
for selecs:=0 to numforma-1 do
begin
if(zoekx >= forma[selecs].left) AND (zoekx <= forma[selecs].left+forma[selecs].width) AND (zoeky >= forma[selecs].top) AND (zoeky <= forma[selecs].top+forma[selecs].height)then
begin
//CreateDir('C:\tmp\goed'+inttostr(selecs));
//ChDir('C:\tmp\goed'+inttostr(selecs));
//dir:='C:\tmp\goed'+inttostr(selecs);
fout:=false;
goedeselectie:=selecs+1;
end;
end;
//ChDir(dir);
//SetCurrentDir(dir);
//AssignFile(myFile, inttostr(color)+'.txt');
i:=-1;
huidigkleur:= -1;
while(huidigkleur = -1)AND(i<length(kleurreeks[0])-1) do
begin
i:= i+1;
if(kleurreeks[0][i] = color)then
begin
huidigkleur := i;
//ShowMessage('kleur is:'+inttostr(color)+'/n genomen kleur is:'+inttostr(kleurreeks[0][i]));
end;
end;
if huidigkleur > -1 then
begin
StatusBar1.SimpleText:= GetCurrentDir+'\'+inttostr(color)+'.txt';
//append(myFile);
end else
begin
//Rewrite(myFile);
//WriteLn(myFile, color);
//WriteLn(myFile, '1');
for i:=0 to numforma do
begin
SetLength(kleurreeksx[i], length(kleurreeksx[i])+1);
SetLength(kleurreeksy[i], length(kleurreeksy[i])+1);
SetLength(kleurreeks[i], length(kleurreeks[i])+1);
kleurreeks[i][Length(kleurreeks[i])-1] := color;
end;
huidigkleur:= Length(kleurreeks[0])-1;
end;
i:=-1;
while(huidigkleur = -1)AND(i<length(kleurreeks[0])-1) do
begin
i:= i+1;
if(kleurreeks[0][i] = color)then
begin
huidigkleur := i;
//ShowMessage('kleur is:'+inttostr(color)+'/n genomen kleur is:'+inttostr(kleurreeks[0][i]));
end;
end;
//kijk welke kleur
SetLength(kleurreeksx[goedeselectie][huidigkleur], length(kleurreeksx[goedeselectie][huidigkleur])+1);
SetLength(kleurreeksy[goedeselectie][huidigkleur], length(kleurreeksy[goedeselectie][huidigkleur])+1);
kleurreeksx[goedeselectie][huidigkleur][Length(kleurreeksx[goedeselectie][huidigkleur])-1]:= zoekx;
kleurreeksy[goedeselectie][huidigkleur][Length(kleurreeksy[goedeselectie][huidigkleur])-1]:= zoeky;
//WriteLn(myFile, '['+inttostr(zoekx)+', '+inttostr(zoeky)+']');
// Close the file
//CloseFile(myFile);
end;
rowcount:= length(kleurreeks[0]);
end;
end;
end;
Step2:
procedure TForm1.Button3Click(Sender: TObject);
var
myFile : TextFile;
text : string;
rowcount: integer;
temp,temp2,temp3: integer;
xt:integer;
startpixelcolor,pixel2color:integer;
startpixelx,startpixely,pixelsy2,pixelsx2,pixel2y,pixel2x:integer;
goedgevonden,slechtgevonden,verschil1x,verschil1y:integer;
zoeky,zoekx:integer;
tempprocent,tempprocent2,procent: variant;
tempje,color: integer;
startpixx,startpixy,startpixcol,regel,fout : integer;
directory : string;
selecs, selecs2:integer;
verwijder:Boolean;
begin
kleur1:= 0;
kleur2:= 0;
kleur3:= 0;
kleuren:= 0;
xt:=Form1.PageControl1.TabIndex+1;
CreateDir('C:\tmp\berekend');
ChDir('C:\tmp\berekend');
for zoeky := forma[0].top to forma[0].top+forma[0].Height-1 do
begin
for zoekx := forma[0].left to forma[0].left+forma[0].Width-1 do
begin
Gauge1.Progress:= floor((zoeky*forma[0].width+zoekx)/(forma[0].Height*forma[0].Width)*100);
color:= img[xt].Canvas.Pixels[zoekx, zoeky];
verwijder:= false;
for selecs:=0 to numforma-1 do
begin
// ChDir('C:\tmp\goed'+inttostr(selecs));
//if not FileExists(inttostr(color)+'.txt') then
i:=-1;
huidigkleur:= -1;
while(huidigkleur = -1)AND(i<length(kleurreeks[0])-1) do
begin
i:= i+1;
if(kleurreeks[0][i] = color)then
begin
huidigkleur := i;
//ShowMessage('kleur is:'+inttostr(color)+'/n genomen kleur is:'+inttostr(kleurreeks[0][i]));
end;
end;
if huidigkleur = -1 then
begin
verwijder:= true;
end;
end;
if(verwijder = false)then
begin
ChDir('C:\tmp\berekend');
if not FileExists(inttostr(color)+'.txt') then
begin
//CreateDir('C:\tmp\fout');
//ChDir('C:\tmp\fout');
//if FileExists(inttostr(color)+'.txt') then
i:=-1;
huidigkleur:= -1;
while(huidigkleur = -1)AND(i<length(kleurreeks[0])-1) do
begin
i:= i+1;
if(kleurreeks[0][i] = color)then
begin
huidigkleur := i;
//ShowMessage('kleur is:'+inttostr(color)+'/n genomen kleur is:'+inttostr(kleurreeks[0][i]));
end;
end;
if huidigkleur > -1 then
begin
//AssignFile(myFile, inttostr(color)+'.txt');
//Reset(myFile);
regel:= 0;
fout:= 0;
// while not Eof(myFile) do
//begin
//fout:= fout+1;
//ReadLn(myFile, text);
//end;
i:=-1;
huidigkleur := -1;
while(huidigkleur = -1)do
begin
i:= i+1;
if(kleurreeks[0][i] = color)then
begin
huidigkleur := i;
//ShowMessage('kleur is:'+inttostr(color)+'/n genomen kleur is:'+inttostr(kleurreeks[0][i]));
end;
end;
//ShowMessage(inttostr(kleurreeks[0][huidigkleur]));
fout:= length(kleurreeksx[0][huidigkleur]);
//CloseFile(myFile);
end;
//000000
temp:= 99999999;
//bestaat := 1;
for selecs:=0 to numforma-1 do
begin
//ChDir('C:\tmp\goed'+inttostr(selecs));
//if FileExists(inttostr(color)+'.txt') then
if huidigkleur > -1 then
begin
//AssignFile(myFile, inttostr(color)+'.txt');
//Reset(myFile);
regel:= 0;
//while not Eof(myFile) do
// begin
// regel:= regel+1;
// ReadLn(myFile, text);
// end;
huidigkleur := -1;
i:=-1;
while(huidigkleur = -1)do
begin
i:= i+1;
if(kleurreeks[0][i] = color)then
begin
huidigkleur := i;
//ShowMessage('kleur is:'+inttostr(color)+'/n genomen kleur is:'+inttostr(kleurreeks[0][i]));
end;
end;
regel:= length(kleurreeksx[selecs+1][huidigkleur]);
//CloseFile(myFile);
if(temp > regel)then temp:= regel;
end;
regel:= temp;
//000000
end;
if(regel = 99999999)then regel:= 0;
CreateDir('C:\tmp\berekend');
ChDir('C:\tmp\berekend');
AssignFile(myFile, inttostr(color)+'.txt');
Rewrite(myFile);
if(regel >2)then
begin
regel:= regel-2;
if(fout >=0)AND(fout < 3)then
fout:=0 else
fout:= fout -2;
end;
if(regel > 5)AND(regel+fout <> 0)then //5 staat voor minimaal aantal
procent:= floor(regel/(regel+fout)*100) else procent:= 0;
WriteLn(myFile, inttostr(regel));
WriteLn(myFile, inttostr(fout));
WriteLn(myFile, inttostr(procent));
kleuren:= kleuren+1;
SetLength(kleur,kleuren);
SetLength(kleurp,kleuren);
SetLength(kleurg,kleuren);
kleur[kleuren-1]:= color;
kleurp[kleuren-1]:= procent;
kleurg[kleuren-1]:= regel;
//ShowMessage(inttostr(kleurp[kleuren-1])+'/'+inttostr(kleurg[kleuren-1])+'/'+inttostr(kleur[kleuren-1]));
CloseFile(myFile);
end;
end;
end;
end;
ShowMessage('hoog'+inttostr(kleuren));
for i := kleuren-1 Downto 0 do
begin
for j := i to kleuren-2 do
begin
if kleurg[j] < kleurg[j + 1] then
begin
tmp := kleurg[j];
kleurg[j] := kleurg[j + 1];
kleurg[j + 1] := tmp;
tmp := kleurp[j];
if(kleurp[j+1] > 100)then ShowMessage(inttostr(j+1));
if(kleurp[j] > 100)then ShowMessage(inttostr(j+1));
kleurp[j] := kleurp[j + 1];
kleurp[j + 1] := tmp;
tmp := kleur[j];
kleur[j] := kleur[j + 1];
kleur[j + 1] := tmp;
end;
end;
end;
for i := kleuren-1 Downto 0 do
begin
for j := i to kleuren-2 do
begin
if kleurp[j] < kleurp[j + 1] then
begin
tmp := kleurg[j];
kleurg[j] := kleurg[j + 1];
kleurg[j + 1] := tmp;
tmp := kleurp[j];
if(kleurp[j+1] > 100)then ShowMessage(inttostr(j+1));
if(kleurp[j] > 100)then ShowMessage(inttostr(j+1));
kleurp[j] := kleurp[j + 1];
kleurp[j + 1] := tmp;
tmp := kleur[j];
kleur[j] := kleur[j + 1];
kleur[j + 1] := tmp;
end;
end;
end;
//QuickSort(kleurg,kleur,kleurp,High(kleurg), Low(kleurg));
//QuickSort(kleurp,kleur,kleurg,High(kleurp), Low(kleurp));
ShowMessage(inttostr(kleurp[0])+'/'+inttostr(kleur[0])+'/'+inttostr(kleurg[0]));
ShowMessage(inttostr(kleurp[1])+'/'+inttostr(kleur[1])+'/'+inttostr(kleurg[1]));
ShowMessage(inttostr(kleurp[2])+'/'+inttostr(kleur[2])+'/'+inttostr(kleurg[2]));
end;
Step3:
procedure TForm1.Button5Click(Sender: TObject);
var
myFile,myFile2 : TextFile;
text : string;
master1, master2, delimiter, found1, found2 : string;
i, j, K : integer; //operating variables
i2, j2, K2 : integer;
pixelkleur, pixelx, pixely: array[0..1000] of integer;
aantal,regel, aantal2, aantal3: integer;
selecs:integer;
firstcolor, secondcolor:integer;
firstx, secondx:integer;
firsty, secondy:integer;
gfirstcolor, gsecondcolor:integer;
gfirstx, gsecondx:integer;
gfirsty, gsecondy:integer;
verschilx, verschily:integer;
xt:integer;
goed: array of integer;
fout, verhouding,verhoudingvorig:integer;
goedvorig,goedvorig2:integer;
zoeky, zoekx:integer;
goedbol : Boolean;
DTM: TDDTMarray;
gevonden:integer;
kleurpos, kleurpos2:integer;
huidigkleur2, tempx, tempy, temppos:integer;
begin
goedvorig:= 0;
ShowMessage(inttostr(kleur[0]));
kleurpos:= kleurpositie(kleur[0]);
for i:=0 to length(kleurreeksx[1][kleurpos])-1 do
begin
Form6.StringGrid3.Cells[1,Form6.StringGrid3.RowCount-1] := inttostr(kleurreeks[1][kleurpos]);
Form6.StringGrid3.Cells[2,Form6.StringGrid3.RowCount-1] := inttostr(kleurreeksx[1][kleurpos][i]);
Form6.StringGrid3.Cells[3,Form6.StringGrid3.RowCount-1] := inttostr(kleurreeksy[1][kleurpos][i]);
Form6.StringGrid3.RowCount:= Form6.StringGrid3.RowCount+1;
end;
kleurpos:= kleurpositie(kleur[1]);
for i:=0 to length(kleurreeksx[1][kleurpos])-1 do
begin
Form6.StringGrid3.Cells[1,Form6.StringGrid3.RowCount-1] := inttostr(kleurreeks[1][kleurpos]);
Form6.StringGrid3.Cells[2,Form6.StringGrid3.RowCount-1] := inttostr(kleurreeksx[1][kleurpos][i]);
Form6.StringGrid3.Cells[3,Form6.StringGrid3.RowCount-1] := inttostr(kleurreeksy[1][kleurpos][i]);
Form6.StringGrid3.RowCount:= Form6.StringGrid3.RowCount+1;
end;
kleurpos:= kleurpositie(kleur[2]);
for i:=0 to length(kleurreeksx[1][kleurpos])-1 do
begin
Form6.StringGrid3.Cells[1,Form6.StringGrid3.RowCount-1] := inttostr(kleurreeks[1][kleurpos]);
Form6.StringGrid3.Cells[2,Form6.StringGrid3.RowCount-1] := inttostr(kleurreeksx[1][kleurpos][i]);
Form6.StringGrid3.Cells[3,Form6.StringGrid3.RowCount-1] := inttostr(kleurreeksy[1][kleurpos][i]);
Form6.StringGrid3.RowCount:= Form6.StringGrid3.RowCount+1;
end;
for i:=0 to Form6.StringGrid3.RowCount-2 do
begin
for k:=i+1 to Form6.StringGrid3.RowCount-2 do
begin
firstcolor:= strtoint(Form6.StringGrid3.Cells[1,i]);
firstx:= strtoint(Form6.StringGrid3.Cells[2,i]);
firsty:= strtoint(Form6.StringGrid3.Cells[3,i]);
secondcolor:= strtoint(Form6.StringGrid3.Cells[1,k]);
secondx:= strtoint(Form6.StringGrid3.Cells[2,k]);
secondy:= strtoint(Form6.StringGrid3.Cells[3,k]);
verschilx:= firstx - secondx;
verschily:= firsty - secondy;
huidigkleur:= kleurpositie(firstcolor);
huidigkleur2:= kleurpositie(secondcolor);
fout:= 0;
SetLength(goed, 0);
SetLength(goed, Numforma+1);
For selecs:=0 to Numforma do
begin
for j:=0 to length(kleurreeksx[selecs][huidigkleur])-1 do
begin
for j2:=j to length(kleurreeksx[selecs][huidigkleur2])-1 do
begin
if((kleurreeksx[selecs][huidigkleur][j]-kleurreeksx[selecs][huidigkleur2][j2]) = verschilx)then
begin
if((kleurreeksy[selecs][huidigkleur][j]-kleurreeksy[selecs][huidigkleur2][j2]) = verschily)then
begin
goed[selecs]:= goed[selecs]+1;
//ShowMessage(inttostr(goed[selecs]));
end;
end;
end;
end;
end;
goedvorig2 := 999999999;
for selecs:=1 to Numforma do
begin
if(goedvorig2 > goed[selecs])then goedvorig2:= goed[selecs];
end;
if(goedvorig2 <> goed[0]+goedvorig2)then
verhouding:= floor((goedvorig2/(goed[0]+goedvorig2))*100)else
verhouding:= 100;
if (verhouding >verhoudingvorig) or ((verhouding =verhoudingvorig) AND (goedvorig2 > goedvorig))then
begin
goedvorig := goedvorig2;
verhoudingvorig:= verhouding;
gfirstcolor:=firstcolor;
gfirstx:= firstx;
gfirsty:= firsty;
gsecondcolor:= secondcolor;
gsecondx:= secondx;
gsecondy:= secondy;
end;
end;
end;
Form6.StaticText1.Caption:= inttostr(gfirstcolor);
Form6.StaticText2.Caption:= inttostr(gfirstx);
Form6.StaticText3.Caption:= inttostr(gfirsty);
Form6.StaticText4.Caption:= inttostr(gsecondx);
Form6.StaticText5.Caption:= inttostr(gsecondy);
Form6.StaticText6.Caption:= inttostr(gsecondcolor);
Form6.StaticText7.Caption:= inttostr(verhoudingvorig);
Form6.StaticText8.Caption:= inttostr(goedvorig);
SetLength(DTM, 2);
DTM[0].x:= gfirstx;
DTM[0].y:= gfirsty;
DTM[0].size:= 0;
//DTM.shape:= pixely[i];
DTM[0].color:= gfirstcolor;
DTM[0].Tolerance:= 0;
DTM[1].x:= gsecondx;
DTM[1].y:= gsecondy;
DTM[1].size:= 0;
//DTM.shape:= pixely[i];
DTM[1].color:= gsecondcolor;
DTM[1].Tolerance:= 0;
Form6.memo1.lines.text:= DDTMtoDTM(DTM);
ShowMessage('klaar');
end;
If you look at the code you will see allot of showmessages and allot commented away. thats because of the testing.
you will also see that i have more variables declared than i use, well that is just because i am unorganized and change my mind continuesly or try a diffrent way of coding with diffrent names:tongue: