From 108bf37d6fbd87b4319991e3624bfa0b30269bfa Mon Sep 17 00:00:00 2001 From: Raymond Date: Sat, 6 Feb 2010 18:18:42 +0000 Subject: [PATCH] Fixed some bugs in the OCR and TPA. git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@528 3f818213-9676-44b0-a9b4-5e4c4e03d09d --- trunk/Units/MMLCore/fontloader.pas | 2 ++ trunk/Units/MMLCore/ocr.pas | 36 +++++++++++++++++------------- trunk/Units/MMLCore/tpa.pas | 13 +++++++++-- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/trunk/Units/MMLCore/fontloader.pas b/trunk/Units/MMLCore/fontloader.pas index d3943c0..75241e2 100644 --- a/trunk/Units/MMLCore/fontloader.pas +++ b/trunk/Units/MMLCore/fontloader.pas @@ -130,6 +130,8 @@ begin Result.Data.Height := Self.Data.Height; Result.Data.inputs := Self.Data.inputs; Result.Data.outputs := Self.Data.outputs; + Result.Data.max_height:= Self.Data.max_height; + Result.Data.max_width:= Self.Data.max_width; end; function TMFonts.GetFontByIndex(Index : integer): TMfont; diff --git a/trunk/Units/MMLCore/ocr.pas b/trunk/Units/MMLCore/ocr.pas index a99ba13..e385bb0 100644 --- a/trunk/Units/MMLCore/ocr.pas +++ b/trunk/Units/MMLCore/ocr.pas @@ -729,52 +729,56 @@ var begin fD := Fonts.GetFont(font); -{ writeln(format('W, H: %d, %d', [fD.max_width, fd.max_height])); } + {writeln(format('W, H: %d, %d', [fD.max_width, fd.max_height]));} TClient(Client).IOManager.GetDimensions(w, h); { writeln('Dimensions: (' + inttostr(w) + ', ' + inttostr(h) + ')'); } { Get the text points } SetLength(TPA, 0); + if (atY + fD.max_height -1) >= h then + raise exception.createFMT('You are trying to get text that is out of is origin y-coordinate: %d',[aty]); + TClient(Client).MFinder.FindColorsTolerance(TPA, color, atX, atY, - min(fD.max_width * len, w - atX - 1), - fD.max_height - 1, tol); + min(atX + fD.max_width * len, w - 1), + atY + fD.max_height - 1, tol); { b := GetTPABounds(TPA); bmp := TMufasaBitmap.Create; bmp.SetSize(b.x2+1,b.y2+1); bmp.DrawTPA(TPA, clRed); - bmp.SaveToFile('/tmp/found.bmp'); } + bmp.SaveToFile('c:\found.bmp');} { Split the text points into something usable. } { +1 because splittpa will not split well if we use 0 space ;) } STPA := SplitTPAEx(TPA, minvspacing+1, hspacing+1); { bmp.DrawATPA(STPA); - bmp.SaveToFile('/tmp/found2.bmp'); - bmp.Free; } + bmp.SaveToFile('c:\found2.bmp'); + bmp.Free; - { for i := 0 to high(STPA) do + for i := 0 to high(STPA) do begin b := GetTPABounds(STPA[i]); bmp := TMufasaBitmap.Create; bmp.SetSize(b.x2+1,b.y2+1); bmp.DrawTPA(STPA[i], clRed); - bmp.SaveToFile('/tmp/t_' + inttostr(i) + '.bmp'); + bmp.SaveToFile('c:\t_' + inttostr(i) + '.bmp'); bmp.Free; - end; } + end; } - SortATPAFrom(STPA, Point(0, 0)); - SortATPAFromFirstPoint(STPA, Point(0, 0)); + SortATPAFrom(STPA, Point(0, atY)); + SortATPAFromFirstPoint(STPA, Point(0, atY)); - { for i := 0 to high(STPA) do +{ for i := 0 to high(STPA) do begin b := GetTPABounds(STPA[i]); bmp := TMufasaBitmap.Create; - bmp.SetSize(b.x2+1,b.y2+1); - bmp.DrawTPA(STPA[i], clRed); - bmp.SaveToFile('/tmp/s_' + inttostr(i) + '.bmp'); + bmp.SetSize(b.x2-b.x1 + 2,b.y2-b.y1 + 2); + for j := 0 to high(STPA[i]) do + bmp.FastSetPixel(stpa[i][j].x-b.x1,stpa[i][j].y-b.y1,clred); + bmp.SaveToFile('c:\s_' + inttostr(i) + '.bmp'); bmp.Free; - end; } + end; } { We no longer need the points in TPA } SetLength(TPA, 0); diff --git a/trunk/Units/MMLCore/tpa.pas b/trunk/Units/MMLCore/tpa.pas index 0f6f0c6..6e6b257 100644 --- a/trunk/Units/MMLCore/tpa.pas +++ b/trunk/Units/MMLCore/tpa.pas @@ -1118,6 +1118,7 @@ function FindTextTPAinTPA(Height : integer; SearchTPA, TotalTPA: TPointArray; va var Len, I,II,LenSearch,LenTPA,xOff,yOff,x,y: integer; tx,ty,MatchCount : integer; + Found : boolean; Screen : Array of Array of Boolean; ScreenBox,SearchBox : TBox; InversedTPA : TPointArray; @@ -1176,15 +1177,23 @@ begin; if ty > 0 then if ((SearchBox.x2 + tx) <= ScreenBox.x2) and ((SearchBox.y2 + ty) <= ScreenBox.y2) then begin; + Found := false; For II := 0 to LenSearch do if Screen[tx + SearchTPA[II].x ][ty + SearchTPA[II].y] = False then + begin + Found := true; Break; - if (II > LenSearch) then + end; + if (not Found) then begin; + Found := false; For II := 0 to LenTPA do if Screen[tx + InversedTPA[II].x ][ty + InversedTPA[II].y] = True then + begin + Found := true; Break; - if (II > LenTPA) then + end; + if (not Found) then begin; MatchCount := MatchCount + 1; SetLength(Matches,MatchCount);