SRL Archive - RS has been updated.

ChooseOption suggestions


Wizzup?

2012-01-31 13:09:36

Hey everyone.

Today I saw the minor update about ChooseOption, it's probably an easy fix for us. (So by all means, please fix the current one first if you can - then read on)

Then I suddenly wondered about a better way, disregarding the actual colour of the text. I remember I made a function for the Quiz solver that returned a TPA of all the points in a box and not in a TPA. It's called ReturnPointsNotInTPA.

I very quickly wrote this to demonstrate the idea: (Very crude)


program new;

var
t, t2: TPointArray;
bmp, w, h, i, bmp2: Integer;
B: TBox;

begin
bmp := LoadBitmap('chooseopt.bmp');
settargetbitmap(bmp);
GetBitmapSize(bmp, w, h);

// any cts works, I was just playing with 3
setcolortolerancespeed(3);
FindColorsTolerance(t, 2563852, 0, 0, w - 1, h - 1, 10);

// get bounds so we don't ``return'' points outside the text box
B := GetTPABounds(t);

// this is magic
ReturnPointsNotInTPAWrap(t, B, t2);
writeln('Length: ' + inttostr(length(t2)));

// draw
bmp2 := CreateBitmap(w, h);
GetMufasaBitmap(bmp2).FastDrawClear(clBlack);
DrawTPABitmap(bmp2, t2, clRed);
DrawBitmapDebugImg(bmp2);
DisplayDebugImgWindow(w, h);


SetDesktopAsClient;
FreeBitmap(bmp);
end.

So 't2' contains a TPA of all the text. (Including shadow, ATM)

This way we really only need the background colour. The question now is, how much does the background colour vary?

weequ

2012-01-31 13:27:32

Isn't the background color transparent?

DemiseScythe

2012-01-31 13:30:02

Background looks similar to inventory color but darker, Ill get a picture, second.


To my suprise it is transparent but very difficult to see through, I had to try for a while to get a shot that showed the transparency in it.

On topic, reading the actual text wouldn't be so bad. Read text with OCR, find bits of string and get cords from it.

Wizzup?

2012-01-31 13:39:51

From: DemiseScythe
Background looks similar to inventory color but darker, Ill get a picture, second.


To my suprise it is transparent but very difficult to see through, I had to try for a while to get a shot that showed the transparency in it.

On topic, reading the actual text wouldn't be so bad. Read text with OCR, find bits of string and get cords from it.


I don't really see how the OCR fits in, because we already have that part covered. (With raw TPA power)
This is just about finding the text in an alternative way. The question remains how transparent it is. Perhaps we can utilize a specific HSL component to create an accurate finder for the background if a CTS alone isn't enough.

Narcle

2012-01-31 13:59:15

I think if we average it out we could figure out the transparent color of it, then HSL or w/e it to get it more accurate. Basically find the "tint" of the color. Also the edges are always constant (unless they changed that again), so we can use that as a reference as well.

Wizzup?

2012-01-31 14:01:27

On my screenshots, tolerance 10 with CTS 3 works wonders. Can anyone else confirm?

Coh3n

2012-01-31 15:24:33

I wrote these while working on the new randoms solvers. I was going to try them with Mordaut. I didn't realize you did the same thing with Quiz. :p

function ReturnTPAExceptColors(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 := returnPointsNotInTPA(tpa, getTPABounds(tpa));

//debugTPA(result, '');
end;
Question, though, why all the bitmap stuff? I finished the Pinball random yesterday, and SKy Scripter used similar methods for finding the spinning pillars, but wasn't sure as to why it was needed.

Narcle

2012-01-31 15:28:22

Using this GetChooseOption it hasn't failed me yet.

Any care to test more? (just replace the whole thing in text.simba)

Function GetChooseOptions(TextType: string): Array of TOptions;
var
B, BB, sB, BigBox: TBox;
TPA, TPA1, TPA2: TPointArray;
aTPA, tempatpa: T2DPointArray;
I, L, target, bmp,w,h, cts: Integer;
Colors: TIntegerArray;
begin
target := GetImageTarget;
GetClientDimensions(B.X2, B.Y2);
B := IntToBox(0, 0, B.X2-1, B.Y2-1);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
FindColorsTolerance(TPA1, 131843, B.X1, B.Y1, B.X2, B.Y2, 0);
FindColorsTolerance(TPA2, 3682593, B.X1, B.Y1, B.X2, B.Y2, 0);
TPA := CombineTPA(TPA1, TPA2);
If Length(TPA) < 100 Then
begin
ColorToleranceSpeed(cts);
Exit;
end;

aTPA := SplitTPA(TPA, 10);
For i := 0 to High(ATPA) do
begin
B := GetTPABounds(ATPA[i]);
if ((B.x2-B.x1) > 90) and ((B.y2-B.y1) > 18) then
Break
else
B := IntToBox(0, 0, 0, 0);
end;

If (B.x2 = 0) then
begin
ColorToleranceSpeed(cts);
Exit;
end;

BigBox := B;

{
//Object Blue, Player White, Item Orange, Action Tan, NPC Yellow, Level Green
Colors := [14342147, 14079443, 3832268, 9677229, 840143, 710915];
SetLength(aTPA, Length(Colors));
for i := 0 to High(Colors) do
FindColorsTolerance(aTPA[i], Colors[i], B.X1, B.Y1, B.X2, B.Y2, 70);
TPA := MergeATPA(aTPA);
}
SetColorToleranceSpeed(3);
FindColorsTolerance(TPA2, 2563852, B.X1, B.Y1, B.X2, B.Y2, 10);
SetColorToleranceSpeed(cts);

sB := GetTPABounds(TPA2);
ReturnPointsNotInTPAWrap(TPA2, B, TPA);

FindColorsTolerance(TPA1, 986117, B.X1, B.Y1, B.X2, B.Y2, 24);//shadow
bmp := CreateBitmap(B.X2-B.X1+2, B.Y2-B.Y1+2);
OffsetTPA(TPA, Point(-B.X1, -B.Y1));
OffsetTPA(TPA1, Point(-B.X1, -B.Y1));
FastDrawClear(bmp, 0);
DrawTPABitmap(bmp, TPA, clRed);
DrawTPABitmap(bmp, TPA1, clPurple);
ocr_FilterUpTextByCharacteristics(GetMufasaBitmap(bmp));
GetbitmapSize(bmp,w,h);
SetTargetBitmap(bmp); // new target for findcolorstolerance.
findcolorstolerance(TPA, clRed, 0, 0, w-1,h-1, 0);
ATPA := SplitTPAEx(TPA, 15, 2);
L := High(ATPA);
SortATPAFromFirstPointY(ATPA, Point(w/2,0));

SetArrayLength(Result, Length(ATPA));
Result[0].BigBox := BigBox;
for i := 0 to high(ATPA) do
begin
TPA := ATPA[i];
tempatpa := SplitTPAEx(TPA, 1, 10); // Split one into characters
SortATPAFromFirstPointX(tempatpa, Point(0, 0));
Result[i].Str := GetTextATPA(tempatpa, 5, 'UpCharsEx');
Writeln(Result[i].Str);
BB := GetTPABounds(ATPA[i]);
Result[i].Bounds := IntToBox(BB.X1+B.X1, BB.Y1+B.Y1, BB.X2+B.X1, BB.Y2+B.Y1);
setlength(tempatpa,0);
setlength(TPA,0);
end;
ColorToleranceSpeed(cts);
SetImageTarget(target);
FreeBitmap(bmp);
end;

kingarabian

2012-01-31 15:57:29

^ I get an access violation.

I have it right click an NPC and then search for an option.

Wizzup?

2012-01-31 16:18:49

From: kingarabian
^ I get an access violation.

I have it right click an NPC and then search for an option.


Where do you get the access violation?

Narcle

2012-01-31 16:19:35

From: Wizzup?
Where do you get the access violation?


He had old Simba.

kingarabian

2012-01-31 16:20:08

From: Wizzup?
Where do you get the access violation?


Sorry my Simba was not updated.

Ah ya, make sure with this new 'GetChooseOptions', to notify people that they must have the latest Simba.

Or else will have another 1k threads asking how to fix the access violation.

marpis

2012-01-31 16:44:42

I once wrote a very fast and reliable ChooseOption that used FindBitmapMask. Is that an option?

Narcle

2012-01-31 16:57:45

From: marpis
I once wrote a very fast and reliable ChooseOption that used FindBitmapMask. Is that an option?


If it works with random spacing? Its basically the same as UpText now except it has a box around it.

marpis

2012-01-31 17:03:49

From: Narcle
If it works with random spacing? Its basically the same as UpText now except it has a box around it.


Oh dang…
EDIT: Have it search letter by letter? Wouldn't even be slow, cause you'd be searching such small areas (just the box next to the previous character)

Mat

2012-01-31 17:08:02

ChooseOption Works, but trying to open the Bank with OpenBank();
Doesn't

kingarabian

2012-01-31 17:08:42

DidClick is fixed.
ChooseOption is fixed.

Waiting on uptext.

Narcle

2012-01-31 17:09:07

From: Mat
ChooseOption Works, but trying to open the Bank with OpenBank();
Doesn't


SRL update should fix, 'quickly' was removed from banks to open them.