Fixed some bugs in the OCR and TPA.

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@528 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Raymond 2010-02-06 18:18:42 +00:00
parent 82e54e5b07
commit 108bf37d6f
3 changed files with 33 additions and 18 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);