visageSDK
Public Member Functions | List of all members
VisageCSWrapper.VisageFaceAnalyser Class Reference

Visage Face Analyser contains face analysis algorithms for estimating gender and emotion from frontal facial images. More...

Public Member Functions

 VisageFaceAnalyser ()
 Constructor. More...
 
 VisageFaceAnalyser (String dataPath)
 Constructor. More...
 
 ~VisageFaceAnalyser ()
 Destructor. More...
 
int Init (String dataPath)
 Initialises VisageFaceAnalyser. More...
 
VFAReturnCode analyseImage (VSImage image, FaceData facedata, int options, ref AnalysisData results)
 Performs face analysis on a given frame. More...
 
VFAReturnCode analyseStream (VSImage image, FaceData facedata, int options, ref AnalysisData results, int faceIndex)
 Performs face analysis on a given image stream (video). More...
 
void resetStreamAnalysis (int faceIndex)
 Resets collected face analysis data. More...
 

Detailed Description

Visage Face Analyser contains face analysis algorithms for estimating gender and emotion from frontal facial images.

Before using VisageFaceAnalyser, it must be initialized using the function Init(). After the initialization the following types of analysis can be used:

Face analysis may be performed on an individual image, or on a sequential stream of images (such as a video or camera feed). The two corresponding functions are:

ANALYSIS TYPEFUNCTION
image analysisanalyseImage()
image stream (video) analysisanalyseStream()

VisageFaceAnalyser uses VsImage structure as a container for the input image. Please refer to the VsImage structure documentation for details of accessing its data members; the basic members are the size of the image (frame->width, frame->height) and the pointer to the actual pixel data of the image (frame->imageData). All of the estimation methods expect grayscale, RGB or RGBA image. Please note that for the most efficient usage, the grayscale image format should be used. Grayscale format is a default image format for the estimation methods and conversion from other valid image formats is done internally.

Definition at line 113 of file VisageFaceAnalyser.cs.

Constructor & Destructor Documentation

VisageCSWrapper.VisageFaceAnalyser.VisageFaceAnalyser ( )

Constructor.

VisageCSWrapper.VisageFaceAnalyser.VisageFaceAnalyser ( String  dataPath)

Constructor.

Parameters
dataPathRelative path from the working directory to the directory that contains VisageFaceAnalyser data files.
VisageCSWrapper.VisageFaceAnalyser.~VisageFaceAnalyser ( )

Destructor.

Member Function Documentation

VFAReturnCode VisageCSWrapper.VisageFaceAnalyser.analyseImage ( VSImage  image,
FaceData  facedata,
int  options,
ref AnalysisData  results 
)

Performs face analysis on a given frame.

This function is primarily intended for performing face analysis on a single image, or consecutive unrelated images. As such, it outputs raw, unfiltered estimation data without smoothing or averaging.

Note
Prior to using this function it is necessary to process the facial image using VisageTracker or VisageFeaturesDetector and pass the frame and obtained data to this function. When using data from VisageTracker, only data obtained when tracking status was TRACK_STAT.OK should be passed.

An example of use, analyseImage on all the faces detected in an image file:

VisageFeaturesDetector mVisageFeaturesDetector = new VisageFeaturesDetector(@"..\Samples\data\Face Detector.cfg");
Bitmap bmp = new Bitmap(path_to_image);
byte[] bmp_byte = BitmapToByteArray(bmp); //convert image data from Bitmap class to a raw byte array
int nChannels = 3;
VSImage inputImage = new VSImage(bmp.Width, bmp.Height, VS_DEPTH._8U, nChannels);
inputImage.imageData = bmp_byte;
int isInitialised = mVFA.Init(@"..\Samples\data\vfa");
int options = 0;
options |= (int)VFAFlags.AGE;
options |= (int)VFAFlags.GENDER;
options |= (int)VFAFlags.EMOTION;
if((vfaInitialised & options) == options)
{
int maxFaces = 100;
FaceData[] data = new FaceData[maxFaces];
AnalysisData[] analysisData = new AnalysisData[maxFaces];
for (int i = 0; i < maxFaces; ++i)
{
data[i] = new FaceData();
analysisData[i] = new AnalysisData();
}
int n_faces = mVisageFeaturesDetector.DetectFacialFeatures(inputImage, data);
for (int i = 0; i < n_faces; i++)
{
VFAReturnCode status = mVFA.analyseImage(inputImage, data[i], options, ref analysisData[i]);
// check analysisdata[i].ageValid and use analysisData[i].age .... (same for gender and emotions)
}
}
Parameters
imageVsImage container that contains the input grayscale, RGB or RGBA frame.
facedataFaceData obtained by a previous successful tracking (TRACK_STAT.OK) or detection operation with VisageTracker or VisageFeaturesDetector.
optionsBitwise combination of VFAFlags which determines the analysis operations to be performed.
resultsAnalysisData struct containing success flags for individual operations and their assorted results.
Returns
VFAReturnCode value indicating the status of the performed analysis.
VFAReturnCode VisageCSWrapper.VisageFaceAnalyser.analyseStream ( VSImage  image,
FaceData  facedata,
int  options,
ref AnalysisData  results,
int  faceIndex 
)

Performs face analysis on a given image stream (video).

This function is primarily intended for performing face analysis on a continuous stream of related frames containing the same person, such as a video or camera feed. Sampling face analysis data from multiple frames can increase estimation accuracy by averaging the result over multiple frames. Internally, the suitability of frames chosen for analysis is continually evaluted based on head pose and overall tracking quality. This guarantees that the analysis buffer is always working with the best available frames, ensuring highest possible estimation accuracy.

Important notes:
This method should only be called with FaceData obtained from a successful tracking operation that returned TRACK_STAT.OK tracking status.

If options parameter is changed between subsequent calls to analyseStream(), the internal state will be reset and previously collected analysis data will be lost. For optimal results options parameter should remain constant during single stream analysis session.

If a new person in the continuous stream replaces the old one, it is neccessary to call resetStreamAnalysis() method otherwise results will not be correct as analyseStream() method has no capability of differentiating faces.

Note
Prior to using this function it is necessary to process the facial image using VisageTracker and pass the frame and obtained data to this function.

An example of use, analyseImage on all the faces detected in an image file:

using Emgu.CV;
VisageTracker m_Tracker = new VisageTracker(@"..\Samples\data\Facial Features Tracker.cfg");
// Video capture and frame data initialization
Capture capture = new Capture(path_to_video_file);
Bitmap bmp = new Bitmap(capture.QueryFrame().Bitmap);
int bitmapStride = 0;
byte[] bmp_byte;
//Grab camera frame
Bitmap bmp = cameraCapture.QueryFrame().Bitmap;
//Create a VSImage and fill it with data to pass it to the DetectFeatures function
frame = new VSImage(bmp.Width, bmp.Height, VS_DEPTH._8U, nChannels);
byte[] bmp_byte = BitmapToByteArray(bmp);
frame.imageData = bmp_byte;
int isInitialised = mVFA.Init(@"..\Samples\data\vfa");
int options = 0;
options |= (int)VFAFlags.AGE;
options |= (int)VFAFlags.GENDER;
options |= (int)VFAFlags.EMOTION;
if((vfaInitialised & options) == options)
{
int maxFaces = 100;
FaceData[] data = new FaceData[maxFaces];
AnalysisData[] analysisData = new AnalysisData[maxFaces];
for (int i = 0; i < maxFaces; ++i)
{
data[i] = new FaceData();
analysisData[i] = new AnalysisData();
}
int[] TrackerStatus = m_Tracker.Track(bmp.Width, bmp.Height, bmp_byte, data, format, origin, bmpdata.Stride, -1, maxFacesTracker);
for (int i = 0; i < n_faces; i++)
{
if (trackerStatus[i] == (int)TRACK_STAT.OK)
VFAReturnCode status = mVFA.analyseStream(inputImage, data[i], options, ref analysisData[i], i);
// check analysisdata[i].ageValid and use analysisData[i].age .... (same for gender and emotions)
}
}
Parameters
imageVsImage pointer that contains the input grayscale, RGB or RGBA frame.
facedataFaceData obtained by a previous successful tracking operation with VisageTracker (TRACK_STAT.OK).
optionsBitwise combination of VFAFlags which determines the analysis operations to be performed.
resultsAnalysisData struct containing success flags for individual operations and their assorted results.
faceIndexIndex of the face for which analysis should be performed.
Returns
VFAReturnCode value indicating the status of the performed analysis.
int VisageCSWrapper.VisageFaceAnalyser.Init ( String  dataPath)

Initialises VisageFaceAnalyser.

This function must be called before using VisageFaceAnalyser by passing it a path to the folder containing the VisageFaceAnalyser data files. Within the Visage|SDK package, this folder is Samples/data/vfa. When implementing applications, developers may copy this folder as part of their application. The path is given relative to the current working directory at the time of calling the Init() function. The VisageFaceAnalyser data folder contains the following subfolders corresponding to the various types of analysis that can be performed:

  • ad: age estimation
  • gd: gender estimation
  • ed: emotion estimation

Note that it is not necessary for all subfolders to be present, only the ones needed by the types of analysis that will be performed. For example, if only gender estimation will be performed, then only the gd folder is required.

The return value of the Init() function indicates which types of analysis have been successfully initialised. Subsequent attempt to use a type of analysis that was not initialized shall fail; for example, if only gd folder was present at initialization, attempt to use EstimateEmotion() shall fail.

The return value is a bitwise combination of flags indicating which types of analysis are successfully initialized.

Parameters
dataPathRelative path from the working directory to the directory that contains VisageFaceAnalyser data files.
Returns
The return value of 0 indicates that no data files are found and no analysis will be possible. In such case, the placement of data files should be verified. A non-zero value indicates that one or more types of analysis are successfully initialized. The specific types of analysis that have been initialized are indicated by a bitwise combination of the flags from VFAFlags.
void VisageCSWrapper.VisageFaceAnalyser.resetStreamAnalysis ( int  faceIndex)

Resets collected face analysis data.

This is intended to be used in cases when a new person replaces the old one in the same continous input stream.

Erases age, gender and emotion data collected up to this point. If an index parameter is specified, only data for that specific face is erased. If no parameter is specified, data for all faces is erased.

Parameters
faceIndexIndex of the face for which AnalysisData should be reset.

The documentation for this class was generated from the following file: