Skip to content

Commit 654381e

Browse files
committed
Update simba.pixelocr.pas
1 parent dd7c0a9 commit 654381e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Source/simba.pixelocr.pas

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ TPixelOCR = record
7878
const
7979
ALPHA_NUM_SYMBOLS = ['a'..'z', 'A'..'Z', '0'..'9', '%', '&', '#', '$', '[', ']', '{', '}', '@', '!', '?'];
8080
var
81+
AlphaNumSymbolTableInitialized: Boolean = False;
8182
AlphaNumSymbolTable: array [Char] of Boolean;
8283

8384
implementation
@@ -118,7 +119,7 @@ function IsAlphaNumSym(const text: string): Boolean; inline;
118119
var
119120
i, count, needed: Integer;
120121
begin
121-
//50% of text
122+
count := 0;
122123
needed := (Length(text) * 50 + 99) div 100;
123124

124125
for i := 1 to Length(text) do
@@ -261,6 +262,7 @@ function TPixelOCR._RecognizeX(const Image: TSimbaImage; const Font: PPixelFont;
261262
Result.Bounds.Y1 := $FFFFFF;
262263
Space := 0;
263264

265+
BestGlyph := @Font^.Glyphs[0];
264266
Lo := @Font^.Glyphs[0];
265267
Hi := @Font^.Glyphs[High(Font^.Glyphs)];
266268

@@ -611,6 +613,14 @@ function TPixelOCR.RecognizeLines(Image: TSimbaImage; constref Font: TPixelFont;
611613
if (Length(Font.Glyphs) = 0) then
612614
SimbaException('Font is empty');
613615

616+
if not AlphaNumSymbolTableInitialized then
617+
begin
618+
FillChar(AlphaNumSymbolTable, SizeOf(AlphaNumSymbolTable), False);
619+
for i to High(ALPHA_NUM_SYMBOLS) do
620+
AlphaNumSymbolTable[ALPHA_NUM_SYMBOLS[i]] := True;
621+
AlphaNumSymbolTableInitialized := True;
622+
end;
623+
614624
Temp := Self;
615625
Temp.Whitelist := ALPHA_NUM_SYMBOLS;
616626
Temp.MaxLen := 1;
@@ -646,10 +656,4 @@ function TPixelOCR.RecognizeLines(Image: TSimbaImage; constref Font: TPixelFont;
646656
end;
647657
end;
648658

649-
initialization
650-
var i: Integer;
651-
FillChar(AlphaNumSymbolTable, SizeOf(AlphaNumSymbolTable), False);
652-
for i to High(ALPHA_NUM_SYMBOLS) do
653-
AlphaNumSymbolTable[ALPHA_NUM_SYMBOLS[i]] := True;
654-
655659
end.

0 commit comments

Comments
 (0)