Einzelnen Beitrag anzeigen

Benutzerbild von Cylence
Cylence

Registriert seit: 2. Sep 2004
Ort: Allgäu
246 Beiträge
 
Delphi 7 Enterprise
 
#1

C FaceTracking DLL in Delphi nutzen

  Alt 9. Sep 2010, 10:25
Hallo,

ich habe hier:

http://chenlab.ece.cornell.edu/projects/FaceTracking/

eine dll gefunden mit der man Facetracking ermöglichen kann/naja oder könnte *g* dabei ist ein .h Header File, was ich testweise mal mit dem
HEADCONV.EXE in einen Delphi Header versucht hab umzuschreiben, aber das Tool hat das nicht richtig gemacht leider.

Dies ist der Header

Delphi-Quellcode:
#ifndef _FACE_TRACK_H
#define _FACE_TRACK_H

#define TWOPI_THREE_HALVES   15.749609946
#define EPSILON            1e-10
#define MIN_FLOAT         1e-20
#define LN_MIN_FLOAT      -46
#define MINFEATURESIZE      5
#define LARGENUM         1000000

#define PACKRGB(r,g,b) ((((unsigned int) r) & 0xfc) << 10) | ((((unsigned int) g) & 0xfc) << 4) | ((((unsigned int) b) & 0xfc) >> 2)
#define UNPACKR(x) (((unsigned int) x) & 0x3f000) >> 10
#define UNPACKG(x) (((unsigned int) x) & 0x00fc0) >> 4
#define UNPACKB(x) (((unsigned int) x) & 0x0003f) << 2

enum TEMPLATE_TYPE
{
   Ft_RECTANGLE,
   Ft_ELLIPSE,
   Ft_PARABOLA
}
;

typedef struct tagTEMPLATE
{
   int x1;         //left
   int y1;         //top
   int x2;         //right
   int y2;         //bottom
   int center;      //vertical center
}
FACE_RECT;

typedef struct tagGAUSS
{
   double c;
   double c_acc;                  //acumulate
   double mean[3], mean_acc[3];
   double cov[3][3], covinv[3][3];
   double cov_acc[3][3];
   double gconst;
}
GAUSS;

typedef struct tagSTATE
{
   int nels;
   GAUSS mix[2];
}
STATE;

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
class AFX_EXT_CLASS CFaceTrack
{
public:
   double *FtGetTemplate() const
   {
      return (double*)m_fTemplate;
   }


public:
   //constructor
   CFaceTrack();
   //destructor
   virtual ~CFaceTrack();

public:
   //high level member functions
   BOOL FtInitialization (int ImgWidth, int ImgHeight, BOOL RestrictAspectRatio=TRUE,
                     TEMPLATE_TYPE TemplateType=Ft_ELLIPSE);

   BOOL FtTraining (RECT FaceLocation, unsigned char *ImgData);

   BOOL FtTrackNextFrame (RECT &FaceRect, unsigned char *ImgData);

   //low level member functions
   //fill the mask with current template shape
   void FtFillMask (int ImgWidth, int ImgHeight, unsigned char *pMask, double *Template,
                  FACE_RECT FaceRect, int flag);

   //calculate the template shape parameters
   void FtFillTemplateParabola();
   void FtFillTemplateEllipse();
   void FtFillTemplateRectangle();

   //split the color channels
   void FtSplitColorChannel (int ImgWidth, int ImgHeight, unsigned char *pImgData, unsigned char *pRGBSplitImg[3]);

   //train the Gaussian Mixture Model
   void FtTrainGMM (unsigned char *pRGBSplitImg[3], unsigned char *pMask);
   void FtInitMixMean (unsigned char *pRGBSplitImg[3], unsigned char *pMask);
   void FtInitMixVar (unsigned char *pRGBSplitImg[3], unsigned char *pMask);
   void FtFillMixAcc (unsigned char *pRGBSplitImage[3], unsigned char *pMask);
   void FtFillMixConvinv (GAUSS *tmix);
   void FtZeroMixAcc ();

   //fill the look-up table with the training result
   void FtFillLUTTable();
   double FtGetProbability (int rin, int gin, int bin, GAUSS *mix);

   //track the face in the current frame
   void FtUpdateTemplate (FACE_RECT &CurFaceRect, FACE_RECT &PreFaceRect, int iStep, int flag);
   //given each pixel in current frame, calculate its likelihood value
   void FtUpdateLikelihoodMap (unsigned char *ImgData, int ImgWidth, int ImgHeight);
   //search strategy
   double FtTargetFunction(int *FaceRect, int *delta, int scale, int flag);


protected:
   int m_nImgWidth;            //the width of the image
   int m_nImgHeight;            //the height of the image
   DWORD m_nTableSize;            //the sampling rate of the color space
                           //note here m_nTableSize is the byte size of the LUT table

   BOOL m_bRestrictAspectRatio;   //whether restrict the aspect ratio of the tracking result
   BOOL m_bIsInitialized;         //indicates whether the internal variables have been allocated

   unsigned char *m_pRGBSplitImg[3];   //the image stored in RGB plane format
   unsigned char *m_pMask;            //the pointer of the mask which indicates the foreground and background region

   float *m_pLUT;                  //the pointer of probability look up table (LUT)
   double *m_pLikelihoodMap;         //the pointer of the likelihood map

   double *m_pom[2];
   double *m_pmo[2];
   double *m_po;

   TEMPLATE_TYPE m_TemplateType;   //the shape of the template to fit the face region

   FACE_RECT m_CurFaceRect;
   FACE_RECT m_PreFaceRect;

   double m_fTemplate[101];      //template equation

   STATE m_StateInfo[2];

};

#endif   //ifndef _FACE_TRACK_H

das ist was das tool übersetzt hat daraus

Delphi-Quellcode:
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.
darin sind ohne ende fehler undefinierter bezeichner usw...
kennt sich jemand damit aus? Kann mir jemand helfen? Ich denke das die dll auch für andere interessant sein könnte.

Gruß

Cylence
Angehängte Dateien
Dateityp: zip FaceTrackingDLL.zip (19,1 KB, 4x aufgerufen)
Tom
Just DO it
  Mit Zitat antworten Zitat