Skip to content

Commit

Permalink
Add pixel font ocr
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Dec 24, 2024
1 parent 54535df commit 8becbb1
Show file tree
Hide file tree
Showing 8 changed files with 528 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Examples/image_drawtext.simba
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ begin
myImage.DrawColor := Colors.RED;
myImage.DrawBox(myBox);
myImage.DrawColor := Colors.BLACK;
myImage.DrawText(Now.ToString('c'), myBox, [EDrawTextAlign.CENTER, EDrawTextAlign.VERTICAL_CENTER]);
myImage.DrawText(Now.ToString('c'), myBox, [EImageTextAlign.CENTER, EImageTextAlign.VERTICAL_CENTER]);

myImage.FontBold := True;
myImage.FontSize := 50;
Expand Down
12 changes: 6 additions & 6 deletions Examples/mouse_teleport_event.simba
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var
TPA: TPointArray; // stores the teleport events so we can view at the end

procedure MouseTeleportEvent(var Sender: TTarget; P: TPoint);
procedure MouseTeleportEvent(var Target: TTarget; Data: TTargetEventData);
begin
WriteLn('Mouse teleported to: ', P);
TPA += P;
WriteLn('Mouse teleported to: ', Data.MouseTeleport);
TPA += [Data.MouseTeleport.X, Data.MouseTeleport.Y];
end;

var
Event: TMouseTeleportEvent;
Event: TTargetEvent;
begin
Event := Target.AddMouseEvent(@MouseTeleportEvent);
Event := Target.AddEvent(ETargetEventType.MOUSE_TELEPORT, @MouseTeleportEvent);
Target.MouseTeleport([200,200]);
Target.MouseMove([600,600]);
Target.RemoveMouseEvent(Event); // Remove the event
Target.RemoveEvent(ETargetEventType.MOUSE_TELEPORT, Event); // Remove the event

Target.MouseMove([200, 600]); // The event has been removed so this wont be "recorded" when we show the path

Expand Down
2 changes: 2 additions & 0 deletions Examples/randomleft.simba
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Random left returns numbers weighted to the left number

const
SampleCount = 1000000;
Range = 10;
Expand Down
99 changes: 99 additions & 0 deletions Source/script/imports/simba.import_bitmapfontocr.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
unit simba.import_bitmapfontocr;

{$i simba.inc}

interface

uses
Classes, SysUtils,
simba.base, simba.script;

procedure ImportBitmapFontOCR(Script: TSimbaScript);

implementation

uses
lptypes, lpvartypes,
simba.pixelocr,
simba.image;

type
PPixelFont = ^TPixelFont;
PPixelOCR = ^TPixelOCR;

procedure _LapePixelOCR_LoadFont(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPixelFont(Result)^ := PPixelOCR(Params^[0])^.LoadFont(PString(Params^[1])^, PInteger(Params^[2])^);
end;

procedure _LapePixelOCR_Recognize1(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PString(Result)^ := PPixelOCR(Params^[0])^.Recognize(PSimbaImage(Params^[1])^, PPixelFont(Params^[2])^, PPoint(Params^[3])^);
end;

procedure _LapePixelOCR_Recognize2(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PString(Result)^ := PPixelOCR(Params^[0])^.Recognize(PSimbaImage(Params^[1])^, PPixelFont(Params^[2])^, PBox(Params^[3])^);
end;

procedure _LapePixelOCR_RecognizeLines(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PStringArray(Result)^ := PPixelOCR(Params^[0])^.RecognizeLines(PSimbaImage(Params^[1])^, PPixelFont(Params^[2])^, PBox(Params^[3])^);
end;

procedure ImportBitmapFontOCR(Script: TSimbaScript);
begin
with Script.Compiler do
begin
addGlobalType([
'record',
' Glyphs: array of record',
' Value: Char;',
' Width: Integer;',
' Height: Integer;',
'',
' points: TPointArray;',
' shadow: TPointArray;',
' background: TPointArray;',
'',
' croppedWidth: Integer;',
'',
' BestMatch: Integer;',
' end;',
'',
' Height: Integer;',
' SpaceWidth: Integer;',
'end;'],
'TPixelFont'
);

addGlobalType([
'record',
' Text: String;',
' Hits: Integer;',
' Bounds: TBox;',
'end;'],
'TPixelOCRMatch'
);

addGlobalType([
'record',
' Tolerance: Single;',
' ShadowTolerance: Single;',
' Blacklist: set of Char;',
' MaxWalk: Integer;',
' Matches: array of TPixelOCRMatch;',
'end'],
'TPixelOCR'
);

addGlobalFunc('function TPixelOCR.LoadFont(dir: String; SpaceWidth: Integer): TPixelFont;', @_LapePixelOCR_LoadFont);

addGlobalFunc('function TPixelOCR.Recognize(img: TImage; font: TPixelFont; p: TPoint): String; overload;', @_LapePixelOCR_Recognize1);
addGlobalFunc('function TPixelOCR.Recognize(img: TImage; font: TPixelFont; bounds: TBox): String; overload;', @_LapePixelOCR_Recognize2);
addGlobalFunc('function TPixelOCR.RecognizeLines(img: TImage; font: TPixelFont; bounds: TBox): TStringArray;', @_LapePixelOCR_RecognizeLines);
end;
end;

end.

Loading

0 comments on commit 8becbb1

Please sign in to comment.