SRL Archive - SRL Archives

30 Nov ChooseOption Fix


Wizzup?

2011-11-30 16:11:55

Narcle and I have done some more work on stabilizing ChooseOption. it should be a lot more stable now. (Update your SRL)

If it is slow you either don't have Simba 975 (which is not yet released, but will be soon) or Simba 0.98-rc7 or higher. If you don't have a Simba that accelerates ChooseOption you will see a warning at compile time.

So without a newer Simba it will be slow (max 1s!), but it will still work a lot better than the previous ChooseOption fix. Or it should anyway.

I'll update this post when Simba 975 is in the autoupdater.

Feedback is welcome.

E: If you're updating your Simba, you should consider trying Simba 0.98-rc7. ( http://villavu.com/forum/showthread.php?p=852119 )

RISK

2011-11-30 16:22:56

Thank you, Wizzup and Narcle.

piper101

2011-11-30 16:24:24

Thank you, much appreciated.

[XoL]

2011-11-30 16:35:26

Thank you both :D

Fire Monkey

2011-11-30 16:43:39

Great fix, thanks guys.. much appreciated :)

Wyn

2011-11-30 16:55:25

Updated SRL. Updated Simba.

Chooseoption still broken.

How I test; OpenBankNPC at edgeville.

Sigh.

Wizzup?

2011-11-30 16:56:42

From: wyn10
Updated SRL. Updated Simba.

Chooseoption still broken.

How I test; OpenBankNPC at edgeville.

Sigh.


Picture would be helpful.

Wyn

2011-11-30 17:07:26

From: Wizzup?
Picture would be helpful.



Here's 3.


legoace

2011-11-30 17:14:55

Thanks for the fix guys; working well for me throughout Falador.

kingarabian

2011-11-30 17:27:05

Will test when I get home from uni.

chrisiyyi

2011-11-30 18:08:02

yaa thnx for the info

Trippeh

2011-11-30 18:50:23

Deposit(a, b, true) = broke

Its depositing 1 by 1.. when it should be selecting Deposit-All or when unique Deposit..


::EDIT::
In SRL Bank:
I changed this:
WaitOptionMulti(['Deposit-All', 'Deposit'], 200);

to this:
WaitOptionMulti(['Deposit-All', 't-All'], 200);

and then it worked but than there's this issue:
if there's an item (unique) in your inventory you can't deposit it unless you leave the bug in SRL.. but then its depositing 1 by 1. been trying all sorts of things in SRL bank but no go..

tried some other things but no succes..
::END EDIT::

Tickyy

2011-11-30 18:57:57

From: Trippeh
Deposit(a, b, true) = broke

meaning:
if there's an item (unique) in your inventory you can't deposit it unless you leave the bug in SRL.. but then its depositing 1 by 1. been trying all sorts of things in SRL bank but no go..


This ^ and i still get the warning even after i downloaded rc7. I am not sure if that's supposed to be like that :duh:

Trippeh

2011-11-30 19:00:51

From: Tickyy
This ^ and i still get the warning even after i downloaded rc7. I am not sure if that's supposed to be like that :duh:


download RC8 mate ;-)

YoHoJo

2011-11-30 19:05:31

Tickyy/Everone getting the not accelerated warning.
Go check out the newest Simba download thread again, wizzup edited it with a working link to proper version.

Silent

2011-11-30 20:41:57

OpenBankNPC still fails… Here is an image:

Wizzup?

2011-12-01 05:40:33

From: Silent SPY
OpenBankNPC still fails… Here is an image:


I'm beginning to think it might just not find the Choose Option menu itself, because that image works for me (cropped to chooseoption):


Compiled successfully in 33 ms.
Size: 116, 102
Time: 1
6, 6 : Talk-to Banker
67, 30 : Bank Banker
62, 44 : Collect Banker
38, 62 : Walk here
29, 79 : Examine Banker
44, 91 : Cancel
115, 101 :
Time: 63
Successfully executed.

(You can safely disregard the olive colour there)


Wizzup?

2011-12-01 06:52:15

For those who want to test:

program new;

// HERE BE DRAGONS
procedure FilterUpTextByCharacteristics(bmp: TMufasaBitmap);
var
x,y: Integer;
begin
{ Filter 2
This performs a `simple' filter.
What we are doing here is simple checking that if Colour[x,y] is part
of the uptext, then so must Colour[x+1,y+1], or Colour[x+1,y+1] is a shadow.
if it is neither, we can safely remove it.

XXX: This causes the previously mentioned fuckup.
}
for y := 0 to bmp.Height - 2 do
for x := 0 to bmp.Width - 2 do
begin
if bmp.fastgetpixel(x,y) = clPurple then
continue;
if bmp.fastgetpixel(x,y) = clBlack then
continue;
if (bmp.fastgetpixel(x,y) <> bmp.fastgetpixel(x+1,y+1)) and
(bmp.fastgetpixel(x+1,y+1) <> clpurple) then
bmp.fastsetpixel(x,y,{clAqua}0);
end;

{
Remove false shadow. (A shadow isn't larger than 1 pixel. So if x, y is
shadow, thex x+1, y+1 can't be shadow. If it is, we can safely remove it.
(As well as x+2, y+2, etc).

The tricky part of the algorithm is that it starts at the bottom,
removing shadow point x,y if x-1,y-1 is also shadow.
}

for y := bmp.Height - 1 downto 1 do
for x := bmp.Width - 1 downto 1 do
begin
if bmp.fastgetpixel(x,y) <> clPurple then
continue;
if bmp.fastgetpixel(x,y) = bmp.fastgetpixel(x-1,y-1) then
begin
bmp.fastsetpixel(x,y,clSilver);
continue;
end;
if bmp.fastgetpixel(x-1,y-1) = 0 then
bmp.fastsetpixel(x,y,clSilver);
end;

// Now we do another filter, with uptext chars identity 1 and 2.
for y := bmp.Height - 2 downto 0 do
for x := bmp.Width - 2 downto 0 do
begin
if bmp.fastgetpixel(x,y) = clPurple then
continue;
if bmp.fastgetpixel(x,y) = clBlack then
continue;

// identity 1
if (bmp.fastgetpixel(x,y) = bmp.fastgetpixel(x+1,y+1) ) then
continue;

// identity 2
if bmp.fastgetpixel(x+1,y+1) <> clPurple then
begin
bmp.fastsetpixel(x,y,0); // 0 was clOlive
continue;
end;

// If we make it to here, it means the pixel is part of the uptext.
end;
end;

procedure SortATPAFromFirstPointY(var a: T2DPointArray; const From: TPoint);
var
i, l: Integer;
DistArr: TIntegerArray;
begin
l := High(a);
if (l < 0) then Exit;
SetLength(DistArr, l + 1);
for i := 0 to l do
DistArr[i] := Round(Sqr(From.y - a[i][0].y));
QuickATPASort(DistArr, a, 0, l, True);
end;

procedure SortATPAFromFirstPointX(var a: T2DPointArray; const From: TPoint);
var
i, l: Integer;
DistArr: TIntegerArray;
begin
l := High(a);
if (l < 0) then Exit;
SetLength(DistArr, l + 1);
for i := 0 to l do
DistArr[i] := Round(Sqr(From.x - a[i][0].x));
QuickATPASort(DistArr, a, 0, l, True);
end;


var
bmp, bmp2: integer;
w, h: integer;
cts: integer;
i: integer;

s: String;

P, P2: TPointArray;
ATPA: Array of TPointArray;
ATPATemp: Array of TPointArray;
t,t2:integer;
Colors: TIntegerArray;
target: Integer;

begin
target := GetImageTarget;

// LoadFont('SmallCharsNS', True); // If we want to use shadows

bmp := LoadBitmap('chooseopt5.bmp'); // Bitmap to search on

SetTargetBitmap(bmp);
GetClientDimensions(w, h);
Writeln('Size: ' + inttostr(w) + ', ' + inttostr(h));

cts := GetToleranceSpeed;
SetColorToleranceSpeed(1);

SetLength(P, 0);
SetLength(P2, 0);

// I forgot which colours these are. You'll need each of the colours here.
{FindColorsTolerance(P, 7901592, 0, 0, w-1, h-1, 15);
P2 := CombineTPA(P, P2); // Don't forget to combine.
FindColorsTolerance(P, 3765443, 0, 0, w-1, h-1, 15);
P2 := CombineTPA(P, P2);
}

Colors := [14210562, 14803165, 1865668, 8560553, 317398];//Object Blue, Player White, Item Orange, Action Tan, NPC Yellow
SetLength(ATPA, Length(Colors));
for i := 0 to High(Colors) do
FindColorsTolerance(ATPA[i], Colors[i], 0, 0, w-1, h-1, 50);
P2 := MergeATPA(ATPA);

// Shadows
FindColorsTolerance(P, 460291, 0, 0, w-1, h-1, 30);

// Reset CTS
SetColorToleranceSpeed(cts);

// Copy of the bitmap, blank
bmp2 := CreateBitmap(w+1, h+1);

// Clear it
FastDrawClear(bmp2, 0);
DrawTPABitmap(bmp2, P2, clRed);
DrawTPABitmap(bmp2, P, clPurple);

// this takes a lot of time, but will be in simba/plugin
t := gettickcount;
ocr_FilterUpTextByCharacteristics(GetMufasaBitmap(bmp2));
t2 := gettickcount;
writeln('Time: ' + inttostr(t2-t));


// Draw something nice.
DisplayDebugImgWindow(w, h);
DrawBitmapDebugImg(bmp2);
DisplayDebugImgWindow(w, h);

SaveBitmap(bmp2, 'test.bmp');

settargetbitmap(bmp2); // new target for findcolorstolerance.
// we need to reset the client properly afterwards.

// comment this for shadow
findcolorstolerance(P, clRed, 0, 0, w-1,h-1, 0);

// uncomment this for shadow
//findcolorstolerance(P, clPurple, 0, 0, w-1,h-1, 0);

t := gettickcount;

ATPA := SplitTPAEx(P, 15, 2);
//SortATPAFromFirstPoint(ATPA, Point(0,0));
SortATPAFromFirstPointY(ATPA, Point(w/2, 0));

for i := 0 to high(ATPA) do
begin
P := ATPA[i];
ATPATemp := SplitTPAEx(P, 1, 10); // the 1 used to be 2, make it 2 if you
// experience problems with spacing
//SortTPAFrom(P, Point(0, 0));
// SortATPAFromFirstPoint(ATPATemp, P[0]);
SortATPAFromFirstPointX(ATPATemp, Point(0, 0));

DrawATPABitmap(bmp2, ATPATemp); // split draw

s := GetTextATPA(ATPATemp, 4, 'SmallChars'); // note that this is no shadow atm
// if you want to do it for shadow,
writeln(IntToStr(P[0].x) + ', ' + IntToStr(P[0].y) + ' : ' + s);

setlength(atpatemp,0);
setlength(p,0);
end;

t2 := gettickcount;
writeln('Time: ' + inttostr(t2-t));

SaveBitmap(bmp2, 'test_split.bmp');

SetImageTarget(target);
//SetDesktopAsClient;
FreeBitmap(bmp);
FreeBitmap(bmp2);
end.

Code is not exactly the same (but largely) the same as Narcle's in SRL. It doesn't ``detect'' the menu, it only extracts text.

Set the bitmap name (chooseopt5.bmp atm), and crop the bitmap (saves a lot of crap) to the chooseoption menu.
Also, if you have an old simba, remove the ocr_ prefix from the filter. (You'll find out where that is as soon as it gives a compiling error)

If that identifies the text properly, the problem is not in the OCR but rather finding the actual ChooseOption MENU.

Narcle

2011-12-01 12:52:28

OpenBankNPC is now fixed. Was a cts problem, I also added this to compass as it didn't have cts speed check. If it fixes anything, no clue. xD