Kantenerkennung z.B. hier:
http://www.swissdelphicenter.ch/torry/s ... hp?id=1704" onclick="window.open(this.href);return false;
Hab's kurz testweise mit OPBitmap versucht auf Laz zu übertragen:
Klappt!!!
Nen TButton und ein TImage auf die Form und "opbitmapforlaz" in die Package - Abhängigkeit des Projekts aufnehmen.
Code: Alles auswählen
unit Unit1;
{$mode delphi}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, opbitmap, opbitmapformats, lazbridge,
Buttons, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
type
TRGBTripleArray = array[0..10000] of TRGBTriple;
PRGBTripleArray = ^TRGBTripleArray;
T3x3FloatArray = array[0..2] of array[0..2] of Extended;
implementation
function Convolve(ABitmap: TOPBitmap; AMask: T3x3FloatArray;
ABias: Integer): TOPBitmap;
var
LRow1, LRow2, LRow3, LRowOut: PRGBTripleArray;
LRow, LCol: integer;
LNewBlue, LNewGreen, LNewRed: Extended;
LCoef: Extended;
begin
LCoef := 0;
for LRow := 0 to 2 do
for LCol := 0 to 2 do
LCoef := LCoef + AMask[LCol, LRow];
if LCoef = 0 then LCoef := 1;
Result := TOPBitmap.Create;
Result.Width := ABitmap.Width - 2;
Result.Height := ABitmap.Height - 2;
Result.PixelFormat := pf24bit;
LRow2 := ABitmap.ScanLine[0];
LRow3 := ABitmap.ScanLine[1];
for LRow := 1 to ABitmap.Height - 2 do
begin
LRow1 := LRow2;
LRow2 := LRow3;
LRow3 := ABitmap.ScanLine[LRow + 1];
LRowOut := Result.ScanLine[LRow - 1];
for LCol := 1 to ABitmap.Width - 2 do
begin
LNewBlue :=
(LRow1[LCol - 1].rgbtBlue * AMask[0,0]) + (LRow1[LCol].rgbtBlue * AMask[1,0]) +
(LRow1[LCol + 1].rgbtBlue * AMask[2,0]) +
(LRow2[LCol - 1].rgbtBlue * AMask[0,1]) + (LRow2[LCol].rgbtBlue * AMask[1,1]) +
(LRow2[LCol + 1].rgbtBlue * AMask[2,1]) +
(LRow3[LCol - 1].rgbtBlue * AMask[0,2]) + (LRow3[LCol].rgbtBlue * AMask[1,2]) +
(LRow3[LCol + 1].rgbtBlue * AMask[2,2]);
LNewBlue := (LNewBlue / LCoef) + ABias;
if LNewBlue > 255 then
LNewBlue := 255;
if LNewBlue < 0 then
LNewBlue := 0;
LNewGreen :=
(LRow1[LCol - 1].rgbtGreen * AMask[0,0]) + (LRow1[LCol].rgbtGreen * AMask[1,0]) +
(LRow1[LCol + 1].rgbtGreen * AMask[2,0]) +
(LRow2[LCol - 1].rgbtGreen * AMask[0,1]) + (LRow2[LCol].rgbtGreen * AMask[1,1]) +
(LRow2[LCol + 1].rgbtGreen * AMask[2,1]) +
(LRow3[LCol - 1].rgbtGreen * AMask[0,2]) + (LRow3[LCol].rgbtGreen * AMask[1,2]) +
(LRow3[LCol + 1].rgbtGreen * AMask[2,2]);
LNewGreen := (LNewGreen / LCoef) + ABias;
if LNewGreen > 255 then
LNewGreen := 255;
if LNewGreen < 0 then
LNewGreen := 0;
LNewRed :=
(LRow1[LCol - 1].rgbtRed * AMask[0,0]) + (LRow1[LCol].rgbtRed * AMask[1,0])
+ (LRow1[LCol + 1].rgbtRed * AMask[2,0]) +
(LRow2[LCol - 1].rgbtRed * AMask[0,1]) + (LRow2[LCol].rgbtRed * AMask[1,1])
+ (LRow2[LCol + 1].rgbtRed * AMask[2,1]) +
(LRow3[LCol - 1].rgbtRed * AMask[0,2]) + (LRow3[LCol].rgbtRed * AMask[1,2])
+ (LRow3[LCol + 1].rgbtRed * AMask[2,2]);
LNewRed := (LNewRed / LCoef) + ABias;
if LNewRed > 255 then
LNewRed := 255;
if LNewRed < 0 then
LNewRed := 0;
LRowOut[LCol - 1].rgbtBlue := trunc(LNewBlue);
LRowOut[LCol - 1].rgbtGreen := trunc(LNewGreen);
LRowOut[LCol - 1].rgbtRed := trunc(LNewRed);
end;
end;
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
LMask: T3x3FloatArray;
OPP:TOPPicture;
OPB:TOPBitmap;
begin
LMask[0,0] := -1;
LMask[1,0] := -1;
LMask[2,0] := -1;
LMask[0,1] := -1;
LMask[1,1] := 8;
LMask[2,1] := -1;
LMask[0,2] := -1;
LMask[1,2] := -1;
LMask[2,2] := -1;
OPP:=TOPPicture.Create;
OPP.LoadFromFile('/home/theo/logoop.bmp');
OPP.Bitmap.PixelFormat:=pf24bit;
OPB:=Convolve(OPP.Bitmap, LMask, 0);
AssignOpBitmapToBitmap(OPB,Image1.Picture.Bitmap);
OPB.free;
OPP.free;
end;
initialization
{$I unit1.lrs}
end.