|
// This is the main DLL file.
#pragma managed
#include "stdafx.h"
#include "FaceLocator.h"
#include <stdio.h>
#define FrontalFaceCascade "haarcascade_frontalface_alt.xml"
#define ProfileFaceCascade "haarcascade_profileface.xml"
FaceLocator::FaceLocator(System::String* appPath)
{
faceMode = 0;
strApplicationPath = appPath;
FrontalFaceDetector = new ObjectLocator();
ProfileFaceDetector = new ObjectLocator();
CurrentFaceDetector = FrontalFaceDetector;
}
FaceLocator::~FaceLocator(void)
{
delete FrontalFaceDetector;
delete ProfileFaceDetector;
}
int FaceLocator::SetFaceMode(int Mode)
{
faceMode = Mode;
if(Mode==0)
CurrentFaceDetector = FrontalFaceDetector;
else
CurrentFaceDetector = ProfileFaceDetector;
return faceMode;
}
void FaceLocator::InitCascades()
{
char *c, *chrAppPath;
chrAppPath = (char*)(void*)System::Runtime
::InteropServices::Marshal::StringToHGlobalAnsi(strApplicationPath);
c = strcat(chrAppPath,FrontalFaceCascade);
FrontalFaceDetector->InitObjectDetect(c);
System::Runtime::InteropServices::Marshal::FreeHGlobal(chrAppPath);
chrAppPath = (char*)(void*)System::Runtime
::InteropServices::Marshal::StringToHGlobalAnsi(strApplicationPath);
c = strcat(chrAppPath,ProfileFaceCascade);
ProfileFaceDetector->InitObjectDetect(c);
System::Runtime::InteropServices::Marshal::FreeHGlobal(chrAppPath);
}
int FaceLocator::DetectFaces(IplImage* inputImage)
{
if(InitFlag==0)
{
InitFlag++;
CurrentFaceDetector->InitImageStorage(inputImage->width,inputImage->height, scale);
InitCascades();
lastHeight = inputImage->height;
lastWidth = inputImage->width;
}
else if((lastHeight!=inputImage->height) || (lastWidth!=inputImage->width))
{
CurrentFaceDetector->InitImageStorage(inputImage->width,inputImage->height, scale);
InitCascades();
lastHeight = inputImage->height;
lastWidth = inputImage->width;
}
CurrentFaceDetector->ManagedImagetoUnManagedImage((inputImage));
CurrentFaceDetector->ImagePreProcessForFaceDetection();
//CurrentFaceDetector->UnSetFaceROI();
int FNum = CurrentFaceDetector->DetectObjects();
return FNum;
//return 0;
}
int FaceLocator::GetFaceCordinates(int index, int &lx, int &ly, int &rx, int &ry)
{
int lx1, ly1, rx1, ry1;
CurrentFaceDetector->GetObjectCoordinates(index, lx1, ly1, rx1, ry1);
lx = lx1;
ly = ly1;
rx = rx1;
ry = ry1;
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.