SRL Archive - RS3 Help

GetchooseOptions not working..


rj

2013-12-18 21:35:59

So… if I use the following code, including SRL5 with the pascalscript interpreter:

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;
BoxColors: TIntegerArray;
begin
target := GetImageTarget;
GetClientDimensions(B.X2, B.Y2);
B := IntToBox(0, 0, B.X2-1, B.Y2-1);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
// Black, Top Blue, grey
BoxColors := [131843, 3682593, 3552822];
SetLength(ATPA, Length(BoxColors));
for i := 0 to High(BoxColors) do
FindColorsTolerance(ATPA[i], BoxColors[i], B.X1, B.Y1, B.X2, B.Y2, 0);
TPA := MergeATPA(ATPA);
If Length(TPA) < 100 Then
begin
ColorToleranceSpeed(cts);
Exit;
end;

ATPA := SplitTPA(TPA, 4);
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;

SetColorToleranceSpeed(3);
FindColorsTolerance(TPA1, 4996381, B.X1, B.Y1, B.X2, B.Y2, 18);//One color covers both Highlighted and non
sB := GetTPABounds(TPA1);
ReturnPointsNotInTPAWrap(TPA1, sB, TPA);
FindColorsTolerance(TPA2, 460291, B.X1, B.Y1, B.X2, B.Y2, 6);//shadow
SetColorToleranceSpeed(cts);

bmp := CreateBitmap(B.X2-B.X1+2, B.Y2-B.Y1+2);
OffsetTPA(TPA, Point(-B.X1, -B.Y1));
OffsetTPA(TPA2, Point(-B.X1, -B.Y1));
FastDrawClear(bmp, 0);
DrawTPABitmap(bmp, TPA, clRed);//Text
DrawTPABitmap(bmp, TPA2, clPurple);//Shadow
ocr_FilterUpTextByCharacteristics(GetMufasaBitmap(bmp));
GetbitmapSize(bmp,w,h);
SetTargetBitmap(bmp); // new target for findcolorstolerance.
SetLength(ATPA, H div 16);
for i := 0 to High(ATPA) do
FindColorsTolerance(ATPA[i], clRed, 0, 2+i*16, W-1, 18+i*16, 0);//+2 to y to line it up
L := High(ATPA);
SortATPAFromFirstPointY(ATPA, Point(w div 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;


I get these results:

[('CraM Diamond', (702, 473, 793, 485), (700, 469, 824, 553)), ('Use Diamond', (702, 489, 783, 498), (0, 0, 0, 0)), ('Drop Diamond', (702, 505, 788, 517), (0, 0, 0, 0)), ('Examine Diamond', (702, 521, 811, 530), (0, 0, 0, 0)), ('Cancel', (702, 537, 742, 546), (0, 0, 0, 0))]

But when I use the lape interpreter.. and the function renamed to _724_getChooseOption I get these results..

[{STR = , BOUNDS = {X1 = 700, Y1 = 472, X2 = 700, Y2 = 472}, BIGBOX = {X1 = 700, Y1 = 472, X2 = 824, Y2 = 556}}, {STR = , BOUNDS = {X1 = 700, Y1 = 472, X2 = 700, Y2 = 472}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}, {STR = , BOUNDS = {X1 = 700, Y1 = 472, X2 = 700, Y2 = 472}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}, {STR = , BOUNDS = {X1 = 700, Y1 = 472, X2 = 700, Y2 = 472}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}, {STR = , BOUNDS = {X1 = 700, Y1 = 472, X2 = 700, Y2 = 472}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}


So… it's somehow different? How come I can't get the choose options with lape? It's finding the boxes but not storing the string?


Debug




it finds the chooseoptions… but it's not splitting into an atpa


somehow the length of that tpa is changing… because when it goes to split it the length of that tpa is 0.

somewhere here

writeln('length 2 ', length(tpa));
Result[0].BigBox := BigBox;
for i := 0 to high(ATPA) do
begin
writeln('length 3 ', length(tpa));
TPA := ATPA[i];

the length of the tpa goes to 0 after the for loop goes after 1. The length of the atpa is 6, but the length of the array of arrays is 0

debug looks like

length 1 2817
length 2 2817
length 3 2817
length 3 0
length 3 0
length 3 0
length 3 0
length 3 0

as you can se.. the lenth was 2817, but after it entered the for loop it went to 0.. why?

rj

2014-01-05 14:17:47

FOUND THE ISSUE AFTER DEBUGGING THE BITMAP:

ocr_FilterUpTextByCharacteristics(GetMufasaBitmap(bmp));
commented out this line and fixed it
not sure why still trying to figure that out







Ok so I *literately* copied and pasted the getChooseOptions function from SRL5. I then pasted it into my own include. When I use it with my include, it finds all of the correct option boxes, but it is not finding the text.

https://github.com/officerBarbrady/srlRSPS

In core/text you can see where I copied and pasted it


How come when I use lape it isn't finding the text, but when I use pascalscript it does?


Test script

Lape:
{$I RSPS/srlRSPS.Simba}

var
myServer:_rsps_server;

begin
myServer.init(720, 'CloudIn');
wait(500);
writeln(GetChooseOptions(''));
end.

results:

[{STR = , BOUNDS = {X1 = 528, Y1 = 242, X2 = 528, Y2 = 242}, BIGBOX = {X1 = 528, Y1 = 242, X2 = 701, Y2 = 374}}, {STR = , BOUNDS = {X1 = 528, Y1 = 242, X2 = 528, Y2 = 242}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}, {STR = , BOUNDS = {X1 = 528, Y1 = 242, X2 = 528, Y2 = 242}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}, {STR = , BOUNDS = {X1 = 528, Y1 = 242, X2 = 528, Y2 = 242}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}, {STR = , BOUNDS = {X1 = 528, Y1 = 242, X2 = 528, Y2 = 242}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}, {STR = , BOUNDS = {X1 = 528, Y1 = 242, X2 = 528, Y2 = 242}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}, {STR = , BOUNDS = {X1 = 528, Y1 = 242, X2 = 528, Y2 = 242}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}, {STR = , BOUNDS = {X1 = 528, Y1 = 242, X2 = 528, Y2 = 242}, BIGBOX = {X1 = 0, Y1 = 0, X2 = 0, Y2 = 0}}]

Pascalscript:

{$i SRL/srl.simba}

begin
wait(1200);
writeln(getChooseOptions(''));
end.

Results:

[('Deposit-1 Diamond', (538, 251, 661, 263), (536, 247, 709, 379)), ('Deposit-5 Diamond', (538, 267, 662, 279), (0, 0, 0, 0)), ('Deposit-10 Diamond', (538, 283, 670, 295), (0, 0, 0, 0)), ('Deposit-30000 Diamond', (538, 299, 699, 311), (0, 0, 0, 0)), ('Deposit-X Diamond', (538, 315, 662, 327), (0, 0, 0, 0)), ('Deposit-All Diamond', (538, 331, 671, 343), (0, 0, 0, 0)), ('Examine Diamond', (538, 347, 649, 356), (0, 0, 0, 0)), ('Cancel', (538, 363, 579, 372), (0, 0, 0, 0))]
If you wish to test yourself it would be greatly appreciated, you can find a server where this would work here: http://cloudin728.com/







My suspicion is that SetTargetBitmap(bmp) is not setting the target for some reason.

Because right here:

FindColorsTolerance(ATPA, clred, 0, 2+i*16, W-1, 18+i*16, 5);//+2 to y to line it up

It is searching in these bounds within the bitmap:

0 2 125 18 0
0 18 125 34 0
0 34 125 50 0
0 50 125 66 0
0 66 125 82 0



It cannot find any red, yet like length of the red in the bitmap is over 2,000

masterBB

2014-01-08 18:26:27

Merged