SRL Archive - Help and Support

Looking for a DTM on a Bitmap


Coh3n

2012-01-25 02:27:16

I've been trying to think of ways to solve certain randoms (mainly Mordaut and Quiz because the rotating items change colors), and I thought of this:
  1. Create a bitmap of the area of the rotating item/object.
  2. GreyScale it, mask it, or whatever it. Save that bitmap. Maybe save multiple bitmaps.
  3. Create a DTM of the item/object for each saved bitmap (would a bitmap be better? I don't know.).
  4. During runtime, create/greyscale the bitmap of the area, then look for the DTM on the bitmap.
Could possibly do the same kind of thing with saved bitmaps of the items, and look for them on the screen, but I've never tried something like that.

So, do you think it's possible? Worth trying?

Sin

2012-01-25 09:39:07

I assume so, all we'd have to do is find the rotated DTM right and autocolour it?
Let me know if you need a test account :)

Coh3n

2012-01-25 13:03:02

From: S1N
I assume so, all we'd have to do is find the rotated DTM right and autocolour it?
Let me know if you need a test account :)
I don't need an account right now, thanks. :)

And yeah, that's all you'd do (except I'm not sure how you'd autocolor it?). But as far as I know, Simba's FindDTM looks on the client. I'm not sure if there's a way to reset the client as the bitmap, then set it back when it's done searching.

Sin

2012-01-25 14:47:02

Ah haha, i meant auto colour as Jagex changes the colour of the objects right?

mormonman

2012-01-25 15:21:28

From: Coh3n
I don't need an account right now, thanks. :)

And yeah, that's all you'd do (except I'm not sure how you'd autocolor it?). But as far as I know, Simba's FindDTM looks on the client. I'm not sure if there's a way to reset the client as the bitmap, then set it back when it's done searching.


Like this :)


....
bmp:= BitmapFromClient(x1, y1, x2, y2);
KMTarget := GetKeyMouseTarget;
ITarget := GetImageTarget;
SetTargetBitmap(bmp)
....do stuff
FreeTarget(GetImageTarget);
FreeBitmap(bmp);
SetKeyMouseTarget(KMTarget);
SetImageTarget(ITarget);

Kasi

2012-01-25 15:31:39

From: S1N
Ah haha, i meant auto colour as Jagex changes the colour of the objects right?


i dont think the greyscale on the random changes color,
just a suggestion, maybe you could make bitmaps of each item, and try findbitmapdeformed? like repeatedly in the same spot until it's recognised an item?

Home

2012-01-25 15:35:20

Someone send me an account :)


~Home

Press Play

2012-01-25 15:48:16

From: pur3b100d
i dont think the greyscale on the random changes color,
just a suggestion, maybe you could make bitmaps of each item, and try findbitmapdeformed? like repeatedly in the same spot until it's recognised an item?
This idea sounds good, although making the bitmaps of every single item might take a while.


I always thought edge detection would be good for these randoms. Because then the colour of the spinning items doesn't matter.

Sin

2012-01-25 19:54:38

From: Home
Someone send me an account :)


~Home


Damn hacker!
Leave this place now!!!

(jk.)

Narcle

2012-01-25 20:27:21

Basically getting into 3D checking. After you get pictures you use all the bitmaps that you took and check through 3D model database, but I wouldn't even know where to begin. I saw RSG doing stuff like this with Simba, but he was just drawing them.

NCDS

2012-01-25 20:30:13

From: -daazndagger-
This idea sounds good, although making the bitmaps of every single item might take a while.


I always thought edge detection would be good for these randoms. Because then the colour of the spinning items doesn't matter.


That's what I always tried with.

Coh3n

2012-01-25 20:50:15

Thanks, mormonman, I'm going to try that out. Home, I'll PM you my account.

I've also written a couple "inverse" TPA functions to get a TPA of every point in a box that isn't in the given TPA. In other words, you look for a (constant) color, and it will invert that TPA and return the points that isn't that color. This may also work for mordaut, since the background colors are constant.

If this bmp/dtm idea doesn't pan out, that's my back up. :) For those who are interested (there may be bugs, I haven't tested it that much):

program new;
{$DEFINE SMART}
{$i srl/srl.simba}
{$i srl/srl/misc/paintsmart.simba}
{$i srl/srl/misc/debug.simba}

type
TRotatingItem = record
Name: string;
Max, Min, Avg, Width, Height: Integer;
end;

function InverseTPA(tpa: TPointArray; area: TBox): TPointArray;
var
i, c, h, hh: integer;
tpaArea: TPointArray;
begin
tpaArea := TPAFromBox(area);

setLength(result, length(tpaArea));
c := 0;

h := high(tpaArea);
for i := 0 to h do
begin
if (pointInTPA(tpaArea[i], tpa)) then
continue;

result[c] := tpaArea[i];
inc(c);
end;

setLength(result, c);
end;

function InverseColors(cols, tols: TIntegerArray; area: TBox): TPointArray;
var
i: integer;
tpa: TPointArray;
atpa: T2DPointArray;
begin
setLength(atpa, length(cols));
for i := 0 to high(cols) do
findColorsTolerance(atpa[i], cols[i], area.x1, area.y1, area.x2, area.y2, tols[i]);

tpa := mergeATPA(atpa);
result := InverseTPA(tpa, area);

debugTPA(result, '');
end;

function GetRotatingItem(cols, tols: TIntegerArray; area: TBox; tries: integer; name: string): TRotatingItem;
var
c: Integer;
bounds: TBox;
tmp: TPointArray;
arr, w, h: TIntegerArray;
begin
setLength(arr, tries);
setLength(w, tries);
setLength(h, tries);

repeat
tmp := inverseColors(cols, tols, area);

bounds := getTPABounds(tmp);
w[c] := (bounds.x2 - bounds.x1);
h[c] := (bounds.y2 - bounds.y1);

arr[c] := length(tmp);
inc(c);
until(c = tries);

quickSort(arr);

result.name := name;
result.min := arr[low(arr)];
result.max := arr[high(arr)];
result.avg := averageTIA(arr);
result.width := averageTIA(w);
result.height := averageTIA(h);
end;

procedure DebugRotatingItem(item: TRotatingItem);
begin
writeln('with TRotatingItem do');
writeln('begin');
writeln(' Name := '+capitalize(item.name)+';');
writeln(' Min := '+toStr(item.min)+';');
writeln(' Max := '+toStr(item.max)+';');
writeln(' Avg := '+toStr(item.avg)+';');
writeln(' Width := '+toStr(item.width)+';');
writeln(' Height := '+toStr(item.height)+';');
writeln('end;');
end;

var
i: integer;
tia: TIntegerArray;
begin
{$IFDEF SMART}
SMART_Server := 1;
SMART_Members := False;
SMART_Signed := True;
SMART_SuperDetail := False;
{$ENDIF}

clearDebug();
activateClient();
setupSRL();

SMART_ClearCanvas();

for i := 1 to 8 do
begin
SMART_DrawBoxEx(false, MD_SmallBox(i), clGreen);

debugRotatingItem(getRotatingItem(
[4410947, 5003083], [10, 10], MD_SmallBox(i), 30, 'Mordaut '+toStr(i)));

writeln('');
end;
end.
It won't compile because it's missing MD_SmallBox and a couple grid functions I wrote to create grids (will be useful for inventory and bank later).

Press Play

2012-01-26 05:14:07

Very smart thinking about the inverse TPA business! I like it very much :) I might see if I can get some accounts in the randoms on purpose for you guys once you've got everything together :)

Coh3n

2012-02-01 00:51:46

Just an update for you guys: I've got the idea in the OP working, except it's a little different. What I do is use returnTPAExceptColors (inverseColors in my last post) to paint the TPA on a bitmap. I then look for the DTM on the bitmap. Since I painted red, the color of the object on the MS doesn't matter because it'll always look for a red item. So basically, it's looking for the DTM shape rather than colors.

So far, it's working well for Mordaut; although, there are some puzzles with items that are VERY similar in shape, so I may try using bitmaps instead of DTMs.


program new;
{$i srl/srl.simba}
{$i ../common.simba}
{$i ../mordaut.simba}

procedure debugBitmap(from: TBox);
var
bmp, dtm, i, w, h, x, y, t: integer;
oldTarget: integer;
tpa: TPointArray;
aFound: extended;
begin
getClientDimensions(w, h);

dtm := DTMFromString('mFQEAAHicnccxDoAgEADBAyOIBmJlaaIFsbLx/2/TNVxDe5tMsVlEJowY4OClFRHUjEUl7Niw6v8VZByoOHHhxoPXwJIz6PoAtLsOtw==');
bmp := createBitmap(w, h);
fastDrawClear(bmp, clBlack);

t := (getSystemTime + 10000);

repeat
tpa := returnTPAExceptColors([4410947, 5003083, 5200206], [20, 20, 20], from);
drawTPABitmap(bmp, tpa, clRed);

oldTarget := getImageTarget();
setTargetBitmap(bmp);

if (findDTMRotatedAlternating(dtm, x, y, from.x1, from.y1, from.x2, from.y2, -Pi, Pi, Pi/30, aFound)) then
begin
writeln('found scimitar');
break;
end;

setImageTarget(oldTarget);

fastDrawClear(bmp, clBlack);

{
displayDebugImgWindow(w, h);
drawBitmapDebugImg(bmp);
}
until(getSystemTime > t);

mmouse(x, y, 5, 5);

//freeBitmap(bmp);
freeDTM(dtm);
end;

var
i: integer;
begin
clearDebug();
activateClient();
setupSRL();

debugBitmap(MD_SmallBox(1));
end.

Narcle

2012-02-01 01:01:29

http://villavu.com/forum/showthread.php?t=73666

^ what about that?

Coh3n

2012-02-01 01:13:02

From: Narcle
http://villavu.com/forum/showthread.php?t=73666

^ what about that?
They're along the same lines I think, but mine doesn't use the colors of the object. Wouldn't work because the colors are constantly changing.