Page 1 of 2 12 LastLast
Results 1 to 25 of 42

Thread: OCR-engine for OSR (Uptext).

  1. #1
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default OCR-engine for OSR (Uptext).

    Deprecated use https://villavu.com/forum/showthread.php?t=111156

    Someone told me that the current OCR-engine for UpText is OSR was somewhat unreliable, so I figured I could make a little something. So I made a plugin wrapping up my RS OCR-engine, hoping that somebody would find use for it. It should be noted that this is for RS shadow fonts only.

    New build: Support for PS!

    I did not do many tests where I compared it to the current GetUpText found in SRL-OSR, but a few. Performance varies a bit (could still use some tweaking), but should generally be more robust the what is now. Here are some BAD CASE SCENARIO examples of performance:
    Snippits

    Code:
    [NEW] Talk-to Duke Horacio / 7 more options
    [OLD] TNlk-t# - @uke Horaci
    
    [NEW] Walk here / 1 more options
    [OLD] Walk here r '
    
    [NEW] Walk here chaos combos (level-63) / 3 more options .
    [OLD] Walk here c
    
    [NEW] Open Large door / 2 more options
    [OLD] @' 0@-'-r Larg e door
    
    [NEW] Attack Man (le..el-2) / 4 more options
    [OLD] @BE[  llan
    
    [NEW] Walk here lady vx (level-54) / 3 more options
    [OLD] Walk here l 
    
    [NEW] Adjust Screen Brightness
    [OLD] Ad'lust Scr 
    
    [NEW] Talk-to Osman / 2 more options
    [OLD] Talk-t@ Dsman7r
    
    [NEW] Walk here A A R 0 N (level-95) / 3 more options '
    [OLD] Walk here F
    
    [NEW] Talk-to Al the Camel / 2 more options
    [OLD] Talk-to Al lh' i'l
    Quite decent, but not perfect. Usually it does read the text quite flawlessly.

    It's speed is very optimal, running in just a few ms usually around 2-10ms.

    The functions which are exposed to the user:
    Functions

    Simba Code:
    //Import / Load the uptext font (must have shadows).
      procedure ocr_LoadFont(FontPath:String; var Font:TCharsN);

      //Release the fonts, should be called at end of script.
      procedure ocr_FreeFont(var Font:TCharsN);

      //Important, must be used before everytime you try to read the uptext (see example)
      procedure ocr_SetClient(ATIA:T2DIntegerArray);

      //Makes it simple.. Everything is hardcoded in the engine
      function ocr_ReadText(Font:TCharsN): AnsiString;
     
      //Read text in client, allows to modify spacers.
      function ocr_ReadTextEx(Font:TCharsN, SpaceMod,MaxSpace:Integer): AnsiString;
     
      //Reads the text in the client and directly stops if "EndAt"-string is matched, it makes it a bit faster, and removes some "end noise".
      function ocr_ReadTextEnd(Font:TCharsN, SpaceMod,MaxSpace:Integer; EndAt:String): AnsiString; overload;

      //Simple regular IsUpText
      function ocr_IsText(Text:String; Chars:TCharsN): Boolean;

      //Same/comparable to IsUpTextMulti
      function ocr_IsTextMulti(TextArr:TStringArray; Chars:TCharsN): Boolean;

      //IsTextEx matches the string by also allowing you to use the "*"-sign to make it "skip".
      //IE: TextPtrn := 'Attack * (level*)'; which would result True if a text like: 'Attack Giant Rat (level-19)' was found.
      function ocr_IsTextEx(TextPtrn:String; Sensitive:Boolean; Chars:TCharsN): Boolean;


    Example usage:
    Simba Code:
    program new;
    {$loadlib rstext.dll}

    var UpFont:TCharsN;

    function ClientATIA(x1,y1,width,height: Integer): T2DIntegerArray;
    var bmp:Integer;
    begin
      bmp := BitmapFromClient(x1,y1,x1+width,y1+height);
      Result := GetBitmapAreaColors(bmp, 0,0,width,height);
      FreeBitmap(bmp);
    end;

    function RS_GetUpText2: String;
    begin
      ocr_SetClient(ClientATIA(7,7,500,16));
      Result := ocr_ReadTextEnd(UpFont,0,200,'more options');
      //Result := ocr_ReadText(UpFont);
    end;

    function RS_IsUpText(Text:String): Boolean;
    begin
      ocr_SetClient(ClientATIA(7,7,500,16));
      Result := ocr_IsTextEx(Text, True, UpFont);
    end;

    var
      t,i: Integer;
      text: String;
    begin
      ocr_LoadFont(AppPath + 'Fonts\UpChars07_s\', UpFont);
      WriteLn(RS_GetUpText2);
      ocr_FreeFont(UpFont);
    end.

    If there should be any problems, please give me some feedback with relative info (EG: Where you whare when it happened).

    A thanks to Janilabo for making am string functions used internally, and Olly for doing some extra testing!
    Attached Files Attached Files
    Last edited by slacky; 04-07-2016 at 12:12 PM.
    !No priv. messages please

  2. #2
    Join Date
    Oct 2006
    Posts
    6,752
    Mentioned
    95 Post(s)
    Quoted
    532 Post(s)

    Default

    Looks awesome man! I don't have a use for it in my current scripts i'm working on, but i'm sure others will!
    “The long-lived and those who will die soonest lose the same thing. The present is all that they can give up, since that is all you have, and what you do not have, you cannot lose.” - Marcus Aurelius

  3. #3
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    This is very good! a massive... huge.. improvement!

  4. #4
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Awesome . I posted in the bugtracker about the current OCR Functions.
    The problem is that they can't read letters where the pixels are connected.

    Please make support for Pascal script too. Lape compiles somewhat slow.

  5. #5
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Very good indeed. I'm going to plug this into AL.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  6. #6
    Join Date
    Sep 2012
    Location
    Netherlands
    Posts
    2,752
    Mentioned
    193 Post(s)
    Quoted
    1468 Post(s)

    Default

    gj! to bad it wont work with pascalscript

  7. #7
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Why wont it work in PascalScript? Just wondering...

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  8. #8
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    Very nice! I almost support not including PascalScript on purpose just to encourage upgrading...

  9. #9
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by Dgby714 View Post
    Why wont it work in PascalScript? Just wondering...
    Got in to problems when I tried to use the exported font-record in PS. It instantly crashed Simba when I tried to load a font, I did not look long for a workaround to this issue, as I didn't really see it as that big a problem, and as for exporting and all, there should not be any problems, so don't see that I can do much about it.
    !No priv. messages please

  10. #10
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by warpie View Post
    Got in to problems when I tried to use the exported font-record in PS. It instantly crashed Simba when I tried to load a font, I did not look long for a workaround to this issue, as I didn't really see it as that big a problem, and as for exporting and all, there should not be any problems, so don't see that I can do much about it.
    What does the record look like?

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  11. #11
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by Dgby714 View Post
    What does the record look like?
    Simba Code:
    type
      TCharN = record
        Pts,Shadows: TPointArray;
        Height,Width: Integer;
      end;
      TCharsN = array of TCharN;
    I've gone over the code qute a few times, there is no reason for it to not work in PS. Yet it doesn't. So I don't believe the mistake is on my end.

    Export file: http://pastebin.com/raw.php?i=PtLJH6SR
    !No priv. messages please

  12. #12
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by warpie View Post
    Simba Code:
    type
      TCharN = record
        Pts,Shadows: TPointArray;
        Height,Width: Integer;
      end;
      TCharsN = array of TCharN;
    I've gone over the code qute a few times, there is no reason for it to not work in PS. Yet it doesn't. So I don't believe the mistake is on my end.
    Is the source of the plugin public?

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  13. #13
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Nice work! OSR has been using that gettext function for a whole now hasn't it?

    This may be a little off topic but can I view a source somewhere? :d didn't see it on your github

  14. #14
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by Officer Barbrady View Post
    Nice work! OSR has been using that gettext function for a whole now hasn't it?

    This may be a little off topic but can I view a source somewhere? :d didn't see it on your github
    No it's not available anywhere. I do not see that it's worth uploading anywhere, it's nothing out of the ordinary.
    It's still quite "dirty" as it uses my SCARExt to fulfill it's needs, might look at upping it somewhere if I get it cleaned out a bit.
    !No priv. messages please

  15. #15
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Here is the requested source (exports are without overload as in the previous upped files):
    http://slacky.info/browser/?fold=fil...iles/RS/RSText

    Updated with latest compiled version (old one was removed from speedy.sh for some reason).
    Last edited by slacky; 02-16-2016 at 05:25 AM.
    !No priv. messages please

  16. #16
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Quote Originally Posted by warpie View Post
    Here is the requested source (exports are without overload as in the previous upped files):
    http://www.speedyshare.com/aP5XG/RSText.rar
    Brilliant mate.
    Glad to see you decided to share the source for this awesome project - appreciated move!

  17. #17
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Well I've fit this into my Lape SRL-OSR and it's working exceptionally well. The accuracy is improved and the speed is so much faster than before. You did very well Mr. WarPie.

    Should I come across any issues I'll be sure to report them here.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  18. #18
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Very, very nice!
    Great job

  19. #19
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    New build! Supports PS, font-loading is now a procedure loadfont(fontpath:string, var Font:TCharsN); .
    Also since it supports PS, overloads are also removed.

    Se first post to grab the latest build. As always, if any errors show up, please post it here.
    !No priv. messages please

  20. #20
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

  21. #21
    Join Date
    Nov 2008
    Posts
    117
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Would be nice to support system fonts. If size must be specified, double would be nicer than integer (so you could say 10.5 for ex).
    Would also be nice to be able to specify where it should look for text to OCR. That way it can be used for more than just RS.

  22. #22
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Quote Originally Posted by Gavril View Post
    Would be nice to support system fonts. If size must be specified, double would be nicer than integer (so you could say 10.5 for ex).
    Would also be nice to be able to specify where it should look for text to OCR. That way it can be used for more than just RS.
    You can look for text in a specific region, look at his example functions; they're default set for the UpText area for RS, you can change these coordinates if you want.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  23. #23
    Join Date
    Sep 2012
    Location
    Netherlands
    Posts
    2,752
    Mentioned
    193 Post(s)
    Quoted
    1468 Post(s)

    Default

    Quote Originally Posted by warpie View Post
    New build! Supports PS, font-loading is now a procedure loadfont(fontpath:string, var Font:TCharsN); .
    Also since it supports PS, overloads are also removed.

    Se first post to grab the latest build. As always, if any errors show up, please post it here.
    thank you so much!


    edit: is this going to be posted on the srl-osr github?

  24. #24
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by Gavril View Post
    Would be nice to support system fonts. If size must be specified, double would be nicer than integer (so you could say 10.5 for ex).
    Would also be nice to be able to specify where it should look for text to OCR. That way it can be used for more than just RS.
    I believe that can be done with the current OCR-engine in Simba, this one is made simply to better the reading of RS UpText (might be able to read other shadowfonts), as the color change, and background change a lot.
    !No priv. messages please

  25. #25
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    I got Wizzup to add upchars07_s to the Simba fonts package.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •