SRL Archive - Help and Support

Fonts detection


xtrapsp

2013-03-29 16:48:11

EDIT:

Gaveup with this script. Simba is utter crap at detecting fonts in my opinion. So there's not even a point in me trying to detect text for stuff like this.



hey all.

having a few problems with this script, basically I want it to write out the success rating from below:


This is what happens:

Clicking Voyages Button
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
could not find Positive Success rating
Drawing box around Test Text
Drawing box around Test Text
Drawing box around Test Text
Drawing box around Test Text
Drawing box around Test Text



This is the snippet:


function TestRead : String;
//Thanks to NKN for the continued help with my Rage when this wouldn't work.
var
Box:Tbox;
BoxColorArray, FontArray: TVariantArray;
i, j: Integer;
begin
BoxColorArray := [1343050, 1374720];
FontArray := [BigChars,CharsNPC,CharsTrade,FriendChars,LoginChars,SmallChars,StatChars,UpChars,XPChars];
Box := IntToBox(547,444-50,620,466-50);
writeln('Drawing box around Test Text');
SMART_DrawBoxEx(True,False,Box,clyellow);
for i := 0 to High(BoxColorArray) do
begin
for j := 0 to High(FontArray) do
begin
if(not(GetTextAtExWrap(Box.x1,Box.y1,Box.x2,Box.y2,0,10,10,BoxColorArray[i],0,FontArray[j])='')) then
begin
Result := GetTextAtExWrap(Box.x1,Box.y1,Box.x2,Box.y2,0,10,10,BoxColorArray[i],0,FontArray[j]);
exit;
end else
Writeln('could not find Positive Success rating');
exit;
end;
end;
WriteLn('Chance of Success: ' + Result);
end;

Le Jingle

2013-03-29 17:37:43

If you attempted each fond in simba, and none of them work correctly in reading the font inside the box, then I think the next step would be to make a font for the text, no?

xtrapsp

2013-03-29 17:58:58

From: Le Jingle
If you attempted each fond in simba, and none of them work correctly in reading the font inside the box, then I think the next step would be to make a font for the text, no?


trying to see if i can avoid this :P

the flea

2013-03-29 17:59:34

If you cannot find the correct font to read that number could you not just measure how filled the bar is and work out a percentage from that?

IIRC the overall success chance is always just the lowest of the 3 adversities.

xtrapsp

2013-03-29 18:14:31

From: the flea
If you cannot find the correct font to read that number could you not just measure how filled the bar is and work out a percentage from that?

IIRC the overall success chance is always just the lowest of the 3 adversities.


theres 3 bars though, so i dunno. I kinda wanted to write it down so it could be logged somewhere

the flea

2013-03-29 18:37:03

how far into the minigame are you though? I'm only at the third island for me and I'm pretty sure its always the lowest bar that determines it. I will go check in a minute when my ships come back in.

EDIT:

EDIT2: I know I'm going on a bit now but just seen you may also find it easier to read the two numbers highlighted in the red boxes and work out the percentage by dividing one by the other. The more simple white text on a dark background may prove easier to detect.

xtrapsp

2013-03-29 21:07:59

From: the flea
how far into the minigame are you though? I'm only at the third island for me and I'm pretty sure its always the lowest bar that determines it. I will go check in a minute when my ships come back in.

EDIT:

EDIT2: I know I'm going on a bit now but just seen you may also find it easier to read the two numbers highlighted in the red boxes and work out the percentage by dividing one by the other. The more simple white text on a dark background may prove easier to detect.


Hey Flea, That might just work!

so it looks like it's always the middle one which is the overall success? Seem's like a good method!

e* : I've come into a problem… Ok so, with some of the missions there is lets say only 1 box and it isn't combat.

How am I going to detect the best option and where the text is as it changes?


the flea

2013-03-29 21:49:00

hmm so I just went to do this activity again and it turns out its not always the middle one, must just be the lowest of the 3 at the time.
I'm not really sure how best to detect it though, its been ages since I've scripted. I am meaning to get back into it and would try help out however I'm going on holiday later today for a week so there's no point right now :(

xtrapsp

2013-03-29 22:17:41

From: the flea
hmm so I just went to do this activity again and it turns out its not always the middle one, must just be the lowest of the 3 at the time.
I'm not really sure how best to detect it though, its been ages since I've scripted. I am meaning to get back into it and would try help out however I'm going on holiday later today for a week so there's no point right now :(


That's ok dude. Thanks for your help. Spoke to Olly and I suppose I'l try making a font.

Gonna post here.

____________________________________________

@Olly
@Le Jingle

procedure test;
var
b: tbox;
s: string;
begin
LoadFont('DockChars', True);
b := IntToBox(547,444-50,620,466-50);


s := GetTextAtExWrap(b.x1, b.y1, b.x2, b.y2, 0, 0, 4, 1343050, 4, 'DockChars');

writeln('result = ' + s);
end;


Le Jingle

2013-03-29 22:46:52

I'm not sure what I can do for the moment, I can suggest other ways to find the ``Overall success"" rate, via reading in the text such as the flea said earlier, then parsing out single/unpaired values, finding the lowest success rate from remaining values, then using that (granted if I read the above posts correctly, saying that those texts on the end are readable).

If you're just asking my opinion about the above post, I don't know specifics about whether the text is correct or accurate to produce decent results. I would also change the 0, 0, 4 to 2, 0, 5 after the search area in the getTextAtExWrap arguments, as it may offer more chance to obtain better results (granted you don't already have them)

xtrapsp

2013-03-29 22:54:56

From: Le Jingle
I'm not sure what I can do for the moment, I can suggest other ways to find the ``Overall success"" rate, via reading in the text such as the flea said earlier, then parsing out single/unpaired values, finding the lowest success rate from remaining values, then using that (granted if I read the above posts correctly, saying that those texts on the end are readable).

If you're just asking my opinion about the above post, I don't know specifics about whether the text is correct or accurate to produce decent results. I would also change the 0, 0, 4 to 2, 0, 5 after the search area in the getTextAtExWrap arguments, as it may offer more chance to obtain better results (granted you don't already have them)


Hey Jingle,

Thanks for the quick response. Had the skype team trying to help me too with no prevail.

I have taken a different approach. I'm doing the white text thing people on Skype and @the flea spoke about..


procedure test2;
var
CurrentShip, SelectedVoyage: tbox;
CurrentShipNumber, SelectedVoyageNumber: string;
begin
LoadFont(UpChars, True);
CurrentShip := IntToBox(481,415-50,502,428-50);
SelectedVoyage := IntToBox(708,415-50,730,428-50);
SMART_DrawBoxEx(True,False,CurrentShip,1343050);
SMART_DrawBoxEx(True,False,SelectedVoyage,1343050);

SelectedVoyageNumber := GetTextAtExWrap(SelectedVoyage.x1, SelectedVoyage.y1, SelectedVoyage.x2, SelectedVoyage.y2, 0, 0, 0, 16777215, 20, StatChars);
CurrentShipNumber := GetTextAtExWrap(CurrentShip.x1, CurrentShip.y1, CurrentShip.x2, CurrentShip.y2, 0, 0, 0, 16777215, 20, StatChars);
writeln('Current Ship = ' + GetNumbers(CurrentShipNumber));
writeln('Current Selected Voyage = ' + SelectedVoyageNumber);
WriteLn('% Of Success = ' + IntToStr(StrToInt(GetNumbers(CurrentShipNumber)) / StrToInt(GetNumbers(SelectedVoyageNumber)) * 100) + '%');;
end;

Brandon

2013-03-31 14:08:04

Can use GLHook for that ;) Ahh just kidding umm..

Those fonts don't look right. They look chunky and fat. Oh and try not to set the spacing to 0. Min spacing = 0. Max has to be more.. so set it to 5 which I believe is standard. Then set the current spacing to start off at 2-3. Here goes:

When making fonts, the background must be completely black and the text must be completely white. I know you already know this but I just say it as a reminder.

Anyway sire, it does work as I tested it.. Offset is there because remember that Simba adds the offset due to the navigation bar which seemed to mess up the font finding for me. You can tell if it's finding the fonts by taking a screenshot of the AREA simba is looking at. If you don't see the stuff you're looking for in the screenshot, then play with the offset.


{$I SRL/SRL.Simba}
{$I SRL/SRL/Misc/Debug.Simba}

var
Offset: Integer;
Bmp: Integer;

begin
SetupSRL;
Offset := 22;
writeln(GetTextAtExWrap(912, 441 - Offset, 958, 458 - Offset, 0, 5, 3, 1343050, 5, 'DockFonts'));

Bmp := BitmapFromClient(912, 441 - Offset, 958, 458 - Offset);
DebugBitmap(Bmp);
FreeBitmap(Bmp);
end.


Compiled successfully in 422 ms.
SRL Compiled in 15 msec
43%
Successfully executed.

The fonts I used looks like: [ATTACH]20409[/ATTACH]

The way I made it was I used the Windows Snipping tool. I saved it as capture on my desktop. I went to paint and set the background black. Set all the text white. Then I used the selection tool and selected it such that there is NO black space around the font. Not even a single pixel. Then cropped it.

Saved as ascii value and voila. Works. PS: The ascii value for your % sign is 37 not 48

rj

2013-03-31 14:12:56

From: Brandon
Can use GLHook for that ;) Ahh just kidding umm..

Those fonts don't look right. They look chunky and fat. Oh and try not to set the spacing to 0. Min spacing = 0. Max has to be more.. so set it to 5 which I believe is standard. Then set the current spacing to start off at 2-3. Here goes:

When making fonts, the background must be completely black and the text must be completely white. I know you already know this but I just say it as a reminder.

Anyway sire, it does work as I tested it.. Offset is there because remember that Simba adds the offset due to the navigation bar which seemed to mess up the font finding for me. You can tell if it's finding the fonts by taking a screenshot of the AREA simba is looking at. If you don't see the stuff you're looking for in the screenshot, then play with the offset.


{$I SRL/SRL.Simba}
{$I SRL/SRL/Misc/Debug.Simba}

var
Offset: Integer;
Bmp: Integer;

begin
SetupSRL;
Offset := 22;
writeln(GetTextAtExWrap(912, 441 - Offset, 958, 458 - Offset, 0, 5, 3, 1343050, 5, 'DockFonts'));

Bmp := BitmapFromClient(912, 441 - Offset, 958, 458 - Offset);
DebugBitmap(Bmp);
FreeBitmap(Bmp);
end.


Compiled successfully in 422 ms.
SRL Compiled in 15 msec
43%
Successfully executed.

The fonts I used looks like: [ATTACH]20409[/ATTACH]

The way I made it was I used the Windows Snipping tool. I saved it as capture on my desktop. I went to paint and set the background black. Set all the text white. Then I used the selection tool and selected it such that there is NO black space around the font. Not even a single pixel. Then cropped it.

Saved as ascii value and voila. Works. PS: The ascii value for your % sign is 37 not 48


What if the font is like a capital E, I can still have black inside of the ridges right?

Brandon

2013-03-31 14:16:28

Inside it yes. Around the edges should have nothing though. I usually remove every black pixel (using the zoom in mspaint) around it while keeping it a squared crop. So crop as much around it as you can without actually touching the digit/letter/character itself.

Top, Bottom, Left, Right. Trim the fat off it. The font will work a lot better and more accurate.

rj

2013-03-31 14:17:36

From: Brandon
Inside it yes. Around the edges should have nothing though. I usually remove every black pixel (using the zoom in mspaint) around it while keeping it a squared crop.


Ok so even top and bottom and left? Ty,


Sorry for Hi-jacking Xtrapsp :p

Ian

2013-03-31 14:18:38

I just did it by counting the number of colored pixels in each digit, working perfectly:

function GetPercentage:Integer;
var
tmpCTS, PercentColor, PercentTol, PixelCount1, PixelCount2, FirstDigit,
SecondDigit, Percent:Integer;
begin
//Color Info
PercentColor := 10263821;
PercentTol := 6;

SMART_ClearCanvas;
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(8.29, 2.22);
repeat
if (CountColorTolerance(PercentColor, 550, 395, 590, 416, PercentTol) = (120)) then
begin
WriteLn('100%!');
FirstDigit := 100;
Break;
end;
if (CountColorTolerance(PercentColor, 580, 395, 590, 416, PercentTol) = (29)) then
begin
WriteLn('Ends in 7!');
//1st Digit
SMART_DrawBoxEx(true, false, intToBox(568, 395, 580, 416), clYellow);
PixelCount1 := CountColorTolerance(PercentColor, 568, 395, 580, 416, PercentTol);
if (PixelCount1 = 43) then
begin
SMART_DrawBoxEx(false, false, intToBox(568, 395, 580, 405), clYellow);
if (CountColorTolerance(PercentColor, 568, 395, 580, 405, PercentTol) > 20) then
begin
FirstDigit := 90;
end else
FirstDigit := 60;
end;
SecondDigit := 7;
{//2nd Digit}
SMART_DrawBoxEx(false, false, intToBox(580, 395, 590, 416), clYellow);
{{PixelCount2 := CountColorTolerance(PercentColor, 580, 395, 590, 416, PercentTol);}
Break;
end;
if (CountColorTolerance(PercentColor, 582, 395, 590, 416, PercentTol) = (28)) then
begin
WriteLn('Ends in 1!');
//1st Digit
SMART_DrawBoxEx(true, false, intToBox(568, 395, 582, 416), clYellow);
PixelCount1 := CountColorTolerance(PercentColor, 568, 395, 581, 416, PercentTol);
if (PixelCount1 = 43) then
begin
SMART_DrawBoxEx(false, false, intToBox(568, 395, 581, 405), clYellow);
if (CountColorTolerance(PercentColor, 568, 395, 581, 405, PercentTol) > 20) then
begin
FirstDigit := 90;
end else
FirstDigit := 60;
end;
SecondDigit := 1;
SMART_DrawBoxEx(false, false, intToBox(582, 395, 590, 416), clYellow);
Break;
end;
if not (CountColorTolerance(PercentColor, 560, 395, 573, 416, PercentTol) > 1) then
begin
WriteLn('Less than 10%!');
SMART_DrawBoxEx(true, false, intToBox(574, 395, 586, 416), clYellow);
PixelCount2 := CountColorTolerance(PercentColor, 574, 395, 586, 416, PercentTol);
if (PixelCount2 = 43) then
begin
SMART_DrawBoxEx(false, false, intToBox(574, 395, 586, 405), clYellow);
if (CountColorTolerance(PercentColor, 574, 395, 586, 405, PercentTol) > 20) then
begin
SecondDigit := 9;
end else
SecondDigit := 6;
end;
Break;
end;
if (CountColorTolerance(PercentColor, 560, 395, 573, 416, PercentTol) > 1) then
begin
WriteLn('More than 10%!');
//1st Digit
SMART_DrawBoxEx(true, false, intToBox(568, 395, 579, 416), clYellow);
PixelCount1 := CountColorTolerance(PercentColor, 568, 395, 579, 416, PercentTol);
if (PixelCount1 = 43) then
begin
SMART_DrawBoxEx(false, false, intToBox(568, 395, 579, 405), clYellow);
if (CountColorTolerance(PercentColor, 568, 395, 579, 405, PercentTol) > 20) then
begin
FirstDigit := 90;
end else
FirstDigit := 60;
end;
//2nd Digit
SMART_DrawBoxEx(false, false, intToBox(579, 395, 590, 416), clYellow);
PixelCount2 := CountColorTolerance(PercentColor, 579, 395, 590, 416, PercentTol);
if (PixelCount2 = 43) then
begin
SMART_DrawBoxEx(false, false, intToBox(579, 395, 590, 405), clYellow);
if (CountColorTolerance(PercentColor, 579, 395, 590, 405, PercentTol) > 20) then
begin
SecondDigit := 9;
end else
SecondDigit := 6;
end;
Break;
end;
until(False);
if (PixelCount1 = 28) then
FirstDigit := 10;
if (PixelCount1 = 37) then
FirstDigit := 20;
if (PixelCount1 = 41) then
FirstDigit := 30;
if (PixelCount1 = 36) then
FirstDigit := 40;
if (PixelCount1 = 40) then
FirstDigit := 50;
if (PixelCount1 = 29) then
FirstDigit := 70;
if (PixelCount1 = 47) then
FirstDigit := 80;

if (PixelCount2 = 28) then
SecondDigit := 1;
if (PixelCount2 = 37) then
SecondDigit := 2;
if (PixelCount2 = 41) then
SecondDigit := 3;
if (PixelCount2 = 36) then
SecondDigit := 4;
if (PixelCount2 = 40) then
SecondDigit := 5;
if (PixelCount2 = 29) then
SecondDigit := 7;
if (PixelCount2 = 47) then
SecondDigit := 8;
Percent := (FirstDigit + SecondDigit);
Result := Percent;
SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);
end;

Olly

2013-03-31 14:31:35

From: BMWxi
I just did it by counting the number of colored pixels in each digit, working perfectly:

function GetPercentage:Integer;
var
tmpCTS, PercentColor, PercentTol, PixelCount1, PixelCount2, FirstDigit,
SecondDigit, Percent:Integer;
begin
//Color Info
PercentColor := 10263821;
PercentTol := 6;

SMART_ClearCanvas;
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(8.29, 2.22);
repeat
if (CountColorTolerance(PercentColor, 550, 395, 590, 416, PercentTol) = (120)) then
begin
WriteLn('100%!');
FirstDigit := 100;
Break;
end;
if (CountColorTolerance(PercentColor, 580, 395, 590, 416, PercentTol) = (29)) then
begin
WriteLn('Ends in 7!');
//1st Digit
SMART_DrawBoxEx(true, false, intToBox(568, 395, 580, 416), clYellow);
PixelCount1 := CountColorTolerance(PercentColor, 568, 395, 580, 416, PercentTol);
if (PixelCount1 = 43) then
begin
SMART_DrawBoxEx(false, false, intToBox(568, 395, 580, 405), clYellow);
if (CountColorTolerance(PercentColor, 568, 395, 580, 405, PercentTol) > 20) then
begin
FirstDigit := 90;
end else
FirstDigit := 60;
end;
SecondDigit := 7;
{//2nd Digit}
SMART_DrawBoxEx(false, false, intToBox(580, 395, 590, 416), clYellow);
{{PixelCount2 := CountColorTolerance(PercentColor, 580, 395, 590, 416, PercentTol);}
Break;
end;
if (CountColorTolerance(PercentColor, 582, 395, 590, 416, PercentTol) = (28)) then
begin
WriteLn('Ends in 1!');
//1st Digit
SMART_DrawBoxEx(true, false, intToBox(568, 395, 582, 416), clYellow);
PixelCount1 := CountColorTolerance(PercentColor, 568, 395, 581, 416, PercentTol);
if (PixelCount1 = 43) then
begin
SMART_DrawBoxEx(false, false, intToBox(568, 395, 581, 405), clYellow);
if (CountColorTolerance(PercentColor, 568, 395, 581, 405, PercentTol) > 20) then
begin
FirstDigit := 90;
end else
FirstDigit := 60;
end;
SecondDigit := 1;
SMART_DrawBoxEx(false, false, intToBox(582, 395, 590, 416), clYellow);
Break;
end;
if not (CountColorTolerance(PercentColor, 560, 395, 573, 416, PercentTol) > 1) then
begin
WriteLn('Less than 10%!');
SMART_DrawBoxEx(true, false, intToBox(574, 395, 586, 416), clYellow);
PixelCount2 := CountColorTolerance(PercentColor, 574, 395, 586, 416, PercentTol);
if (PixelCount2 = 43) then
begin
SMART_DrawBoxEx(false, false, intToBox(574, 395, 586, 405), clYellow);
if (CountColorTolerance(PercentColor, 574, 395, 586, 405, PercentTol) > 20) then
begin
SecondDigit := 9;
end else
SecondDigit := 6;
end;
Break;
end;
if (CountColorTolerance(PercentColor, 560, 395, 573, 416, PercentTol) > 1) then
begin
WriteLn('More than 10%!');
//1st Digit
SMART_DrawBoxEx(true, false, intToBox(568, 395, 579, 416), clYellow);
PixelCount1 := CountColorTolerance(PercentColor, 568, 395, 579, 416, PercentTol);
if (PixelCount1 = 43) then
begin
SMART_DrawBoxEx(false, false, intToBox(568, 395, 579, 405), clYellow);
if (CountColorTolerance(PercentColor, 568, 395, 579, 405, PercentTol) > 20) then
begin
FirstDigit := 90;
end else
FirstDigit := 60;
end;
//2nd Digit
SMART_DrawBoxEx(false, false, intToBox(579, 395, 590, 416), clYellow);
PixelCount2 := CountColorTolerance(PercentColor, 579, 395, 590, 416, PercentTol);
if (PixelCount2 = 43) then
begin
SMART_DrawBoxEx(false, false, intToBox(579, 395, 590, 405), clYellow);
if (CountColorTolerance(PercentColor, 579, 395, 590, 405, PercentTol) > 20) then
begin
SecondDigit := 9;
end else
SecondDigit := 6;
end;
Break;
end;
until(False);
if (PixelCount1 = 28) then
FirstDigit := 10;
if (PixelCount1 = 37) then
FirstDigit := 20;
if (PixelCount1 = 41) then
FirstDigit := 30;
if (PixelCount1 = 36) then
FirstDigit := 40;
if (PixelCount1 = 40) then
FirstDigit := 50;
if (PixelCount1 = 29) then
FirstDigit := 70;
if (PixelCount1 = 47) then
FirstDigit := 80;

if (PixelCount2 = 28) then
SecondDigit := 1;
if (PixelCount2 = 37) then
SecondDigit := 2;
if (PixelCount2 = 41) then
SecondDigit := 3;
if (PixelCount2 = 36) then
SecondDigit := 4;
if (PixelCount2 = 40) then
SecondDigit := 5;
if (PixelCount2 = 29) then
SecondDigit := 7;
if (PixelCount2 = 47) then
SecondDigit := 8;
Percent := (FirstDigit + SecondDigit);
Result := Percent;
SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);
end;


case statments…. :)

Ian

2013-03-31 14:37:31

From: Ollybest
case statments…. :)


Yeah, that's what turp said :)

xtrapsp

2013-03-31 19:00:26

Thanks for your help guys!