Skip to content

Commit 72af183

Browse files
committed
try to fix recognize lines bug
1 parent c3abf60 commit 72af183

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

Source/simba.pixelocr.pas

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -578,28 +578,15 @@ function TPixelOCR.Recognize(Image: TSimbaImage; constref Font: TPixelFont; Boun
578578
end;
579579

580580
function TPixelOCR.RecognizeLines(Image: TSimbaImage; constref Font: TPixelFont; Bounds: TBox): TStringArray;
581-
581+
var Temp: TPixelOCR;
582582
function MaybeRecognize(const X, Y: Integer; const isBinary: Boolean; out Match: TPixelOCRMatch): Boolean;
583-
var
584-
Temp: TPixelOCR;
585583
begin
586584
Result := False;
587-
588-
// use a copy here since we change these properties
589-
Temp := Self;
590-
Temp.Whitelist := ALPHA_NUM_SYMBOLS;
591-
Temp.MaxLen := 1;
592-
Temp.MaxWalk := 0;
593-
594585
// Find something on a row that isn't a small character
595586
Match := Temp._RecognizeX(Image, @Font, X, Y, isBinary);
596587
if (Match.Hits > 0) then
597588
begin
598589
// OCR the row and some extra rows
599-
Temp.Whitelist := Self.Whitelist;
600-
Temp.MaxWalk := 0;
601-
Temp.MaxLen := 0;
602-
603590
Match := Temp._RecognizeXY(Image, @Font, X, Y, Font.MaxGlyphHeight div 2, isBinary);
604591
// Ensure that actual Text was extracted, not just a symbol mess of short or small character symbols.
605592
if ContainsAlphaNumSym(Match.Text) then
@@ -614,6 +601,14 @@ function TPixelOCR.RecognizeLines(Image: TSimbaImage; constref Font: TPixelFont;
614601
if (Length(Font.Glyphs) = 0) then
615602
SimbaException('Font is empty');
616603

604+
Temp := Self;
605+
Temp.Whitelist := ALPHA_NUM_SYMBOLS;
606+
Temp.MaxLen := 1;
607+
Temp.MaxWalk := 0;
608+
Temp.Whitelist := Self.Whitelist;
609+
Temp.MaxWalk := 0;
610+
Temp.MaxLen := 0;
611+
617612
Result := [];
618613
Matches := [];
619614

@@ -634,6 +629,7 @@ function TPixelOCR.RecognizeLines(Image: TSimbaImage; constref Font: TPixelFont;
634629
// Now we can confidently skip this search line by a jump, but we dont skip fully in case of close/overlapping Text
635630
// So we divide the texts max glyph Height by 2 and subtract that from the lower end of the found bounds.
636631
Bounds.Y1 := Max(Bounds.Y1, Match.Bounds.Y2 - (Font.MaxGlyphHeight div 2));
632+
Continue;
637633
end;
638634

639635
Bounds.Y1 += 1;

0 commit comments

Comments
 (0)