Skip to content

Commit

Permalink
Use properties in matrix methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Dec 17, 2024
1 parent fafa1ca commit 96b410f
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 319 deletions.
217 changes: 116 additions & 101 deletions Source/script/imports/simba.import_matrix.pas

Large diffs are not rendered by default.

40 changes: 0 additions & 40 deletions Source/script/imports/simba.import_target.pas
Original file line number Diff line number Diff line change
Expand Up @@ -764,30 +764,6 @@ procedure _LapeTarget_GetColorsMatrix(const Params: PParamArray; const Result: P
PIntegerMatrix(Result)^ := PSimbaTarget(Params^[0])^.GetColorsMatrix(PBox(Params^[1])^);
end;

(*
TTarget.HasImage
----------------
```
function TTarget.HasImage(Image: TSimbaImage; Tolerance: Single; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers; MinCount: Integer = 1; Bounds: TBox = [-1,-1,-1,-1]): Boolean;
```
*)
procedure _LapeTarget_HasImage1(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := PSimbaTarget(Params^[0])^.HasImage(PSimbaImage(Params^[1])^, PSingle(Params^[2])^, PColorSpace(Params^[3])^, PChannelMultipliers(Params^[4])^, PInteger(Params^[5])^, PBox(Params^[6])^);
end;

(*
TTarget.HasImage
----------------
```
function TTarget.HasImage(Image: TSimbaImage; Tolerance: Single; MinCount: Integer = 1; Bounds: TBox = [-1,-1,-1,-1]): Boolean;
```
*)
procedure _LapeTarget_HasImage2(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := PSimbaTarget(Params^[0])^.HasImage(PSimbaImage(Params^[1])^, PSingle(Params^[2])^, PInteger(Params^[3])^, PBox(Params^[4])^);
end;

(*
TTarget.FindImage
-----------------
Expand Down Expand Up @@ -848,18 +824,6 @@ procedure _LapeTarget_FindTemplate(const Params: PParamArray; const Result: Poin
PPoint(Result)^ := PSimbaTarget(Params^[0])^.FindTemplate(PSimbaImage(Params^[1])^, PSingle(Params^[2])^, PBox(Params^[3])^);
end;

(*
TTarget.HasTemplate
--------------------
```
function TTarget.HasTemplate(Image: TImage; MinMatch: Single; Bounds: TBox = [-1,-1,-1,-1]): Boolean;
```
*)
procedure _LapeTarget_HasTemplate(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := PSimbaTarget(Params^[0])^.HasTemplate(PSimbaImage(Params^[1])^, PSingle(Params^[2])^, PBox(Params^[3])^);
end;

(*
TTarget.FindDTM
---------------
Expand Down Expand Up @@ -1162,11 +1126,7 @@ procedure ImportTarget(Script: TSimbaScript);
addGlobalFunc('function TTarget.FindImageEx(Image: TImage; Tolerance: Single; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers; MaxToFind: Integer = -1; Bounds: TBox = [-1,-1,-1,-1]): TPointArray; overload', @_LapeTarget_FindImageEx2);
addGlobalFunc('function TTarget.FindImage(Image: TImage; Tolerance: Single; Bounds: TBox = [-1,-1,-1,-1]): TPoint; overload', @_LapeTarget_FindImage1);
addGlobalFunc('function TTarget.FindImage(Image: TImage; Tolerance: Single; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers; Bounds: TBox = [-1,-1,-1,-1]): TPoint; overload', @_LapeTarget_FindImage2);
addGlobalFunc('function TTarget.HasImage(Image: TImage; Tolerance: Single; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers; MinCount: Integer = 1; Bounds: TBox = [-1,-1,-1,-1]): TPoint; overload', @_LapeTarget_HasImage1);
addGlobalFunc('function TTarget.HasImage(Image: TImage; Tolerance: Single; MinCount: Integer = 1; Bounds: TBox = [-1,-1,-1,-1]): TPoint; overload', @_LapeTarget_HasImage2);

addGlobalFunc('function TTarget.FindTemplate(Templ: TImage; out Match: Single; Bounds: TBox = [-1,-1,-1,-1]): TPoint', @_LapeTarget_FindTemplate);
addGlobalFunc('function TTarget.HasTemplate(Templ: TImage; MinMatch: Single; Bounds: TBox = [-1,-1,-1,-1]): Boolean', @_LapeTarget_HasTemplate);

addGlobalFunc('function TTarget.FindDTM(DTM: TDTM; Bounds: TBox = [-1,-1,-1,-1]): TPoint', @_LapeTarget_FindDTM);
addGlobalFunc('function TTarget.FindDTMEx(DTM: TDTM; MaxToFind: Integer = -1; Bounds: TBox = [-1,-1,-1,-1]): TPointArray', @_LapeTarget_FindDTMEx);
Expand Down
12 changes: 1 addition & 11 deletions Source/simba.finder_image.pas
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function FindImageOnBuffer(var Limit: TLimit;
SearchWidth, SearchHeight: Integer): TPointArray;

function FindTemplateOnTarget(constref Target: TSimbaTarget; Templ: TSimbaImage; out Match: Single; Bounds: TBox): TPoint;
function HasTemplateOnTarget(constref Target: TSimbaTarget; Templ: TSimbaImage; MinMatch: Single; Bounds: TBox): Boolean;

var
ImageFinderMultithreadOpts: record
Expand Down Expand Up @@ -288,23 +287,14 @@ function FindTemplateOnTarget(constref Target: TSimbaTarget; Templ: TSimbaImage;
try
Mat := MatchTemplate(Image, Templ, TM_CCOEFF_NORMED);

Best := Mat.ArgMax();
Best := Mat.ArgMax;
Match := Mat[Best.Y, Best.X];
Result := Best + Bounds.TopLeft;
finally
Image.Free();
end;
end;

function HasTemplateOnTarget(constref Target: TSimbaTarget; Templ: TSimbaImage; MinMatch: Single; Bounds: TBox): Boolean;
var
Match: Single;
begin
FindTemplateOnTarget(Target, Templ, Match, Bounds);

Result := Match >= MinMatch;
end;

initialization
ImageFinderMultithreadOpts.Enabled := True;
ImageFinderMultithreadOpts.SliceHeight := 250;
Expand Down
6 changes: 3 additions & 3 deletions Source/simba.matchtemplate_ccoeff.pas
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ function __MatchTemplate_CCOEFF(Image, Template: TIntegerMatrix; Normed: Boolean

if not Normed then
begin
mR := TemplChannels.R.Mean();
mG := TemplChannels.G.Mean();
mB := TemplChannels.B.Mean();
mR := TemplChannels.R.Mean;
mG := TemplChannels.G.Mean;
mB := TemplChannels.B.Mean;
tplSigma := 0;
end else
begin
Expand Down
18 changes: 0 additions & 18 deletions Source/simba.target.pas
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,9 @@ TSimbaTarget = record
function FindImage(Image: TSimbaImage; Tolerance: Single; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers; ABounds: TBox): TPoint; overload;
function FindImageEx(Image: TSimbaImage; Tolerance: Single; MaxToFind: Integer; ABounds: TBox): TPointArray; overload;
function FindImageEx(Image: TSimbaImage; Tolerance: Single; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers; MaxToFind: Integer; ABounds: TBox): TPointArray; overload;
function HasImage(Image: TSimbaImage; Tolerance: Single; MinCount: Integer; ABounds: TBox): Boolean; overload;
function HasImage(Image: TSimbaImage; Tolerance: Single; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers; MinCount: Integer; ABounds: TBox): Boolean; overload;

// Finder - template
function FindTemplate(Templ: TSimbaImage; out Match: Single; ABounds: TBox): TPoint;
function HasTemplate(Templ: TSimbaImage; MinMatch: Single; ABounds: TBox): Boolean;

// Finder - dtm
function FindDTM(DTM: TDTM; ABounds: TBox): TPoint;
Expand Down Expand Up @@ -554,26 +551,11 @@ function TSimbaTarget.FindImage(Image: TSimbaImage; Tolerance: Single; ColorSpac
Result := TPoint.Create(-1, -1);
end;

function TSimbaTarget.HasImage(Image: TSimbaImage; Tolerance: Single; MinCount: Integer; ABounds: TBox): Boolean;
begin
Result := Length(FindImageOnTarget(Self, Image, ABounds, DefaultColorSpace, Tolerance, DefaultMultipliers, MinCount)) >= MinCount;
end;

function TSimbaTarget.HasImage(Image: TSimbaImage; Tolerance: Single; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers; MinCount: Integer; ABounds: TBox): Boolean;
begin
Result := Length(FindImageOnTarget(Self, Image, ABounds, ColorSpace, Tolerance, Multipliers, MinCount)) >= MinCount;
end;

function TSimbaTarget.FindTemplate(Templ: TSimbaImage; out Match: Single; ABounds: TBox): TPoint;
begin
Result := FindTemplateOnTarget(Self, Templ, Match, ABounds);
end;

function TSimbaTarget.HasTemplate(Templ: TSimbaImage; MinMatch: Single; ABounds: TBox): Boolean;
begin
Result := HasTemplateOnTarget(Self, Templ, MinMatch, ABounds);
end;

function TSimbaTarget.FindDTMEx(DTM: TDTM; MaxToFind: Integer; ABounds: TBox): TPointArray;
begin
Result := FindDTMOnTarget(Self, DTM, ABounds, MaxToFind);
Expand Down
Loading

0 comments on commit 96b410f

Please sign in to comment.