Brandon
05-09-2012, 05:43 AM
Why does SRL not have a function for this already? I'm struggling to write one lol. I use the below to gather my minimap bitmaps then I use another function below to Check whether they match..
Problem: It's too accurate -_- So I need to know how to check neighbouring pixels or something to make it less accurate. Basically the below will check the colours of the bitmap with a tolerance but I noticed that not only does the colours change every so often (This is not a problem) but rather the minimap shifts ever so slightly to a direction.. Anything more than a 5 pixels shift makes it return false..
Basically if I'm standing on a square and I run the below function, it will grab my bitmap. If I move 4 squares, the bitmaps don't match until I'm within 2 - 3 squares of my old position.
How can I fix it. The entire script is on this thread: http://villavu.com/forum/showthread.php?t=81885
Procedure GetMinimap(var Map: Integer);
var
TPA, Draw: TPointArray;
TIA: TIntegerArray;
I, BMP: Integer;
begin
BMP:= CreateBitmap(MMX2 - MMX1 + 1, MMY2 - MMY1 + 1);
TPA:= TPAFromBox(MMBox);
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 75.0, MMCX, MMCY);
TIA:= GetColors(TPA);
TPA:= TPAFromBox(IntToBox(0, 0, MMX2 - MMX1, MMY2 - MMY1));
DrawTPABitmap(BMP, TPA, 0);
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 75.0, (MMX2 - MMX1)/2, (MMY2 - MMY1)/2);
SetLength(DRAW, 1);
For I:= 0 To High(TPA) do
begin
Draw[0]:= TPA[I];
DrawTPABitmap(BMP, Draw, TIA[I]);
end;
For I:= 0 To High(TPA) do
begin
if (SimilarColors(TIA[I], 67075, 20)) then //If similar to black, make it completely black.
FastSetPixel(BMP, TPA[I].X, TPA[I].Y, clBlack);
end;
Map:= CopyBitmap(Bmp);
FreeBitmap(BMP);
end;
Function FindBitmapInBitmap(XBMP, YBMP, Tol: Integer): Boolean;
var
Similar, NotSimilar, I, J, X: Integer;
BMPC1, BMPC2: T2DIntegerArray;
begin
try
BMPC1:= GetBitmapAreaColors(XBMP, 0, 0, 150, 150);
BMPC2:= GetBitmapAreaColors(YBMP, 0, 0, 150, 150);
X:= High(BMPC1);
For I:= 0 To 150 do
begin
For J:= 0 To 150 do
begin
if ((SimilarColors(BMPC1[J][I], 0, 20)) or (SimilarColors(BMPC2[J][I], 0, 20))) then //If similar to black, ignore it..
Continue;
if (SimilarColors(BMPC1[J][I], BMPC2[J][I], Tol)) then
Inc(Similar)
else
Inc(NotSimilar);
end;
end;
Result:= Similar > NotSimilar;
except
Result:= False;
end;
end;
Problem: It's too accurate -_- So I need to know how to check neighbouring pixels or something to make it less accurate. Basically the below will check the colours of the bitmap with a tolerance but I noticed that not only does the colours change every so often (This is not a problem) but rather the minimap shifts ever so slightly to a direction.. Anything more than a 5 pixels shift makes it return false..
Basically if I'm standing on a square and I run the below function, it will grab my bitmap. If I move 4 squares, the bitmaps don't match until I'm within 2 - 3 squares of my old position.
How can I fix it. The entire script is on this thread: http://villavu.com/forum/showthread.php?t=81885
Procedure GetMinimap(var Map: Integer);
var
TPA, Draw: TPointArray;
TIA: TIntegerArray;
I, BMP: Integer;
begin
BMP:= CreateBitmap(MMX2 - MMX1 + 1, MMY2 - MMY1 + 1);
TPA:= TPAFromBox(MMBox);
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 75.0, MMCX, MMCY);
TIA:= GetColors(TPA);
TPA:= TPAFromBox(IntToBox(0, 0, MMX2 - MMX1, MMY2 - MMY1));
DrawTPABitmap(BMP, TPA, 0);
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 75.0, (MMX2 - MMX1)/2, (MMY2 - MMY1)/2);
SetLength(DRAW, 1);
For I:= 0 To High(TPA) do
begin
Draw[0]:= TPA[I];
DrawTPABitmap(BMP, Draw, TIA[I]);
end;
For I:= 0 To High(TPA) do
begin
if (SimilarColors(TIA[I], 67075, 20)) then //If similar to black, make it completely black.
FastSetPixel(BMP, TPA[I].X, TPA[I].Y, clBlack);
end;
Map:= CopyBitmap(Bmp);
FreeBitmap(BMP);
end;
Function FindBitmapInBitmap(XBMP, YBMP, Tol: Integer): Boolean;
var
Similar, NotSimilar, I, J, X: Integer;
BMPC1, BMPC2: T2DIntegerArray;
begin
try
BMPC1:= GetBitmapAreaColors(XBMP, 0, 0, 150, 150);
BMPC2:= GetBitmapAreaColors(YBMP, 0, 0, 150, 150);
X:= High(BMPC1);
For I:= 0 To 150 do
begin
For J:= 0 To 150 do
begin
if ((SimilarColors(BMPC1[J][I], 0, 20)) or (SimilarColors(BMPC2[J][I], 0, 20))) then //If similar to black, ignore it..
Continue;
if (SimilarColors(BMPC1[J][I], BMPC2[J][I], Tol)) then
Inc(Similar)
else
Inc(NotSimilar);
end;
end;
Result:= Similar > NotSimilar;
except
Result:= False;
end;
end;