SRL Archive - News and General

Dtm scanner!!


nielskool

2010-05-15 18:43:48

Hey guys,

long long time ago i said i would make a DTM scanner, well three days ago i started, and guess what, it works.
open the screensot,
make a minimun of two selections
and the program wil generate a dtm for the object… isn't that great?
but… it needs some perfection.
the program is made in delphi, so if there are any volunteers who like to test it for me or help me make it better, please react:P(i preffer SRL members)

can be used for everything, not just runescape.
sorry for my bad english, i am dutch and it is 0:44 AM:P

//edit
http://www.youtube.com/watch?v=plzYJ94sYwQ

things to improve:
now it only finds 100% matches make a color scanner with a bit tolerance
now the dtm is limited to 2 pixels, increase to 10
now it only looks which pixel combination comes most in selection(with the best colors)
make it also look for the dtm outside of the selection.


proces explenetion:
first it scans the first selection
save all colors and there coörds
get the coörds of these colors in the other selection and in the non selection
take the color that comes most in the selection en least in the non selection
colorcounted(selection)/(colorcounted(selection)+colorcounted(nonselection))*100=%
remember the colors with the highest %
for every pixel of the 3 best colors combine with another pixel
find dtm in selection
remember the dtm with the highest lowest found.
is in selection1 the dtm is found 10 times, and in selection2 it is found 2 times than it says this dtm is found 2 times

hope you guys understand:P

Sex

2010-05-16 03:18:44

I'd love to help :)..

ShowerThoughts

2010-05-16 07:00:22

Post the code?

nielskool

2010-05-16 07:53:37

eej hermen,

i have to say it is a hell of a mess..:P
and i started with other ways of searching for a dtm so there are 4 algorthmes in the app.. first 3 don't work, atleast not as i want it to.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Menus, Buttons, ExtDlgs, Grids,
ValEdit, ToolWin, Gauges, Mask;

type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
PageControl1: TPageControl;
Addb: TButton;
delb: TButton;
adds: TButton;
dels: TButton;
MainMenu1: TMainMenu;
File1: TMenuItem;
Exit1: TMenuItem;
Help1: TMenuItem;
Howtouse1: TMenuItem;
About1: TMenuItem;
New1: TMenuItem;
Reset1: TMenuItem;
Dtms1: TMenuItem;
Makedtm1: TMenuItem;
MakeDDTM1: TMenuItem;
BitBtn1: TBitBtn;
Edit1: TEdit;
Label1: TLabel;
OpenPictureDialog1: TOpenPictureDialog;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Button1: TButton;
Button2: TButton;
CheckDTM1: TMenuItem;
Checkcolor1: TMenuItem;
GenerarteDTM1: TMenuItem;
Credits1: TMenuItem;
ValueListEditor1: TValueListEditor;
Button4: TButton;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Edit10: TEdit;
Edit11: TEdit;
Edit12: TEdit;
Edit13: TEdit;
ValueListEditor2: TValueListEditor;
ValueListEditor3: TValueListEditor;
Button6: TButton;
StaticText1: TStaticText;
BitBtn2: TBitBtn;
Edit14: TEdit;
Gauge1: TGauge;
MaskEdit1: TMaskEdit;
MaskEdit2: TMaskEdit;
Button7: TButton;
Button8: TButton;
Button3: TButton;
Button5: TButton;
Label7: TLabel;
procedure AddbClick(Sender: TObject);
procedure PageControl1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure delbClick(Sender: TObject);
procedure OpenPictureDialog1SelectionChange(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure Credits1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1Mouseup(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);

procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
x : integer;
im:boolean;
tabSheetw : array[0..10] of TTabSheet;
selec1x,selec1y,selec2x,selec2y : array[0..12] of integer;
selec: array[0..12] of Tshape;
img: array[0..10] of TImage;
pixelsy, pixelsx: integer;
scro: array[0..10] of TScrollBox;
temparr , temparr2:array of integer;
kleur1,kleur2,kleur3:integer;
kleur1p,kleur2p,kleur3p:integer;
kleur1g,kleur2g,kleur3g:integer;

implementation

uses Unit2, Unit3, Unit4, Math, Unit5, Unit6;
var
forma: array of TShape; //Array to create
formaUtil: Integer; // Kind of shape
Numforma: Integer; //Number of shapes
Izq, Arr, Ancho, alto, x1, x2, y1, y2: Integer; //Position and size of shape
activar: Boolean; //Tells when you are creating and sizing the shape


{$R *.dfm}
procedure TForm1.Image1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
xt:integer;
begin
formaUtil := 1;
if formaUtil < 1 then Exit;
activar := True;
xt:=Form1.PageControl1.TabIndex+1;
//starting draw the shape
x1 := x+ img[xt].left;
Edit10.text:= inttostr(x1);
//ShowMessage(inttostr(x1));
y1 := y+ img[xt].Top;
Edit11.text:= inttostr(y1);
//ShowMessage(inttostr(y1));
numforma := numforma + 1;
setlength(forma, numforma);
forma[numforma - 1] := TShape.Create(TabSheetw[xt]);
forma[numforma - 1].Pen.Mode:=pmNot;
forma[numforma - 1].Pen.Width:=1;
forma[numforma - 1].Pen.Color:=clBlack;
if formaUtil = 1 then
forma[numforma - 1].Shape :=stRectangle
else
forma[numforma - 1].Shape := stCircle;
forma[numforma - 1].Left := x1;
forma[numforma - 1].Top := y1;
forma[numforma - 1].Parent := scro[xt];
forma[numforma - 1].Width := 0;
forma[numforma - 1].Height := 0;
forma[numforma - 1].BringToFront;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
xt:integer;
begin
xt:=Form1.PageControl1.TabIndex+1;
Edit8.Text:= inttostr(x);
Edit9.Text:= inttostr(y);
Edit7.Color := img[xt].Canvas.Pixels[x+img[xt].left, y+img[xt].Top];
Edit6.Text := inttostr(img[xt].Canvas.Pixels[x+img[xt].left, y+img[xt].Top]);
if (formaUtil = 0) then Exit;
if (numforma = 0) then Exit;
if not activar then Exit;
x2 := x+img[xt].left;
Edit12.text:= inttostr(x2);
y2 := y+img[xt].Top;
Edit13.text:= inttostr(y2);
forma[numforma - 1].Width := x2 - x1;
forma[numforma - 1].Height := y2 - y1;
StaticText1.Caption := IntToStr(numforma);
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
xt:integer;
begin
xt:=Form1.PageControl1.TabIndex+1;
x2 := x+img[xt].left;
//ShowMessage(inttostr(x2));
y2 := y+img[xt].Top;
//ShowMessage(inttostr(y2));
forma[numforma - 1].Width := x2 - x1;
forma[numforma - 1].Height := y2 - y1;
formaUtil := 1;
activar := False;
//form5.show;
Form5.MaskEdit1.text := inttostr(forma[0].left);
Form5.MaskEdit2.text := inttostr(forma[0].top);
Form5.MaskEdit3.text := inttostr(forma[0].height);
Form5.MaskEdit4.text := inttostr(forma[0].width);

end;

procedure TForm1.AddbClick(Sender: TObject);
begin
x:= pageControl1.PageCount+1;
tabSheetw[x] := TTabSheet.Create(PageControl1) ;
tabSheetw[x].PageControl := PageControl1;
tabSheetw[x].Caption:= inttostr(pageControl1.PageCount);
scro[x] := TScrollBox.Create(tabSheetw[x]);
scro[x].Align := alClient;
scro[x].Parent:= tabSheetw[x];
scro[x].BorderStyle:=bsSingle;
img[x] := TImage.Create(scro[x]);
img[x].Parent := scro[x];
img[x].OnMouseUp := Image1MouseUp;
img[x].OnMouseDown := Image1MouseDown;
img[x].OnMouseMove := Image1MouseMove;


end;

procedure setrechts();
var
x : integer;
tabSheetw : array[0..10] of TTabSheet;
begin
end;

procedure sorter();
var i,j,temp, temp2,minIndex:integer;
sortedstring:string;
begin
setlength(temparr2,high(temparr));
for i:= low(temparr) to high(temparr) do
begin
temparr2[i] := strtoint(Form1.ValueListEditor2.Values[inttostr(temparr[i])]);
end;

for i:= 0 to length(temparr)-1 do
begin
// zoek kleinste in de rest van de array
minIndex := i;
for j:=i to length(temparr2)do
begin
if (temparr2[j] < temparr2[minIndex]) then
begin
minIndex := j;
end;
end;

// verwissel waarden
temp := temparr[i];
temparr[i] := temparr[minIndex];
temparr[minIndex] := temp;

temp := temparr2[i];
temparr2[i] := temparr2[minIndex];
temparr2[minIndex] := temp;
//ShowMessage(inttostr(temparr[i]));


end;
end;


procedure TForm1.PageControl1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//setrechts();
end;

procedure TForm1.delbClick(Sender: TObject);
begin
x:= pageControl1.PageCount;
tabSheetw[x].Destroy;
end;

procedure TForm1.OpenPictureDialog1SelectionChange(Sender: TObject);
begin
//Self.get
//Self.Parent.image1.picture := Self.
end;

procedure TForm1.Button4Click(Sender: TObject);
var
Bitmap: TBitmap;
x:integer;
begin
Bitmap := TBitmap.Create;
if OpenPictureDialog1.Execute then
begin
x:= PageControl1.TabIndex+1;
Bitmap.LoadFromFile(OpenPictureDialog1.FileName);
img[x].Picture.LoadFromFile(OpenPictureDialog1.FileName);
img[x].Width:= Bitmap.Width ;
img[x].Height:= Bitmap.Height;
end;
Bitmap.Free;
end;




procedure TForm1.About1Click(Sender: TObject);
begin
About.show;
end;

procedure TForm1.Credits1Click(Sender: TObject);
begin
Credits.show;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
formaUtil := 1;
Numforma := 0;
activar := False;
end;







procedure TForm1.BitBtn2Click(Sender: TObject);
begin
Form4.ShowModal;
end;



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,i, error:integer;
bestaat: Boolean;

begin
xt:=Form1.PageControl1.TabIndex+1;
tempje2:= 0;
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];
for i:=0 to tempje2-1 do
begin
if(color2[i] = color2[tempje2])then tempje2:= tempje2-1;
end;
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
CreateDir('C:\tmp\fout');
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));
end;
end;

AssignFile(myFile, inttostr(color)+'.txt');
if FileExists(inttostr(color)+'.txt') then
Append(myFile)
else
begin
Rewrite(myFile);
WriteLn(myFile, color);
WriteLn(myFile, '1');
end;
WriteLn(myFile, '['+inttostr(zoekx)+', '+inttostr(zoeky)+']');

// Close the file
CloseFile(myFile);





end;
end;
end;


end;


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;
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
begin
for selecs2:=0 to numforma-1 do
begin
ChDir('C:\tmp\goed'+inttostr(selecs2));
If(FileExists(inttostr(color)+'.txt'))then
DeleteFile(inttostr(color)+'.txt');
end;
ChDir('C:\tmp\berekend');
If(FileExists(inttostr(color)+'.txt'))then
DeleteFile(inttostr(color)+'.txt');
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
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;
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
begin
AssignFile(myFile, inttostr(color)+'.txt');
Reset(myFile);
regel:= 0;

while not Eof(myFile) do
begin
regel:= regel+1;
ReadLn(myFile, text);

end;
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));
if(procent > kleur3p)then
begin
if(kleur3 = 0)then
begin
if(kleur2 = 0)then
begin
if(kleur1 = 0)then
begin
kleur1 := color;
kleur1p := procent;
kleur1g := regel;
end else
begin
kleur2 := color;
kleur2p := procent;
kleur2g := regel;
end;
end else
begin
kleur1 := color;
kleur1p := procent;
kleur1g := regel;
end;
end;

end;

if(procent > kleur3p)then
begin
kleur3 := color;
kleur3p:= procent;
kleur3g:= regel;
end;
if(procent = kleur3p)then
begin
if(regel > kleur3g)then
begin
kleur3 := color;
kleur3p:= procent;
kleur3g:= regel;
end;
end;

if(kleur3p > kleur2p)then
begin
temp:= kleur3;
temp2:= kleur3p;
temp3:= kleur3g;
kleur3 := kleur2;
kleur3p:= kleur2p;
kleur3g:= kleur2g;
kleur2 := temp;
kleur2p:= temp2;
kleur2g:= temp3;
end;
if(kleur3p = kleur2p)then
begin
if(kleur3g > kleur2g)then
begin
temp:= kleur3;
temp2:= kleur3p;
temp3:= kleur3g;
kleur3 := kleur2;
kleur3p:= kleur2p;
kleur3g:= kleur2g;
kleur2 := temp;
kleur2p:= temp2;
kleur2g:= temp3;
end;
end;

if(kleur2p > kleur1p)then
begin
temp:= kleur2;
temp2:= kleur2p;
temp3:= kleur2g;
kleur2 := kleur1;
kleur2p:= kleur1p;
kleur2g:= kleur1g;
kleur1 := temp;
kleur1p:= temp2;
kleur1g:= temp3;
end;
if(kleur2p = kleur1p)then
begin
if(kleur2g > kleur1g)then
begin
temp:= kleur2;
temp2:= kleur2p;
temp3:= kleur2g;
kleur2 := kleur1;
kleur2p:= kleur1p;
kleur2g:= kleur1g;
kleur1 := temp;
kleur1p:= temp2;
kleur1g:= temp3;
end;
end;

CloseFile(myFile);


end;
end;
end;
end;
ShowMessage(inttostr(kleur1p)+'/'+inttostr(kleur1));
ShowMessage(inttostr(kleur2p)+'/'+inttostr(kleur2));
ShowMessage(inttostr(kleur3p)+'/'+inttostr(kleur3));
end;


procedure TForm1.Button5Click(Sender: TObject);
var
myFile,myFile2 : TextFile;
text : string;
master1, master2, delimiter, found1, found2 : string;
i, j, K : integer; //operating variables
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:integer;
goedvorig,goedvorig2:integer;


begin
for selecs:=0 to numforma-1 do
begin
aantal:= 0;
aantal2:= 0;
aantal3:= 0;

ChDir('C:\tmp\goed'+inttostr(selecs));
AssignFile(myFile, inttostr(kleur1)+'.txt');
Reset(myFile);

regel:= 0;
while not Eof(myFile) do
begin
ReadLn(myFile, text);
regel:= regel+1;
if(regel > 2)then
begin
delimiter :='[';
master1:= text;
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ',';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found1 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
delimiter :=',';
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ']';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found2 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
pixelkleur[aantal] := kleur1;
pixelx[aantal] := strtoint(found1);
pixely[aantal] := strtoint(found2);
aantal := aantal+1;


end;
end;
CloseFile(myFile);
AssignFile(myFile2, inttostr(kleur2)+'.txt');
Reset(myFile2);

regel:= 0;
while not Eof(myFile2) do
begin
ReadLn(myFile2, text);
regel:= regel+1;
if(regel > 2)then
begin
delimiter :='[';
master1:= text;
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ',';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found1 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
delimiter :=',';
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ']';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found2 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
pixelkleur[aantal] := kleur2;
pixelx[aantal] := strtoint(found1);
pixely[aantal] := strtoint(found2);
aantal := aantal+1;


end;
end;

CloseFile(myFile2);
AssignFile(myFile, inttostr(kleur3)+'.txt');
Reset(myFile);

regel:= 0;
while not Eof(myFile) do
begin
ReadLn(myFile, text);
regel:= regel+1;
if(regel > 2)then
begin
delimiter :='[';
master1:= text;
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ',';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found1 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
delimiter :=',';
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ']';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found2 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
pixelkleur[aantal] := kleur3;
pixelx[aantal] := strtoint(found1);
pixely[aantal] := strtoint(found2);
aantal := aantal+1;


end;
end;
CloseFile(myFile);
if(selecs= 0)then
begin
for i:=0 to aantal-1 do
begin
Form6.StringGrid1.RowCount:= aantal;
Form6.StringGrid1.Cells[1,i] := inttostr(pixelkleur[i]);
Form6.StringGrid1.Cells[2,i] := inttostr(pixelx[i]);
Form6.StringGrid1.Cells[3,i] := inttostr(pixely[i]);
end;
end;
if(selecs= 1)then
begin
for i:=0 to aantal-1 do
begin
Form6.StringGrid2.RowCount:= aantal;
Form6.StringGrid2.Cells[1,i] := inttostr(pixelkleur[i]);
Form6.StringGrid2.Cells[2,i] := inttostr(pixelx[i]);
Form6.StringGrid2.Cells[3,i] := inttostr(pixely[i]);
end;
end;
if(selecs= 2)then
begin
for i:=0 to aantal-1 do
begin
Form6.StringGrid3.RowCount:= aantal+aantal2+aantal3;
Form6.StringGrid3.Cells[1,i] := inttostr(pixelkleur[i]);
Form6.StringGrid3.Cells[2,i] := inttostr(pixelx[i]);
Form6.StringGrid3.Cells[3,i] := inttostr(pixely[i]);
end;
end;
end;

for i:=0 to Form6.StringGrid1.RowCount-2 do
begin
for J:=i+1 to Form6.StringGrid1.RowCount-1 do
begin
firstcolor:= strtoint(Form6.StringGrid1.cells[1,i]);
secondcolor:= strtoint(Form6.StringGrid1.cells[1,j]);
firstx:= strtoint(Form6.StringGrid1.cells[2,i]);
firsty:= strtoint(Form6.StringGrid1.cells[3,i]);
secondx:= strtoint(Form6.StringGrid1.cells[2,j]);
secondy:= strtoint(Form6.StringGrid1.cells[3,j]);
verschilx:= secondx-firstx;
verschily:= secondy-firsty;

xt:=Form1.PageControl1.TabIndex+1;
goed:= 0;
for K:=0 to Form6.StringGrid1.RowCount-1 do
begin
if(strtoint(Form6.StringGrid1.cells[1,K]) = firstcolor)then
begin
//kleur 1 is goed
if(secondcolor = img[xt].Canvas.Pixels[strtoint(Form6.StringGrid1.cells[2,K]), strtoint(Form6.StringGrid1.cells[3,K])])then
begin
goed:= goed+1;
end;
end;
end;
goedvorig2:= goed;
goed:= 0;

for K:=0 to Form6.StringGrid2.RowCount-1 do
begin
if(strtoint(Form6.StringGrid2.cells[1,K]) = firstcolor)then
begin
//kleur 1 is goed
if(strtoint(Form6.StringGrid2.cells[2,K])+verschilx > 0)AND(strtoint(Form6.StringGrid2.cells[2,K])+verschilx < img[xt].Width)AND(strtoint(Form6.StringGrid2.cells[3,K])+verschily > 0)AND(strtoint(Form6.StringGrid2.cells[3,K])+verschily < img[xt].Height)then
begin
if(secondcolor = img[xt].Canvas.Pixels[strtoint(Form6.StringGrid2.cells[2,K])+verschilx, strtoint(Form6.StringGrid2.cells[3,K])+verschily])then
begin
goed:= goed+1;
end;
end;
end;
end;
if(goedvorig2<goed)then goed:= goedvorig2;
if(goed > goedvorig)then
begin
goedvorig:= goed;
gfirstcolor:= strtoint(Form6.StringGrid1.cells[1,i]);
gsecondcolor:= strtoint(Form6.StringGrid1.cells[1,j]);
gfirstx:= strtoint(Form6.StringGrid1.cells[2,i]);
gfirsty:= strtoint(Form6.StringGrid1.cells[3,i]);
gsecondx:= strtoint(Form6.StringGrid1.cells[2,j]);
gsecondy:= strtoint(Form6.StringGrid1.cells[3,j]);
//ShowMessage('gelukt');
end;

end;
end;
ShowMessage(inttostr(goedvorig));
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);

end;



end.

i removed the other algoritmes.
i don't expect you to understand what how it does because the names i use are a dutch and english mixed. sometimes not logical.

ShowerThoughts

2010-05-16 08:13:05

From: nielskool
eej herman,

i have to say it is a hell of a mess..:P
and i started with other ways of searching for a dtm so there are 4 algorthmes in the app.. first 3 don't work, atleast not as i want it to.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Menus, Buttons, ExtDlgs, Grids,
ValEdit, ToolWin, Gauges, Mask;

type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
PageControl1: TPageControl;
Addb: TButton;
delb: TButton;
adds: TButton;
dels: TButton;
MainMenu1: TMainMenu;
File1: TMenuItem;
Exit1: TMenuItem;
Help1: TMenuItem;
Howtouse1: TMenuItem;
About1: TMenuItem;
New1: TMenuItem;
Reset1: TMenuItem;
Dtms1: TMenuItem;
Makedtm1: TMenuItem;
MakeDDTM1: TMenuItem;
BitBtn1: TBitBtn;
Edit1: TEdit;
Label1: TLabel;
OpenPictureDialog1: TOpenPictureDialog;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Button1: TButton;
Button2: TButton;
CheckDTM1: TMenuItem;
Checkcolor1: TMenuItem;
GenerarteDTM1: TMenuItem;
Credits1: TMenuItem;
ValueListEditor1: TValueListEditor;
Button4: TButton;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Edit10: TEdit;
Edit11: TEdit;
Edit12: TEdit;
Edit13: TEdit;
ValueListEditor2: TValueListEditor;
ValueListEditor3: TValueListEditor;
Button6: TButton;
StaticText1: TStaticText;
BitBtn2: TBitBtn;
Edit14: TEdit;
Gauge1: TGauge;
MaskEdit1: TMaskEdit;
MaskEdit2: TMaskEdit;
Button7: TButton;
Button8: TButton;
Button3: TButton;
Button5: TButton;
Label7: TLabel;
procedure AddbClick(Sender: TObject);
procedure PageControl1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure delbClick(Sender: TObject);
procedure OpenPictureDialog1SelectionChange(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure Credits1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1Mouseup(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);

procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
x : integer;
im:boolean;
tabSheetw : array[0..10] of TTabSheet;
selec1x,selec1y,selec2x,selec2y : array[0..12] of integer;
selec: array[0..12] of Tshape;
img: array[0..10] of TImage;
pixelsy, pixelsx: integer;
scro: array[0..10] of TScrollBox;
temparr , temparr2:array of integer;
kleur1,kleur2,kleur3:integer;
kleur1p,kleur2p,kleur3p:integer;
kleur1g,kleur2g,kleur3g:integer;

implementation

uses Unit2, Unit3, Unit4, Math, Unit5, Unit6;
var
forma: array of TShape; //Array to create
formaUtil: Integer; // Kind of shape
Numforma: Integer; //Number of shapes
Izq, Arr, Ancho, alto, x1, x2, y1, y2: Integer; //Position and size of shape
activar: Boolean; //Tells when you are creating and sizing the shape


{$R *.dfm}
procedure TForm1.Image1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
xt:integer;
begin
formaUtil := 1;
if formaUtil < 1 then Exit;
activar := True;
xt:=Form1.PageControl1.TabIndex+1;
//starting draw the shape
x1 := x+ img[xt].left;
Edit10.text:= inttostr(x1);
//ShowMessage(inttostr(x1));
y1 := y+ img[xt].Top;
Edit11.text:= inttostr(y1);
//ShowMessage(inttostr(y1));
numforma := numforma + 1;
setlength(forma, numforma);
forma[numforma - 1] := TShape.Create(TabSheetw[xt]);
forma[numforma - 1].Pen.Mode:=pmNot;
forma[numforma - 1].Pen.Width:=1;
forma[numforma - 1].Pen.Color:=clBlack;
if formaUtil = 1 then
forma[numforma - 1].Shape :=stRectangle
else
forma[numforma - 1].Shape := stCircle;
forma[numforma - 1].Left := x1;
forma[numforma - 1].Top := y1;
forma[numforma - 1].Parent := scro[xt];
forma[numforma - 1].Width := 0;
forma[numforma - 1].Height := 0;
forma[numforma - 1].BringToFront;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
xt:integer;
begin
xt:=Form1.PageControl1.TabIndex+1;
Edit8.Text:= inttostr(x);
Edit9.Text:= inttostr(y);
Edit7.Color := img[xt].Canvas.Pixels[x+img[xt].left, y+img[xt].Top];
Edit6.Text := inttostr(img[xt].Canvas.Pixels[x+img[xt].left, y+img[xt].Top]);
if (formaUtil = 0) then Exit;
if (numforma = 0) then Exit;
if not activar then Exit;
x2 := x+img[xt].left;
Edit12.text:= inttostr(x2);
y2 := y+img[xt].Top;
Edit13.text:= inttostr(y2);
forma[numforma - 1].Width := x2 - x1;
forma[numforma - 1].Height := y2 - y1;
StaticText1.Caption := IntToStr(numforma);
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
xt:integer;
begin
xt:=Form1.PageControl1.TabIndex+1;
x2 := x+img[xt].left;
//ShowMessage(inttostr(x2));
y2 := y+img[xt].Top;
//ShowMessage(inttostr(y2));
forma[numforma - 1].Width := x2 - x1;
forma[numforma - 1].Height := y2 - y1;
formaUtil := 1;
activar := False;
//form5.show;
Form5.MaskEdit1.text := inttostr(forma[0].left);
Form5.MaskEdit2.text := inttostr(forma[0].top);
Form5.MaskEdit3.text := inttostr(forma[0].height);
Form5.MaskEdit4.text := inttostr(forma[0].width);

end;

procedure TForm1.AddbClick(Sender: TObject);
begin
x:= pageControl1.PageCount+1;
tabSheetw[x] := TTabSheet.Create(PageControl1) ;
tabSheetw[x].PageControl := PageControl1;
tabSheetw[x].Caption:= inttostr(pageControl1.PageCount);
scro[x] := TScrollBox.Create(tabSheetw[x]);
scro[x].Align := alClient;
scro[x].Parent:= tabSheetw[x];
scro[x].BorderStyle:=bsSingle;
img[x] := TImage.Create(scro[x]);
img[x].Parent := scro[x];
img[x].OnMouseUp := Image1MouseUp;
img[x].OnMouseDown := Image1MouseDown;
img[x].OnMouseMove := Image1MouseMove;


end;

procedure setrechts();
var
x : integer;
tabSheetw : array[0..10] of TTabSheet;
begin
end;

procedure sorter();
var i,j,temp, temp2,minIndex:integer;
sortedstring:string;
begin
setlength(temparr2,high(temparr));
for i:= low(temparr) to high(temparr) do
begin
temparr2[i] := strtoint(Form1.ValueListEditor2.Values[inttostr(temparr[i])]);
end;

for i:= 0 to length(temparr)-1 do
begin
// zoek kleinste in de rest van de array
minIndex := i;
for j:=i to length(temparr2)do
begin
if (temparr2[j] < temparr2[minIndex]) then
begin
minIndex := j;
end;
end;

// verwissel waarden
temp := temparr[i];
temparr[i] := temparr[minIndex];
temparr[minIndex] := temp;

temp := temparr2[i];
temparr2[i] := temparr2[minIndex];
temparr2[minIndex] := temp;
//ShowMessage(inttostr(temparr[i]));


end;
end;


procedure TForm1.PageControl1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//setrechts();
end;

procedure TForm1.delbClick(Sender: TObject);
begin
x:= pageControl1.PageCount;
tabSheetw[x].Destroy;
end;

procedure TForm1.OpenPictureDialog1SelectionChange(Sender: TObject);
begin
//Self.get
//Self.Parent.image1.picture := Self.
end;

procedure TForm1.Button4Click(Sender: TObject);
var
Bitmap: TBitmap;
x:integer;
begin
Bitmap := TBitmap.Create;
if OpenPictureDialog1.Execute then
begin
x:= PageControl1.TabIndex+1;
Bitmap.LoadFromFile(OpenPictureDialog1.FileName);
img[x].Picture.LoadFromFile(OpenPictureDialog1.FileName);
img[x].Width:= Bitmap.Width ;
img[x].Height:= Bitmap.Height;
end;
Bitmap.Free;
end;




procedure TForm1.About1Click(Sender: TObject);
begin
About.show;
end;

procedure TForm1.Credits1Click(Sender: TObject);
begin
Credits.show;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
formaUtil := 1;
Numforma := 0;
activar := False;
end;







procedure TForm1.BitBtn2Click(Sender: TObject);
begin
Form4.ShowModal;
end;



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,i, error:integer;
bestaat: Boolean;

begin
xt:=Form1.PageControl1.TabIndex+1;
tempje2:= 0;
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];
for i:=0 to tempje2-1 do
begin
if(color2[i] = color2[tempje2])then tempje2:= tempje2-1;
end;
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
CreateDir('C:\tmp\fout');
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));
end;
end;

AssignFile(myFile, inttostr(color)+'.txt');
if FileExists(inttostr(color)+'.txt') then
Append(myFile)
else
begin
Rewrite(myFile);
WriteLn(myFile, color);
WriteLn(myFile, '1');
end;
WriteLn(myFile, '['+inttostr(zoekx)+', '+inttostr(zoeky)+']');

// Close the file
CloseFile(myFile);





end;
end;
end;


end;


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;
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
begin
for selecs2:=0 to numforma-1 do
begin
ChDir('C:\tmp\goed'+inttostr(selecs2));
If(FileExists(inttostr(color)+'.txt'))then
DeleteFile(inttostr(color)+'.txt');
end;
ChDir('C:\tmp\berekend');
If(FileExists(inttostr(color)+'.txt'))then
DeleteFile(inttostr(color)+'.txt');
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
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;
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
begin
AssignFile(myFile, inttostr(color)+'.txt');
Reset(myFile);
regel:= 0;

while not Eof(myFile) do
begin
regel:= regel+1;
ReadLn(myFile, text);

end;
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));
if(procent > kleur3p)then
begin
if(kleur3 = 0)then
begin
if(kleur2 = 0)then
begin
if(kleur1 = 0)then
begin
kleur1 := color;
kleur1p := procent;
kleur1g := regel;
end else
begin
kleur2 := color;
kleur2p := procent;
kleur2g := regel;
end;
end else
begin
kleur1 := color;
kleur1p := procent;
kleur1g := regel;
end;
end;

end;

if(procent > kleur3p)then
begin
kleur3 := color;
kleur3p:= procent;
kleur3g:= regel;
end;
if(procent = kleur3p)then
begin
if(regel > kleur3g)then
begin
kleur3 := color;
kleur3p:= procent;
kleur3g:= regel;
end;
end;

if(kleur3p > kleur2p)then
begin
temp:= kleur3;
temp2:= kleur3p;
temp3:= kleur3g;
kleur3 := kleur2;
kleur3p:= kleur2p;
kleur3g:= kleur2g;
kleur2 := temp;
kleur2p:= temp2;
kleur2g:= temp3;
end;
if(kleur3p = kleur2p)then
begin
if(kleur3g > kleur2g)then
begin
temp:= kleur3;
temp2:= kleur3p;
temp3:= kleur3g;
kleur3 := kleur2;
kleur3p:= kleur2p;
kleur3g:= kleur2g;
kleur2 := temp;
kleur2p:= temp2;
kleur2g:= temp3;
end;
end;

if(kleur2p > kleur1p)then
begin
temp:= kleur2;
temp2:= kleur2p;
temp3:= kleur2g;
kleur2 := kleur1;
kleur2p:= kleur1p;
kleur2g:= kleur1g;
kleur1 := temp;
kleur1p:= temp2;
kleur1g:= temp3;
end;
if(kleur2p = kleur1p)then
begin
if(kleur2g > kleur1g)then
begin
temp:= kleur2;
temp2:= kleur2p;
temp3:= kleur2g;
kleur2 := kleur1;
kleur2p:= kleur1p;
kleur2g:= kleur1g;
kleur1 := temp;
kleur1p:= temp2;
kleur1g:= temp3;
end;
end;

CloseFile(myFile);


end;
end;
end;
end;
ShowMessage(inttostr(kleur1p)+'/'+inttostr(kleur1));
ShowMessage(inttostr(kleur2p)+'/'+inttostr(kleur2));
ShowMessage(inttostr(kleur3p)+'/'+inttostr(kleur3));
end;


procedure TForm1.Button5Click(Sender: TObject);
var
myFile,myFile2 : TextFile;
text : string;
master1, master2, delimiter, found1, found2 : string;
i, j, K : integer; //operating variables
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:integer;
goedvorig,goedvorig2:integer;


begin
for selecs:=0 to numforma-1 do
begin
aantal:= 0;
aantal2:= 0;
aantal3:= 0;

ChDir('C:\tmp\goed'+inttostr(selecs));
AssignFile(myFile, inttostr(kleur1)+'.txt');
Reset(myFile);

regel:= 0;
while not Eof(myFile) do
begin
ReadLn(myFile, text);
regel:= regel+1;
if(regel > 2)then
begin
delimiter :='[';
master1:= text;
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ',';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found1 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
delimiter :=',';
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ']';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found2 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
pixelkleur[aantal] := kleur1;
pixelx[aantal] := strtoint(found1);
pixely[aantal] := strtoint(found2);
aantal := aantal+1;


end;
end;
CloseFile(myFile);
AssignFile(myFile2, inttostr(kleur2)+'.txt');
Reset(myFile2);

regel:= 0;
while not Eof(myFile2) do
begin
ReadLn(myFile2, text);
regel:= regel+1;
if(regel > 2)then
begin
delimiter :='[';
master1:= text;
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ',';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found1 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
delimiter :=',';
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ']';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found2 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
pixelkleur[aantal] := kleur2;
pixelx[aantal] := strtoint(found1);
pixely[aantal] := strtoint(found2);
aantal := aantal+1;


end;
end;

CloseFile(myFile2);
AssignFile(myFile, inttostr(kleur3)+'.txt');
Reset(myFile);

regel:= 0;
while not Eof(myFile) do
begin
ReadLn(myFile, text);
regel:= regel+1;
if(regel > 2)then
begin
delimiter :='[';
master1:= text;
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ',';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found1 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
delimiter :=',';
i:= pos(delimiter, master1); //Step 1-2
if i > 0 then
begin
master2 := master1;
delete(master2,i,1); // Step 3
delimiter := ']';
j:= pos(delimiter, master2); //Step 4
if j > 0 then
begin
j := j +1;
found2 := copy(master1,(i+1),(j-i-1)); //Step 5
end
else MessageDlg('No 2nd delimiter found',mtError,[mbOK],0);
end
else MessageDlg('No 1st delimiter found',mtError,[mbOK],0);
pixelkleur[aantal] := kleur3;
pixelx[aantal] := strtoint(found1);
pixely[aantal] := strtoint(found2);
aantal := aantal+1;


end;
end;
CloseFile(myFile);
if(selecs= 0)then
begin
for i:=0 to aantal-1 do
begin
Form6.StringGrid1.RowCount:= aantal;
Form6.StringGrid1.Cells[1,i] := inttostr(pixelkleur[i]);
Form6.StringGrid1.Cells[2,i] := inttostr(pixelx[i]);
Form6.StringGrid1.Cells[3,i] := inttostr(pixely[i]);
end;
end;
if(selecs= 1)then
begin
for i:=0 to aantal-1 do
begin
Form6.StringGrid2.RowCount:= aantal;
Form6.StringGrid2.Cells[1,i] := inttostr(pixelkleur[i]);
Form6.StringGrid2.Cells[2,i] := inttostr(pixelx[i]);
Form6.StringGrid2.Cells[3,i] := inttostr(pixely[i]);
end;
end;
if(selecs= 2)then
begin
for i:=0 to aantal-1 do
begin
Form6.StringGrid3.RowCount:= aantal+aantal2+aantal3;
Form6.StringGrid3.Cells[1,i] := inttostr(pixelkleur[i]);
Form6.StringGrid3.Cells[2,i] := inttostr(pixelx[i]);
Form6.StringGrid3.Cells[3,i] := inttostr(pixely[i]);
end;
end;
end;

for i:=0 to Form6.StringGrid1.RowCount-2 do
begin
for J:=i+1 to Form6.StringGrid1.RowCount-1 do
begin
firstcolor:= strtoint(Form6.StringGrid1.cells[1,i]);
secondcolor:= strtoint(Form6.StringGrid1.cells[1,j]);
firstx:= strtoint(Form6.StringGrid1.cells[2,i]);
firsty:= strtoint(Form6.StringGrid1.cells[3,i]);
secondx:= strtoint(Form6.StringGrid1.cells[2,j]);
secondy:= strtoint(Form6.StringGrid1.cells[3,j]);
verschilx:= secondx-firstx;
verschily:= secondy-firsty;

xt:=Form1.PageControl1.TabIndex+1;
goed:= 0;
for K:=0 to Form6.StringGrid1.RowCount-1 do
begin
if(strtoint(Form6.StringGrid1.cells[1,K]) = firstcolor)then
begin
//kleur 1 is goed
if(secondcolor = img[xt].Canvas.Pixels[strtoint(Form6.StringGrid1.cells[2,K]), strtoint(Form6.StringGrid1.cells[3,K])])then
begin
goed:= goed+1;
end;
end;
end;
goedvorig2:= goed;
goed:= 0;

for K:=0 to Form6.StringGrid2.RowCount-1 do
begin
if(strtoint(Form6.StringGrid2.cells[1,K]) = firstcolor)then
begin
//kleur 1 is goed
if(strtoint(Form6.StringGrid2.cells[2,K])+verschilx > 0)AND(strtoint(Form6.StringGrid2.cells[2,K])+verschilx < img[xt].Width)AND(strtoint(Form6.StringGrid2.cells[3,K])+verschily > 0)AND(strtoint(Form6.StringGrid2.cells[3,K])+verschily < img[xt].Height)then
begin
if(secondcolor = img[xt].Canvas.Pixels[strtoint(Form6.StringGrid2.cells[2,K])+verschilx, strtoint(Form6.StringGrid2.cells[3,K])+verschily])then
begin
goed:= goed+1;
end;
end;
end;
end;
if(goedvorig2<goed)then goed:= goedvorig2;
if(goed > goedvorig)then
begin
goedvorig:= goed;
gfirstcolor:= strtoint(Form6.StringGrid1.cells[1,i]);
gsecondcolor:= strtoint(Form6.StringGrid1.cells[1,j]);
gfirstx:= strtoint(Form6.StringGrid1.cells[2,i]);
gfirsty:= strtoint(Form6.StringGrid1.cells[3,i]);
gsecondx:= strtoint(Form6.StringGrid1.cells[2,j]);
gsecondy:= strtoint(Form6.StringGrid1.cells[3,j]);
//ShowMessage('gelukt');
end;

end;
end;
ShowMessage(inttostr(goedvorig));
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);

end;



end.

i removed the other algoritmes.
i don't expect you to understand what how it does because the names i use are a dutch and english mixed. sometimes not logical.


First of all my name is Hermen.
Second part of it is: I am also dutch.
Last part, Imma going to check it our for you.

Edit:
Can you please send me the folder containing ALL files, because this is just unit1?

nielskool

2010-05-16 08:57:43

ok
wait..

ShowerThoughts

2010-05-16 08:58:26

Use someting like www.uppit.com

nielskool

2010-05-17 15:29:22

just tryed my program on a evergreen tree(to start with)
found a dtm of 2 pixels. finds all evergreen trees and as far as i know nothing else.
does anyone have somethings he can't make a good dtm of.. tell me and il try

nielsie95

2010-05-17 16:50:51

The Youtube clip looks pretty impressive :)

nielskool

2010-05-17 19:06:47

thanks, hope to improve it this week. i've got a week before my next exam is.

Wizzup?

2010-05-17 19:17:35

From: nielsie95
The Youtube clip looks pretty impressive :)


It indeed looks pretty cool!

Coh3n

2010-05-17 19:25:37

I don't think I've ever seen a DTM work for main screen object finding. :p

MylesMadness

2010-05-17 19:26:28

This looks way to cool, you need to compile this to an exe

Nava2

2010-05-17 19:51:15

You should make this into an extension for Simba ;)

nielskool

2010-05-17 21:01:24

i think i will. hmm i made this with delphi first thing todo when it is finished is to find out how extensions work with simba and more important whic language:p

tarajunky

2010-05-17 23:38:55

From: Coh3n
I don't think I've ever seen a DTM work for main screen object finding. :p


In my old Varrock East miner, I used ALL dtms to find the iron rocks. That was back with the old jagged rocks with uniform color, though. Worked great. Very accurate and fast.

I think I only needed 2 dtms to find all 4 iron rock, IIRC.

Tim0suprem0

2010-05-18 13:07:46

This looks sweet!

MylesMadness

2010-05-18 15:40:25

From: nielskool
i think i will. hmm i made this with delphi first thing todo when it is finished is to find out how extensions work with simba and more important whic language:p
Simba plugins use delphi, so its your lucky day!

Wizzup?

2010-05-18 15:42:45

From: MylesMadness
Simba plugins use delphi, so its your lucky day!


Actually, they use FPC ,but Delphi should work in most cases.

Bebe

2010-05-18 17:13:23

And if not Simba is open source for a reason ;)

nielskool

2010-05-18 19:01:09

Update:

Not limited to two selections anymore.
Convert the points to a DTM string (DTMlib of nielsie95)
Better sorting of the colors(second level sorting)

Todo:

Extend points from 2 to user set
Use all colors greater than 90%(user editable) for dtm search
Use all best colors until the pixel amount is greater than 400(user editable) for dtm search

And at the end: add tolerance.
Maybe area but i think it wil slowdown the search about 10 times
tolerance would also slow it down but if done properly than it won't be much.
With a bit luck it isn't even needed. If it is needed it will work because tolerance gives so much extra accuracy in combination with more points.

there is only one problem… i don't know the way tolerance works with those color numbers:pinch:

Wizzup?

2010-05-18 19:27:14

From: nielskool
there is only one problem… i don't know the way tolerance works with those color numbers:pinch:


See the Simba source… :)

nielskool

2010-05-18 20:00:38

Yes, that was my first option

nielskool

2010-05-19 14:12:58

i've got some bad news and good news:P

i made some improvements to the script to be more accurate, but it made the script also 40-80 times slower.

i think i know a solution to this problem but therefor i need to find a way to script something.

to be continued…:P

nielskool

2010-05-19 17:56:52

Maybe some of you can help me with it:

First i wanted to put every color of the image into an array. but than the array'ss length would me like 10 million!
This gave me stack overflow. based on this i made something that saves every color in a map, every color got his own txt file.
In this file are the coordinates of that color stored.

Well first of all to open each, read each file and edit each file takes alot of time.
So how do i store the colors of the image properly in the memory?

//Edit
Hmm maybe I kan make an array with al the colors numbers the picture has.
Then make an array of an array with the x cordinats.
And an arrar of an array with the y coordinates.
Hmm then the array would be like this:
array1 = [1221,135525,1233322,993,0]
array2[0][11] = color 1221 with x coordinate 11
array3[1][67] = color 135525 with y coordinate 67

Hmm that would solve allot i guess

/Edit2

is color:= array[10];
faster than
color:= TImage.Canvas.Pixels[x, y] ?

nielsie95

2010-05-19 18:41:06

You might want to check into ScanLines. They are a lot faster than .Pixels[x, y].. And I don't see why all colours can't be in an array? The bitmap does it too ;)

nielskool

2010-05-19 19:25:37

if i make an array with a length of 10.000.000 it gives me a stack overflow, which i have extended to the max.
but the way i described earlyer all the colors can be in an array becase:
there are not 10mil colors in a pic
i only use the colors that exist in the first selection(filtered by the colors of the other selections

if the selection is 200x200 that wold give a max of 40.000 colors

hmm i think i didn't explain that 10 mil right
example:

array[2577431][0] := 10 //x of color… point 1
array2[2577431][0] := 10 //y of color… point 1

btw thanks for the advice

and i don't know how images are stored? do they even stay in the memory or am i confused with movies now:p?

//Edit

tryed to add the new system for two houres.. didn't get it to work.
the array of array of array of integer was very confusing with the setlengths etc and i think i need to sleep a bit more:p
well Sunday i am free.. i guess/hope then i can finish it! YEA!!

nielskool

2010-05-22 20:06:15

Little update:
Colors in the array works(way faster than txt files)
Functions ready for the dtm search

Todo:
Finish the dtm search
Now it must do 150.000 calculations for every possible DTM, when i finish the new procedure it should be reduced to 500 calculations max for every DTM, so it should be allot faster!!:D

For now it is time for me to sleep(2:00AM).
I hope to finish version 1.0 today:P(release)(still limited to a 2 point DTM)

nielskool

2010-05-26 16:11:42

new topic made. relaese topic