SRL Archive - Bugs

FindColoredAreaTolerance


weequ

2011-11-26 11:31:19

  WriteLn(IntTOStr(CountColor(5330001, MMX1, MMY1, MMX2, MMY2)));
if FindColoredAreaTolerance(Ax, Ay, 5330001, MMX1, MMY1, MMX2, MMY2, 4000, 0) then MoveMouse(AX, AY);
Prints 2354 but still moves the mouse.

I made few versions of this but they are all buggy or too slow.

Nava2

2011-11-26 11:37:28


function TMFinder.FindColoredAreaTolerance(var x, y: Integer; Color, xs, ys, xe, ye, MinArea, tol: Integer): Boolean;
var
PtrData: TRetData;
Ptr, Before: PRGB32;
PtrInc: Integer;
dX, dY, xx, yy, fx, fy, Count: Integer;
clR, clG, clB : Byte;
H1, S1, L1: Extended;
NotFound : Boolean;

compare: TCTSCompareFunction;
ctsinfo: TCTSInfo;

label Hit;


begin
Result := false;
// checks for valid xs,ys,xe,ye? (may involve GetDimensions)
DefaultOperations(xs,ys,xe,ye);

// calculate delta x and y
dX := xe - xs;
dY := ye - ys;
//next, convert the color to r,g,b
ColorToRGB(Color, clR, clG, clB);
if Cts = 2 then
RGBToHSL(clR,clG,clB,H1,S1,L1);
PtrData := TClient(Client).IOManager.ReturnData(xs, ys, dX + 1, dY + 1);

// Do we want to "cache" these vars?
// We will, for now. Easier to type.
Ptr := PtrData.Ptr;
PtrInc := PtrData.IncPtrWith;
Count := 0;

ctsinfo := Create_CTSInfo(Self.CTS, Color, Tol, hueMod, satMod);
compare := Get_CTSCompare(Self.CTS);

for yy := ys to ye do
begin;
for xx := xs to xe do
begin;
NotFound := False;
// Colour comparison here.
if compare(ctsinfo, Ptr) then
begin
Before := Ptr;
for fy := yy to ye do
begin
for fx := xx to xe do
begin
Inc(Ptr);
if compare(ctsinfo, Ptr) then
begin
NotFound := True;
Break;
end;
Inc(Count);
if Count >= MinArea then
goto Hit;
end;

if NotFound then
begin
Ptr := Before;
Break;
end;
Inc(Ptr, PtrInc);
end;
end;
Inc(Ptr);
end;
Inc(Ptr, PtrInc);
end;

Result := False;
Free_CTSInfo(ctsinfo);
TClient(Client).IOManager.FreeReturnData;
Exit;

Hit:
Result := True;
x := xx;
y := yy;
Free_CTSInfo(ctsinfo);
TClient(Client).IOManager.FreeReturnData;
end;

https://github.com/MerlijnWajer/Simba/blob/master/Units/MMLCore/finder.pas

weequ

2011-11-26 11:39:18

Yup something must be wrong there. Couldn't understand the code too well :/

I think we need to use "Flood fill" algorithm.

mastaraymond

2011-11-26 11:43:58

From: weequ
Yup something must be wrong there. Couldn't understand the code too well :/

I think we need to use "Flood fill" algorithm.

FindColorsTolerance and FloodFillTPA?

weequ

2011-11-26 11:46:55

From: mastaraymond
FindColorsTolerance and FloodFillTPA?
Well I didn't know Simba had FloodFill algorithm. That's an option but I think it could be optimized to be quite much faster.

For example: Stop filling when it reaches minarea.

Also I thoght that we wouldn't have to scan every pixel if the MinArea is greater than 1. (If MinArea is 100 then could just leave 9*10 boxes unscanned)

mastaraymond

2011-11-26 11:57:49

From: weequ
Well I didn't know Simba had FloodFill algorithm. That's an option but I think it could be optimized to be quite much faster.

For example: Stop filling when it reaches minarea.

Also I thoght that we wouldn't have to scan every pixel if the MinArea is greater than 1. (If MinArea is 100 then could just leave 9*10 boxes unscanned)

FindColorsTolerance is blazing fast (try to avoid tol 2 and 3 with that aspect)