2009-10-23 18:21:14 -04:00
|
|
|
program project1;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
|
|
|
cthreads,
|
|
|
|
{$ENDIF}{$ENDIF}
|
|
|
|
Classes, SysUtils, CustApp,
|
|
|
|
Forms,Interfaces,
|
2009-10-25 16:55:50 -04:00
|
|
|
LCLIntf,
|
2009-11-01 06:07:46 -05:00
|
|
|
Client,
|
2009-12-17 09:54:21 -05:00
|
|
|
bitmaps,x ,mufasatypes,dtm,dtmutil, ocrutil ,graphics ,colour_conv,math
|
2009-10-23 18:21:14 -04:00
|
|
|
|
2009-10-25 16:55:50 -04:00
|
|
|
|
2009-10-23 18:21:14 -04:00
|
|
|
{ you can add units after this };
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ MufasaTests }
|
|
|
|
|
|
|
|
MufasaTests = class(TCustomApplication)
|
|
|
|
protected
|
|
|
|
procedure DoRun; override;
|
|
|
|
public
|
|
|
|
constructor Create(TheOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure WriteHelp; virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ MufasaTests }
|
|
|
|
|
2009-12-04 15:57:00 -05:00
|
|
|
const
|
|
|
|
CW = 800;
|
|
|
|
CH = 600;
|
|
|
|
|
|
|
|
function randomdtm(a: integer): pdtm;
|
|
|
|
var
|
|
|
|
i: integer;
|
|
|
|
begin
|
|
|
|
initdtm(result, a);
|
|
|
|
for i := 1 to result.l - 1 do
|
|
|
|
begin
|
|
|
|
result.p[i] := point(random(30) - 15, random(30) - 15);
|
|
|
|
result.c[i] := 0;
|
|
|
|
result.t[i] := random(255);
|
|
|
|
result.asz [i] := random(5);
|
|
|
|
result.ash[i] := 0;
|
|
|
|
writeln(format('dtm: (%d, %d) c: %d, t: %d, asz: %d', [result.p[i].x,
|
|
|
|
result.p[i].y, result.c[i], result.t[i], result.asz[i]]));
|
|
|
|
end;
|
|
|
|
result.c[0] := 255;
|
|
|
|
end;
|
|
|
|
|
2009-10-23 18:21:14 -04:00
|
|
|
procedure MufasaTests.DoRun;
|
|
|
|
|
2009-12-17 09:54:21 -05:00
|
|
|
const
|
|
|
|
ocr_Limit_High = 192;
|
|
|
|
ocr_Limit_Low = 65;
|
|
|
|
|
2009-10-23 18:21:14 -04:00
|
|
|
var
|
|
|
|
ErrorMsg: String;
|
2009-10-25 16:55:50 -04:00
|
|
|
Time: DWord;
|
2009-10-23 18:21:14 -04:00
|
|
|
C: TClient;
|
2009-12-17 09:54:21 -05:00
|
|
|
I, w, h,x,y: Integer;
|
2009-12-01 18:41:43 -05:00
|
|
|
dtm: pdtm;
|
|
|
|
p:tpointarray;
|
2009-12-17 09:54:21 -05:00
|
|
|
bmp, bmprs: TMufasaBitmap;
|
|
|
|
cyan, itemc:integer;
|
|
|
|
r,g,b:integer;
|
|
|
|
t:Dword;
|
2009-10-25 16:55:50 -04:00
|
|
|
|
2009-10-23 18:21:14 -04:00
|
|
|
begin
|
|
|
|
// quick check parameters
|
|
|
|
ErrorMsg:=CheckOptions('h','help');
|
|
|
|
if ErrorMsg<>'' then begin
|
|
|
|
ShowException(Exception.Create(ErrorMsg));
|
|
|
|
Terminate;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// parse parameters
|
|
|
|
if HasOption('h','help') then begin
|
|
|
|
WriteHelp;
|
|
|
|
Terminate;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ add your program here }
|
2009-12-17 09:54:21 -05:00
|
|
|
cyan := rgbtocolor(0,255,255);
|
|
|
|
|
|
|
|
|
|
|
|
bmprs := TMufasaBitmap.Create;
|
2009-12-17 09:57:53 -05:00
|
|
|
bmprs.LoadFromFile('/home/merlijn/Programs/mufasa/pics/uptext7.png');
|
2009-10-23 18:21:14 -04:00
|
|
|
C := TClient.Create;
|
2009-12-17 09:54:21 -05:00
|
|
|
C.MWindow.SetTarget(bmprs);
|
|
|
|
C.MWindow.GetDimensions(w, h);
|
2009-10-25 16:55:50 -04:00
|
|
|
|
2009-12-01 18:41:43 -05:00
|
|
|
bmp := TMufasaBitmap.Create;
|
2009-12-17 09:54:21 -05:00
|
|
|
bmp.CopyClientToBitmap(C.MWindow, True, 0, 0, 450, 50);
|
|
|
|
|
|
|
|
t:=gettickcount;
|
|
|
|
|
|
|
|
for y := 0 to bmp.Height - 1 do
|
|
|
|
for x := 0 to bmp.Width - 1 do
|
|
|
|
begin
|
|
|
|
colortorgb(bmp.fastgetpixel(x,y),r,g,b);
|
|
|
|
// the abs(g-b) < 15 seems to help heaps when taking out crap points
|
2009-12-17 09:57:53 -05:00
|
|
|
if (r > ocr_Limit_High) and (g > ocr_Limit_High) and (b > ocr_Limit_High){ and (abs(g-b) < 15)} then
|
2009-12-17 09:54:21 -05:00
|
|
|
begin
|
|
|
|
bmp.fastsetpixel(x,y,clwhite);
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
if (r < ocr_Limit_Low) and (g > ocr_Limit_High) and (b > ocr_Limit_High) then
|
|
|
|
begin
|
|
|
|
bmp.fastsetpixel(x,y,cyan);
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
if (r < ocr_Limit_Low) and (g > ocr_Limit_High) and (b < ocr_Limit_Low) then
|
|
|
|
begin
|
|
|
|
bmp.fastsetpixel(x,y,rgbtocolor(0,255,0));
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
if(r > ocr_Limit_High) and (g > 100) and (g < ocr_Limit_High) and (b > 30) and (b < 90) then
|
|
|
|
begin
|
|
|
|
bmp.fastsetpixel(x,y,rgbtocolor(255,127,0));
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
if(r > ocr_Limit_High) and (g > ocr_Limit_High) and (b < ocr_Limit_Low) then
|
|
|
|
begin
|
|
|
|
bmp.fastsetpixel(x,y,rgbtocolor(255,255,0));
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
// better use g < 40 than ocr_Limit_Low imo
|
|
|
|
if (r > ocr_Limit_High) and (g < ocr_Limit_Low) and (b < ocr_Limit_Low) then
|
|
|
|
begin
|
|
|
|
bmp.fastsetpixel(x,y,rgbtocolor(255,0,0));
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
bmp.fastsetpixel(x,y,0);
|
|
|
|
end;
|
|
|
|
writeln(inttostr(gettickcount-t));
|
|
|
|
{
|
|
|
|
bmp.Posterize(130); // ~ 3
|
|
|
|
// bmp.Contrast(3);
|
|
|
|
|
|
|
|
for y := 0 to bmp.Height - 1 do
|
|
|
|
for x := 0 to bmp.Width - 1 do
|
|
|
|
begin
|
|
|
|
if bmp.FastGetPixel(x, y) = clWhite then
|
|
|
|
continue;
|
|
|
|
//cyan
|
|
|
|
if bmp.FastGetPixel(x, y) = rgbtocolor(0,255,255) then
|
|
|
|
continue;
|
|
|
|
//green
|
|
|
|
if bmp.FastGetPixel(x, y) = rgbtocolor(0,255,0) then
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//item // TODO -> 5.bmp = not OK
|
|
|
|
if bmp.FastGetPixel(x, y) = rgbtocolor(255,130,0) then
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//yellow, interact
|
|
|
|
if bmp.FastGetPixel(x, y) = rgbtocolor(255,255,0) then
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bmp.fastsetpixel(x,y,0);
|
|
|
|
end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bmp.SaveToFile('/tmp/output.bmp');
|
|
|
|
//bmp.OnDestroy:=nil;
|
2009-11-03 07:57:39 -05:00
|
|
|
bmp.Free;
|
2009-12-01 18:41:43 -05:00
|
|
|
C.Free;
|
2009-10-23 18:21:14 -04:00
|
|
|
|
|
|
|
// stop program loop
|
|
|
|
Terminate;
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor MufasaTests.Create(TheOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(TheOwner);
|
|
|
|
StopOnException:=True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor MufasaTests.Destroy;
|
|
|
|
begin
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure MufasaTests.WriteHelp;
|
|
|
|
begin
|
|
|
|
{ add your help code here }
|
|
|
|
writeln('Usage: ',ExeName,' -h');
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
Application: MufasaTests;
|
|
|
|
|
|
|
|
{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}
|
|
|
|
|
|
|
|
begin
|
|
|
|
Application:=MufasaTests.Create(nil);
|
|
|
|
Application.Title:='My Application';
|
|
|
|
Application.Run;
|
|
|
|
Application.Free;
|
|
|
|
end.
|
|
|
|
|
2009-12-01 18:41:43 -05:00
|
|
|
|
|
|
|
{ {$WARNING Change This Path!}
|
|
|
|
C.MOCR.InitTOCR('/home/merlijn/Programs/mufasa/Fonts/');
|
|
|
|
//C.MOCR.InitTOCR('/home/merlijn/Programs/mufasa/ben/');
|
|
|
|
|
|
|
|
{C.MWindow.GetDimensions(W, H);
|
|
|
|
Time := GetTickCount;
|
|
|
|
for i := 0 to 100 do
|
|
|
|
C.MFinder.FindColor(X, Y, 0, 0, 0, W - 1, H - 1);
|
|
|
|
writeln('Time: ' + IntToStr(GetTickCount - Time));
|
|
|
|
|
|
|
|
if C.MFinder.FindColor(X, Y, 0, 0, 0, W - 1, H - 1) then
|
|
|
|
begin
|
|
|
|
C.MInput.SetMousePos(X, Y);
|
|
|
|
writeln('found!');
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
writeln('not found!');
|
|
|
|
end; }
|
|
|
|
|
|
|
|
|
|
|
|
bmp := TMufasaBitmap.Create;
|
|
|
|
|
|
|
|
{$WARNING Change This Path!}
|
|
|
|
{ bmp.LoadFromFile('/home/merlijn/Programs/mufasa/UpText/text1.bmp');
|
|
|
|
//bmp.LoadFromFile('/home/merlijn/Programs/mufasa/output.bmp');
|
|
|
|
|
|
|
|
writeln(inttostr(bmp.Width) + ', ' + inttostr(bmp.height));
|
|
|
|
{C.MWindow.SetTarget(x.TWindow(94371927)); }
|
|
|
|
C.MWindow.SetTarget(bmp);
|
|
|
|
|
|
|
|
Time := GetTickCount;
|
|
|
|
for i := 0 to 100 do
|
|
|
|
C.MOCR.GetUpTextAt(0,0);
|
|
|
|
writeln('Time: ' + FloatToStr(((GetTickCount - Time) / (i + 1))));
|
|
|
|
writeln(C.MOCR.GetUpTextAt(0,0)); }
|
|
|
|
|
|
|
|
//C.MInput.ClickMouse(5,5, mouse_Left);
|
|
|
|
sleep(2000);
|
|
|
|
C.MInput.SendText('a'); }
|