unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, Grids, Spin;
type
{ TForm1 }
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Label1: TLabel;
Label2: TLabel;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure floodFill_(x,y,fillColor,oldColor: integer);
procedure quadratmalen(image,top_,left_,kantenlaenge,farbe:integer);
procedure AddFound(nr,x,y,wert:integer);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
b,h:integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
b:=image1.width; h:=image1.height;
// Breite und Höhe der Imagefelder
image2.width:=b; image2.height:=h;
image3.width:=b; image3.height:=h;
image4.width:=b; image4.height:=h;
image1.canvas.brush.color:=clblack;
// Hintergrundfarben
image2.canvas.brush.color:=clblack;
image3.canvas.brush.color:=clblack;
image4.canvas.brush.color:=clwhite;
image1.canvas.fillrect(rect(0,0,b,h));
// Rechteck mit obigen Farben ausfüllen
image2.canvas.fillrect(rect(0,0,b,h));
image3.canvas.fillrect(rect(0,0,b,h));
image4.canvas.fillrect(rect(0,0,b,h));
image1.Picture.loadfromfile('
1sw.bmp');
// Bilder hochladen
image2.Picture.loadfromfile('
pic2.bmp');
form1.caption:= '
Bildanalyse-Suche nach Vergleichsschwankungen';
end;
procedure tform1.floodFill_(x,y,fillColor,oldColor: integer);
begin
with image3.canvas
do
if (pixels[x,y]=oldColor)
then
begin
Pixels[x,y]:= fillcolor;
floodFill_(x+1,y, clred, oldColor);
floodFill_(x-1,y, clred, oldColor);
floodFill_(x,y+1, clred, oldColor);
floodFill_(x,y-1, clred, oldColor);
end;
end;
procedure tform1.quadratmalen(image,top_,left_,kantenlaenge,farbe:integer);
var
x,
// Koordinaten
y
:integer;
begin
x:=stringgrid1.cells[1,nr];
// Koordinaten aus stringrid nehmen - klappt nicht!
y:=stringgrid1.cells[2,nr];
case image
of
1:
with form1.image1.canvas
do
begin
end;
2:
with form1.image2.canvas
do
begin
end;
3:
with form1.image3.canvas
do
begin
quadratmalen(3,round(x-(spinedit2.value/2)),round(y-(spinedit2.value/2)),spinedit1.value,clred);
// Quadratmalen mittels zeichnen der 4 Linien - klappt nicht!
pen.color:=clred;
moveto(round(x-spinedit2.value/2),round (y-spinedit2.value/2));
// klappt nicht!
lineto(round(x+spinedit2.value/2),round (y-spinedit2.value/2));
lineto(round(x+spinedit2.value/2),round (y+spinedit2.value/2));
lineto(round(x-spinedit2.value/2),round (y+spinedit2.value/2));
lineto(round(x-spinedit2.value/2),round (y-spinedit2.value/2));
end;
4:
with form1.image4.canvas
do
begin
end;
end;
end;
procedure TForm1.Addfound (nr,x,y,wert:Integer);
Begin
If stringgrid1.rowcount < (nr+1)
then
stringgrid1.rowcount:= nr+1;
stringgrid1.cells[0,0]:='
Nr.';
stringgrid1.cells[1,0]:='
X';
stringgrid1.cells[2,0]:='
Y';
stringgrid1.cells[3,0]:='
Diff-Wert';
stringgrid1.cells[0,nr]:=inttostr(Nr);
stringgrid1.cells[1,nr]:=inttostr(X);
stringgrid1.cells[2,nr]:=inttostr(Y);
stringgrid1.cells[3,nr]:=inttostr(Wert);
end;
procedure TForm1.Button1Click(Sender: TObject);
Var
farbe1,
// Pixelfarbe im Image1
farbe2,
// Pixelfarbe im Image2
wert,
// Differenzwert
schwellwert,
// Schwellwert zum Vergleich
x,
// Laufindex
y,
// Laufindex
z,
// Zähler
kante
:integer;
begin
schwellwert:=spinedit1.value;
// Voreinstellung 10
kante:=spinedit2.value;
z:=0;
// Zähler auf Null gesetzt
For x:=0
to b-1
do // Pixelweise Bilder auslesen
Begin
For y:=0
to h-1
do
Begin
farbe1 := image1.canvas.pixels[x,y];
// Farbe merken
farbe2 := image2.canvas.pixels[x,y];
wert:= (farbe1
and clred)-(farbe2
and clred);
// Differenzwert
If wert > schwellwert
then // mit Schwellwert vergleichen
begin
inc(z);
// Zähler hochzählen
AddFound(z,x,y,wert);
// Daten in Stringgrid einfügen
end;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
end.