SimpleOCR is a Simba plugin for reading text in Old School RuneScape originally developed by @slackydev.
The algorithm is very much designed for OSRS (blocky text with no anti-aliasing). Every pixel of the glyph must match for for a character to be recognized.
The actual character recognition is quite similar to using Simba's FindBitmap for every character in the fontset.
procedureTFontSet.Load(FileName: String; Space: Integer = 4);
functionTSimpleOCR.Recognize(Area: TBox; Filter: TOCRFilter; Font: TFontSet): String;
functionTSimpleOCR.RecognizeStatic(Area: TBox; Filter: TOCRFilter; Font: TFontSet; MaxWalk: Integer = 20): String;
functionTSimpleOCR.RecognizeLines(Area: TBox; Filter: TOCRFilter; Font: TFontSet; out TextBounds: TBoxArray): TStringArray; overload;
functionTSimpleOCR.RecognizeLines(Area: TBox; Filter: TOCRFilter; Font: TFontSet): TStringArray; overload;
functionTSimpleOCR.RecognizeNumber(Area: TBox; Filter: TOCRFilter; Font: TFontSet): Int64;
functionTSimpleOCR.LocateText(Area: TBox; Text: String; constref Font: TFontSet; Filter: TOCRFilter; out Bounds: TBox): Single; overload;
functionTSimpleOCR.LocateText(Area: TBox; Text: String; constref Font: TFontSet; Filter: TOCRFilter; MinMatch: Single): Boolean; overload;
functionTSimpleOCR.TextToMatrix(Text: String; constref Font: TFontSet): TIntegerMatrix;
functionTSimpleOCR.TextToTPA(Text: String; constref Font: TFontSet): TPointArray; The first pixel (highlighted in red) of the character being checked is the color used, all other of the character must fall within
Toleranceof that.If the fontset has a shadow each RGB value of a possible shadow point must be below
MaxShadowValue.functionTOCRAnyColorFilter.Create(Tolerance: Integer; MaxShadowValue: Integer): TOCRAnyColorFilter; static;
This filter is generally used for uptext reading.
Basic color finding.
functionTOCRColorFilter.Create(Colors, Tolerances: TIntegerArray): TOCRColorFilter; static; functionTOCRColorFilter.Create(Colors: TIntegerArray): TOCRColorFilter; static; overload;
Example:
TOCRColorFilter.Create([$0000FF]); // Find color redExample with tolerance:
TOCRColorFilter.Create([$FFFFFF], [100]); // Find color white with 100 tolerance
Basic color finding but inverted.
functionTOCRInvertColorFilter.Create(Colors, Tolerances: TIntegerArray): TOCRInvertColorFilter; static; overload; functionTOCRInvertColorFilter.Create(Colors: TIntegerArray): TOCRInvertColorFilter; static; overload;
Example:
TOCRInvertColorFilter.Create([3358536, 0], [3, 10]); // Everything but brown and black (text shadow)
If a pixel brightness value is greater than a threshold amount, it is assigned white, else it is assigned black.
functionTOCRThresholdFilter.Create(Amount: Integer; Invert: Boolean = False): TOCRThresholdFilter; static;
Example:
TOCRThresholdFilter.Create(10); // Orange and red are brighter than the brown background
First shadows are found using average R,G,B value.
Shadow = (R+G+B) div 3 < MaxShadowValueNext shadow pixels are offset by -1,-1. The most common color from the offset pixels is used for the search color.
functionTOCRShadowFilter.Create(MaxShadowValue: Integer = 25; Tolerance: Integer = 5): TOCRShadowFilter; static;
Example:
TOCRShadowFilter.Create();
The LocateText function does not OCR! An "image" of the desired text is generated with TextToMatrix/TextToTPA and searched for. Again quite similar to Simba's FindBitmap.
- Works well with
TOCRAnyColorFilter. Although this is slower. - Will not work if the spacing between characters is dynamic.





