unit FACETRACK;
{**************************************************************************}
{ }
{ This C DLL header file first (automatic) conversion generated by: }
{ HeadConv 4.0 (c) 2000 by Bob Swart (aka Dr.Bob - www.drbob42.com) }
{ Final Delphi-Jedi (Darth) command-line units edition }
{ }
{ Generated Date: 09.09.2010 }
{ Generated Time: 10:15:18 }
{ }
{**************************************************************************}
interface
uses
{$IFDEF WIN32}
Windows;
{$ELSE}
Wintypes, WinProcs;
{$ENDIF}
{=> d:\workspace\facetrackingdll\FACETRACK.H <=}
{$IFNDEF _FACE_TRACK_H}
{$DEFINE _FACE_TRACK_H}
const
TWOPI_THREE_HALVES = 15.749609946;
const
EPSILON = 1e-10;
const
MIN_FLOAT = 1e-20;
const
LN_MIN_FLOAT = -46;
const
MINFEATURESIZE = 5;
const
LARGENUM = 1000000;
const
PACKRGB(r,g,b) = ((((unsigned int) r) & 0xfc) << 10) | ((((unsigned int) g) & 0xfc) << 4) | ((((unsigned int) b) & 0xfc) >> 2);
const
UNPACKR(x) = (((unsigned int) x) & 0x3f000) >> 10;
const
UNPACKG(x) = (((unsigned int) x) & 0x00fc0) >> 4;
const
UNPACKB(x) = (((unsigned int) x) & 0x0003f) << 2;
type
TEMPLATE_TYPE = (
Ft_RECTANGLE,
Ft_ELLIPSE,
Ft_PARABOLA );
type
tagTEMPLATE =
record
x1: Integer;
y1: Integer;
x2: Integer;
y2: Integer;
center: Integer;
end {tagTEMPLATE};
type
tagGAUSS =
record
c: Double;
c_acc: Double;
mean:
Array[0..3-1]
of, mean_acc:
Array[0..3-1]
of Double;
cov:
Array[0..3-1]
of:
Array[0..3-1]
of, covinv:
Array[0..3-1]
of:
Array[0..3-1]
of Double;
cov_acc:
Array[0..3-1]
of:
Array[0..3-1]
of Double;
gconst: Double;
end {tagGAUSS};
type
tagSTATE =
record
nels: Integer;
mix:
Array[0..2-1]
of GAUSS;
end {tagSTATE};
{///&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& }
var
FtGetTemplate:
function: PPUBLIC: DOUBLE
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
return:
function(
var _1: Double): Integer
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
CFaceTrack:
function: Integer
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///destructor }
var
~CFaceTrack:
function:
VIRTUAL cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtInitialization:
function(ImgWidth: Integer;
ImgHeight: Integer;
RestrictAspectRatio=TRUE: Bool;
TemplateType=Ft_ELLIPSE: TEMPLATE_TYPE): Bool
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtTraining:
function(FaceLocation: RECT;
var ImgData: Byte): Bool
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtTrackNextFrame:
function(
var FaceRect: RECT;
var ImgData: Byte): Bool
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///low level member functions }
{///fill the mask with current template shape }
var
FtFillMask:
procedure(ImgWidth: Integer;
ImgHeight: Integer;
var pMask: Byte;
var Template: Double;
FaceRect: FACE_RECT;
flag: Integer)
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///calculate the template shape parameters }
var
FtFillTemplateParabola:
procedure cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtFillTemplateEllipse:
procedure cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtFillTemplateRectangle:
procedure cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///split the color channels }
var
FtSplitColorChannel:
procedure(ImgWidth: Integer;
ImgHeight: Integer;
var pImgData: Byte;
var pRGBSplitImg[3]: Byte)
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///train the Gaussian Mixture Model }
var
FtTrainGMM:
procedure(
var pRGBSplitImg[3]: Byte;
var pMask: Byte)
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtInitMixMean:
procedure(
var pRGBSplitImg[3]: Byte;
var pMask: Byte)
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtInitMixVar:
procedure(
var pRGBSplitImg[3]: Byte;
var pMask: Byte)
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtFillMixAcc:
procedure(
var pRGBSplitImage[3]: Byte;
var pMask: Byte)
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtFillMixConvinv:
procedure(
var tmix: GAUSS)
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtZeroMixAcc:
procedure cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///fill the look-up table with the training result }
var
FtFillLUTTable:
procedure cdecl {$IFDEF WIN32} stdcall {$ENDIF};
var
FtGetProbability:
function(rin: Integer;
gin: Integer;
bin: Integer;
var mix: GAUSS): Double
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///track the face in the current frame }
var
FtUpdateTemplate:
procedure(
var CurFaceRect: FACE_RECT;
var PreFaceRect: FACE_RECT;
iStep: Integer;
flag: Integer)
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///given each pixel in current frame, calculate its likelihood value }
var
FtUpdateLikelihoodMap:
procedure(
var ImgData: Byte;
ImgWidth: Integer;
ImgHeight: Integer)
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///search strategy }
var
FtTargetFunction:
function(
var FaceRect: Integer;
var delta: Integer;
scale: Integer;
flag: Integer): Double
cdecl {$IFDEF WIN32} stdcall {$ENDIF};
{///note here m_nTableSize is the byte size of the LUT table }
{$ENDIF //ifndef _FACE_TRACK_H}
var
DLLLoaded: Boolean
{ is DLL (dynamically) loaded already? }
{$IFDEF WIN32} = False;
{$ENDIF}
implementation
var
SaveExit: pointer;
DLLHandle: THandle;
{$IFNDEF MSDOS}
ErrorMode: Integer;
{$ENDIF}
procedure NewExit;
far;
begin
ExitProc := SaveExit;
FreeLibrary(DLLHandle)
end {NewExit};
procedure LoadDLL;
begin
if DLLLoaded
then Exit;
{$IFNDEF MSDOS}
ErrorMode := SetErrorMode($8000
{SEM_NoOpenFileErrorBox});
{$ENDIF}
DLLHandle := LoadLibrary('
FACETRACK.DLL');
if DLLHandle >= 32
then
begin
DLLLoaded := True;
SaveExit := ExitProc;
ExitProc := @NewExit;
@FtGetTemplate := GetProcAddress(DLLHandle,'
FtGetTemplate');
{$IFDEF WIN32}
Assert(@FtGetTemplate <>
nil);
{$ENDIF}
@return := GetProcAddress(DLLHandle,'
return');
{$IFDEF WIN32}
Assert(@return <>
nil);
{$ENDIF}
@CFaceTrack := GetProcAddress(DLLHandle,'
CFaceTrack');
{$IFDEF WIN32}
Assert(@CFaceTrack <>
nil);
{$ENDIF}
@~CFaceTrack := GetProcAddress(DLLHandle,'
~CFaceTrack');
{$IFDEF WIN32}
Assert(@~CFaceTrack <>
nil);
{$ENDIF}
@FtInitialization := GetProcAddress(DLLHandle,'
FtInitialization');
{$IFDEF WIN32}
Assert(@FtInitialization <>
nil);
{$ENDIF}
@FtTraining := GetProcAddress(DLLHandle,'
FtTraining');
{$IFDEF WIN32}
Assert(@FtTraining <>
nil);
{$ENDIF}
@FtTrackNextFrame := GetProcAddress(DLLHandle,'
FtTrackNextFrame');
{$IFDEF WIN32}
Assert(@FtTrackNextFrame <>
nil);
{$ENDIF}
@FtFillMask := GetProcAddress(DLLHandle,'
FtFillMask');
{$IFDEF WIN32}
Assert(@FtFillMask <>
nil);
{$ENDIF}
@FtFillTemplateParabola := GetProcAddress(DLLHandle,'
FtFillTemplateParabola');
{$IFDEF WIN32}
Assert(@FtFillTemplateParabola <>
nil);
{$ENDIF}
@FtFillTemplateEllipse := GetProcAddress(DLLHandle,'
FtFillTemplateEllipse');
{$IFDEF WIN32}
Assert(@FtFillTemplateEllipse <>
nil);
{$ENDIF}
@FtFillTemplateRectangle := GetProcAddress(DLLHandle,'
FtFillTemplateRectangle');
{$IFDEF WIN32}
Assert(@FtFillTemplateRectangle <>
nil);
{$ENDIF}
@FtSplitColorChannel := GetProcAddress(DLLHandle,'
FtSplitColorChannel');
{$IFDEF WIN32}
Assert(@FtSplitColorChannel <>
nil);
{$ENDIF}
@FtTrainGMM := GetProcAddress(DLLHandle,'
FtTrainGMM');
{$IFDEF WIN32}
Assert(@FtTrainGMM <>
nil);
{$ENDIF}
@FtInitMixMean := GetProcAddress(DLLHandle,'
FtInitMixMean');
{$IFDEF WIN32}
Assert(@FtInitMixMean <>
nil);
{$ENDIF}
@FtInitMixVar := GetProcAddress(DLLHandle,'
FtInitMixVar');
{$IFDEF WIN32}
Assert(@FtInitMixVar <>
nil);
{$ENDIF}
@FtFillMixAcc := GetProcAddress(DLLHandle,'
FtFillMixAcc');
{$IFDEF WIN32}
Assert(@FtFillMixAcc <>
nil);
{$ENDIF}
@FtFillMixConvinv := GetProcAddress(DLLHandle,'
FtFillMixConvinv');
{$IFDEF WIN32}
Assert(@FtFillMixConvinv <>
nil);
{$ENDIF}
@FtZeroMixAcc := GetProcAddress(DLLHandle,'
FtZeroMixAcc');
{$IFDEF WIN32}
Assert(@FtZeroMixAcc <>
nil);
{$ENDIF}
@FtFillLUTTable := GetProcAddress(DLLHandle,'
FtFillLUTTable');
{$IFDEF WIN32}
Assert(@FtFillLUTTable <>
nil);
{$ENDIF}
@FtGetProbability := GetProcAddress(DLLHandle,'
FtGetProbability');
{$IFDEF WIN32}
Assert(@FtGetProbability <>
nil);
{$ENDIF}
@FtUpdateTemplate := GetProcAddress(DLLHandle,'
FtUpdateTemplate');
{$IFDEF WIN32}
Assert(@FtUpdateTemplate <>
nil);
{$ENDIF}
@FtUpdateLikelihoodMap := GetProcAddress(DLLHandle,'
FtUpdateLikelihoodMap');
{$IFDEF WIN32}
Assert(@FtUpdateLikelihoodMap <>
nil);
{$ENDIF}
@FtTargetFunction := GetProcAddress(DLLHandle,'
FtTargetFunction');
{$IFDEF WIN32}
Assert(@FtTargetFunction <>
nil);
{$ENDIF}
end
else
begin
DLLLoaded := False;
{ Error: FACETRACK.DLL could not be loaded !! }
end;
{$IFNDEF MSDOS}
SetErrorMode(ErrorMode)
{$ENDIF}
end {LoadDLL};
begin
LoadDLL;
end.