1
0
mirror of https://github.com/moparisthebest/Simba synced 2025-01-30 23:00:18 -05:00

GetTextAt initial implementation.

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@499 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Wizzup? 2010-01-30 02:58:03 +00:00
parent 6d839ec43a
commit 78a354ecea
3 changed files with 219 additions and 102 deletions

View File

@ -30,15 +30,15 @@
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<Units Count="29">
<Units Count="31">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
<CursorPos X="45" Y="90"/>
<TopLine Value="72"/>
<CursorPos X="3" Y="98"/>
<TopLine Value="79"/>
<EditorIndex Value="0"/>
<UsageCount Value="83"/>
<UsageCount Value="86"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -54,7 +54,7 @@
<CursorPos X="21" Y="53"/>
<TopLine Value="35"/>
<EditorIndex Value="9"/>
<UsageCount Value="36"/>
<UsageCount Value="37"/>
<Loaded Value="True"/>
</Unit2>
<Unit3>
@ -76,8 +76,8 @@
<UnitName Value="colour_conv"/>
<CursorPos X="18" Y="332"/>
<TopLine Value="309"/>
<EditorIndex Value="4"/>
<UsageCount Value="16"/>
<EditorIndex Value="6"/>
<UsageCount Value="17"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
@ -85,8 +85,8 @@
<UnitName Value="finder"/>
<CursorPos X="31" Y="1907"/>
<TopLine Value="1890"/>
<EditorIndex Value="2"/>
<UsageCount Value="39"/>
<EditorIndex Value="4"/>
<UsageCount Value="40"/>
<Loaded Value="True"/>
</Unit6>
<Unit7>
@ -101,17 +101,17 @@
<UnitName Value="MufasaTypes"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="34"/>
<EditorIndex Value="3"/>
<UsageCount Value="37"/>
<EditorIndex Value="5"/>
<UsageCount Value="38"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<UnitName Value="ocr"/>
<CursorPos X="7" Y="729"/>
<TopLine Value="713"/>
<EditorIndex Value="10"/>
<UsageCount Value="36"/>
<CursorPos X="110" Y="825"/>
<TopLine Value="766"/>
<EditorIndex Value="1"/>
<UsageCount Value="37"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
@ -137,10 +137,10 @@
<Unit13>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<UnitName Value="bitmaps"/>
<CursorPos X="51" Y="867"/>
<TopLine Value="1"/>
<EditorIndex Value="1"/>
<UsageCount Value="34"/>
<CursorPos X="38" Y="45"/>
<TopLine Value="24"/>
<EditorIndex Value="3"/>
<UsageCount Value="35"/>
<Loaded Value="True"/>
</Unit13>
<Unit14>
@ -181,18 +181,14 @@
<UnitName Value="dtm"/>
<CursorPos X="29" Y="31"/>
<TopLine Value="411"/>
<EditorIndex Value="6"/>
<UsageCount Value="32"/>
<Loaded Value="True"/>
</Unit19>
<Unit20>
<Filename Value="../../Units/MMLCore/dtmutil.pas"/>
<UnitName Value="dtmutil"/>
<CursorPos X="1" Y="89"/>
<TopLine Value="1"/>
<EditorIndex Value="5"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit20>
<Unit21>
<Filename Value="../../../Documents/fpc/packages/fcl-base/src/custapp.pp"/>
@ -207,7 +203,7 @@
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="7"/>
<UsageCount Value="16"/>
<UsageCount Value="17"/>
<Loaded Value="True"/>
</Unit22>
<Unit23>
@ -240,8 +236,8 @@
<UnitName Value="os_linux"/>
<CursorPos X="66" Y="54"/>
<TopLine Value="24"/>
<EditorIndex Value="11"/>
<UsageCount Value="14"/>
<EditorIndex Value="10"/>
<UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit27>
<Unit28>
@ -250,131 +246,127 @@
<CursorPos X="53" Y="62"/>
<TopLine Value="34"/>
<EditorIndex Value="8"/>
<UsageCount Value="13"/>
<UsageCount Value="14"/>
<Loaded Value="True"/>
</Unit28>
<Unit29>
<Filename Value="../../Units/MMLCore/tpa.pas"/>
<UnitName Value="tpa"/>
<CursorPos X="33" Y="535"/>
<TopLine Value="514"/>
<EditorIndex Value="2"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit29>
<Unit30>
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
<UnitName Value="IOManager"/>
<CursorPos X="78" Y="433"/>
<TopLine Value="416"/>
<UsageCount Value="10"/>
</Unit30>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<JumpHistory Count="25" HistoryIndex="24">
<Position1>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="18" Column="48" TopLine="1"/>
<Filename Value="project1.lpr"/>
<Caret Line="88" Column="28" TopLine="70"/>
</Position1>
<Position2>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="55" Column="47" TopLine="37"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="777" Column="48" TopLine="759"/>
</Position2>
<Position3>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="56" Column="74" TopLine="37"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="744" Column="50" TopLine="726"/>
</Position3>
<Position4>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="156" Column="24" TopLine="133"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="775" Column="37" TopLine="757"/>
</Position4>
<Position5>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="31" Column="66" TopLine="25"/>
<Caret Line="57" Column="29" TopLine="33"/>
</Position5>
<Position6>
<Filename Value="project1.lpr"/>
<Caret Line="89" Column="15" TopLine="67"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="739" Column="56" TopLine="718"/>
</Position6>
<Position7>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="53" Column="21" TopLine="35"/>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="5" Column="87" TopLine="1"/>
</Position7>
<Position8>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="740" Column="27" TopLine="722"/>
<Caret Line="767" Column="27" TopLine="741"/>
</Position8>
<Position9>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="742" Column="39" TopLine="722"/>
<Caret Line="763" Column="10" TopLine="743"/>
</Position9>
<Position10>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="713" Column="14" TopLine="708"/>
<Filename Value="../../Units/MMLCore/tpa.pas"/>
<Caret Line="49" Column="23" TopLine="31"/>
</Position10>
<Position11>
<Filename Value="project1.lpr"/>
<Caret Line="86" Column="16" TopLine="67"/>
<Filename Value="../../Units/MMLCore/tpa.pas"/>
<Caret Line="50" Column="23" TopLine="31"/>
</Position11>
<Position12>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="40" Column="31" TopLine="22"/>
<Filename Value="../../Units/MMLCore/tpa.pas"/>
<Caret Line="56" Column="23" TopLine="31"/>
</Position12>
<Position13>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="751" Column="17" TopLine="722"/>
<Caret Line="189" Column="48" TopLine="94"/>
</Position13>
<Position14>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="55" Column="23" TopLine="37"/>
<Caret Line="4" Column="70" TopLine="1"/>
</Position14>
<Position15>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="761" Column="40" TopLine="702"/>
<Caret Line="721" Column="16" TopLine="712"/>
</Position15>
<Position16>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="763" Column="36" TopLine="735"/>
<Caret Line="732" Column="72" TopLine="711"/>
</Position16>
<Position17>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="737" Column="13" TopLine="724"/>
<Caret Line="806" Column="43" TopLine="786"/>
</Position17>
<Position18>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="734" Column="74" TopLine="712"/>
<Filename Value="project1.lpr"/>
<Caret Line="95" Column="37" TopLine="67"/>
</Position18>
<Position19>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="741" Column="39" TopLine="716"/>
<Filename Value="project1.lpr"/>
<Caret Line="197" Column="69" TopLine="166"/>
</Position19>
<Position20>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="726" Column="62" TopLine="716"/>
<Filename Value="project1.lpr"/>
<Caret Line="89" Column="20" TopLine="71"/>
</Position20>
<Position21>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="741" Column="39" TopLine="723"/>
<Filename Value="project1.lpr"/>
<Caret Line="88" Column="4" TopLine="71"/>
</Position21>
<Position22>
<Filename Value="project1.lpr"/>
<Caret Line="88" Column="36" TopLine="72"/>
<Caret Line="87" Column="3" TopLine="71"/>
</Position22>
<Position23>
<Filename Value="project1.lpr"/>
<Caret Line="84" Column="48" TopLine="72"/>
<Caret Line="95" Column="21" TopLine="71"/>
</Position23>
<Position24>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="29" Column="12" TopLine="1"/>
<Filename Value="project1.lpr"/>
<Caret Line="94" Column="57" TopLine="78"/>
</Position24>
<Position25>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="67" Column="9" TopLine="49"/>
<Filename Value="project1.lpr"/>
<Caret Line="98" Column="3" TopLine="74"/>
</Position25>
<Position26>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="68" Column="61" TopLine="49"/>
</Position26>
<Position27>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="159" Column="42" TopLine="141"/>
</Position27>
<Position28>
<Filename Value="../../Units/MMLCore/ocrutil.pas"/>
<Caret Line="216" Column="25" TopLine="198"/>
</Position28>
<Position29>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="732" Column="24" TopLine="710"/>
</Position29>
<Position30>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="741" Column="10" TopLine="711"/>
</Position30>
</JumpHistory>
</ProjectOptions>
<CompilerOptions>
@ -384,17 +376,17 @@
<OtherUnitFiles Value="$(ProjPath)/../../Units/MMLCore/;$(ProjPath)/../../Units/Misc/;$(ProjPath)/../../Units/MMLAddon/;$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/$(LCLWidgetType)/;$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/;$(ProjPath)/../../Units/Linux/;$(LazarusDir)/components/mouseandkeyinput/"/>
</SearchPaths>
<CodeGeneration>
<Checks>
<IOChecks Value="True"/>
<RangeChecks Value="True"/>
<OverflowChecks Value="True"/>
<StackChecks Value="True"/>
</Checks>
<VerifyObjMethodCallValidity Value="True"/>
<Optimizations>
<VariablesInRegisters Value="True"/>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="True"/>
<GenerateDwarf Value="True"/>
</Debugging>
</Linking>
<Other>
<CustomOptions Value="-dM_MEMORY_DEBUG"/>
<CompilerPath Value="$(CompPath)"/>

View File

@ -61,6 +61,7 @@ var
Time: DWord;
C: TClient;
I: Integer;
T: DWord;
dtm: pdtm;
p:tpointarray;
bmp: TMufasaBitmap;
@ -83,11 +84,25 @@ begin
{ add your program here }
C := TClient.Create('.');
C.MOCR.InitTOCR('/home/merlijn/Programs/mufasa/Fonts/');
bmp := TMufasaBitmap.Create;
//bmp.LoadFromFile('/home/merlijn/Programs/mufasa/pics/smallchars.bmp');
bmp.LoadFromFile('/home/merlijn/Programs/mufasa/pics/UpChars.bmp');
C.IOManager.SetTarget(bmp);
C.MOCR.InitTOCR('/home/merlijn/Programs/mufasa/trunk/Fonts/');
// small chars
t := GetTickCount;
for i := 0 to 100 do
C.MOCR.GetTextAt(0,0,0,3,2,65278,2,100,'UpChars');
//C.MOCR.GetTextAt(0,0,1,3,2,0,0,100,'SmallChars');
writeln(floattostr((gettickcount - t) / 100.0) + ' ms');
writeln(C.MOCR.GetTextAt(0,0,0,3,2,65278,2,100,'UpChars'));
//writeln(C.MOCR.GetTextAt(0,0,1,3,2,0,0,100,'SmallChars'));
bmp := C.MOCR.TextToFontBitmap('Danke schon', 'SmallChars');
bmp.SaveToFile('/tmp/wat.bmp');
{ bmp := C.MOCR.TextToFontBitmap('Welcome to RuneScape.', 'SmallChars');
bmp.SaveToFile('/tmp/wat.bmp'); }
{ bmp := TMufasaBitmap.Create;
bmp.SetSize(CW,CH);
@ -138,6 +153,7 @@ begin
//bmp.OnDestroy:=nil;
//bmp.Free;
bmp.Free;
C.Free;
// stop program loop

View File

@ -54,7 +54,8 @@ uses
procedure FilterShadowBitmap(bmp: TMufasaBitmap);
procedure FilterCharsBitmap(bmp: TMufasaBitmap);
function GetTextAt(atX, atY, minspacing, maxspacing, color, tol, len: integer; font: string): string;
function GetTextAt(atX, atY, minvspacing, maxvspacing, hspacing,
color, tol, len: integer; font: string): string;
function TextToFontTPA(Text, font: String; var w, h: integer): TPointArray;
function TextToFontBitmap(Text, font: String): TMufasaBitmap;
function TextToMask(Text, font: String): TMask;
@ -549,6 +550,8 @@ begin
// split chars
chars_2d := SplitTPAEx(chars,1,charsbmp.height);
{ FIXME: This only sorts the points in every TPA }
SortATPAFrom(chars_2d, point(0,0));
for x := 0 to high(chars_2d) do
begin
@ -684,9 +687,15 @@ begin
result:=result+' ';
lb:=b;
end;
for i := 0 to high(t) do
t[i] := t[i] - point(b.x1,b.y1);
{
FIXME: If the TPA is too large, we can still go beyond n's bounds.
We should check the bounds in GetTextPointsIn
}
for i := 0 to high(thachars[j]) do
begin
n[(thachars[j][i].x) + ((thachars[j][i].y) * font.width)] := 1;
@ -704,19 +713,119 @@ begin
result := GetUpTextAtEx(atX, atY, false);
end;
function TMOCR.GetTextAt(atX, atY, minspacing, maxspacing, color, tol, len: integer; font: string): string;
function TMOCR.GetTextAt(atX, atY, minvspacing, maxvspacing, hspacing,
color, tol, len: integer; font: string): string;
var
b, lb: TBox;
i, j, w, h: Integer;
lbset: boolean;
n: TNormArray;
fD: TocrData;
TPA: TPointArray;
STPA: T2DPointArray;
bmp:tmufasabitmap;
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);
//TClient(Client).MFinder.FindColorsTolerance(TPA, color, atX, atY, {fuck}0, {fuck}0, tol);
TClient(Client).MFinder.FindColorsTolerance(TPA, color, atX, atY,
min(fD.max_width * len, w - atX - 1),
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'); }
{ 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; }
{ 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.Free;
end; }
SortATPAFrom(STPA, Point(0, 0));
SortATPAFromFirstPoint(STPA, Point(0, 0));
{ 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.Free;
end; }
{ We no longer need the points in TPA }
SetLength(TPA, 0);
fillchar(b, sizeof(tbox), 0);
fillchar(lb, sizeof(tbox), 0);
lbset := false;
SetLength(Result, 0);
SetLength(n, (fd.width + 1) * (fd.height + 1));
for i := 0 to min(high(STPA),len) do
begin
for j := 0 to high(n) do
n[j] := 0;
TPA := STPA[i];
b := GetTPABounds(TPA);
if not lbset then
begin
lb:=b;
lbset:=true;
end else
begin
{ if b.x1 - lb.x2 < minvspacing then
begin
writeln('GetTextAt: not enough spacing between chars...');
lb := b;
continue;
end; }
if b.x1 - lb.x2 > maxvspacing then
result:=result+' ';
lb:=b;
end;
for j := 0 to high(tpa) do
tpa[j] := tpa[j] - point(b.x1,b.y1);
{
FIXME: We never check it j actually fits in n's bounds...
This *WILL* error when wrong spaces etc are passed.
Added a temp resolution.
}
for j := 0 to high(tpa) do
begin
if (tpa[j].x) + ((tpa[j].y) * fD.width) <= high(n) then
n[(tpa[j].x) + ((tpa[j].y) * fD.width)] := 1
else
raise Exception.Create('The automatically split characters are too wide. Try decreasing minspacing');
end;
result := result + GuessGlyph(n, fD);
end;
end;
function TMOCR.TextToFontTPA(Text, font: String; var w, h: integer): TPointArray;