libwebcamheadtracker  1.0.0
A library for webcam-based head tracking
Public Types | Public Member Functions | Static Public Member Functions | List of all members
WebcamHeadTracker Class Reference

Webcam-based head tracker. More...

Public Types

enum  DebugOption { Debug_Window = 1, Debug_Timing = 2 }
 Debug options. More...
 
enum  Filter { Filter_None, Filter_Kalman, Filter_Double_Exponential }
 Filter types. More...
 

Public Member Functions

 WebcamHeadTracker (unsigned int debugOptions=0)
 Constructor. More...
 
 ~WebcamHeadTracker ()
 Destructor. More...
 
bool initWebcam ()
 Initialize the webcam. More...
 
bool initPoseEstimator (const char *frontalFaceXml=filePathFrontalFaceXml(), const char *faceLandmarksDat=filePathFaceLandmarksDat())
 Initialize the pose estimator. More...
 
void setFocalLengthsInPixels (float fx, float fy)
 Set intrinsic camera parameters: focal lengths. More...
 
void setPrincipalPointInPixels (float cx, float cy)
 Set intrinsic camera parameters: principal points. More...
 
void setDistortionCoefficients (float k1, float k2, float p1, float p2, float k3=0.0f)
 Set camera distortion coefficients. More...
 
void setFilter (enum Filter filter)
 Set the filter that is applied to the pose. More...
 
bool isReady () const
 Returns true if this tracker is ready to get a new frame and compute a new head pose. More...
 
void getNewFrame ()
 Get a new frame from the webcam. More...
 
bool computeHeadPose ()
 Compute a new head pose. More...
 
void getHeadPosition (float *headPosition) const
 Get the last known head position. More...
 
void getHeadOrientation (float *headOrientation) const
 Get the last known head orientation. More...
 

Static Public Member Functions

static const char * filePathFrontalFaceXml ()
 Default path to haarcascade_frontalface_alt.xml (location at build time, if it was found) More...
 
static const char * filePathFaceLandmarksDat ()
 Default path to shape_predictor_68_face_landmarks.dat (location at build time, if it was found) More...
 

Detailed Description

Webcam-based head tracker.

Member Enumeration Documentation

◆ DebugOption

Debug options.

Enumerator
Debug_Window 

Show a GUI window with the webcam frame and face detection results.

Debug_Timing 

Print timings for each step to stderr.

◆ Filter

Filter types.

Enumerator
Filter_None 

Do not apply any filtering (very strong jittering, but no additional delays)

Filter_Kalman 

Apply Kalman filter (smooth results, but long update delays on pose changes)

Filter_Double_Exponential 

Apply double exponential smoothing (smooth results, acceptable delays)

Constructor & Destructor Documentation

◆ WebcamHeadTracker()

WebcamHeadTracker::WebcamHeadTracker ( unsigned int  debugOptions = 0)

Constructor.

Parameters
debugOptionsBitwise combination of DebugOption flags.

◆ ~WebcamHeadTracker()

WebcamHeadTracker::~WebcamHeadTracker ( )

Destructor.

Member Function Documentation

◆ computeHeadPose()

bool WebcamHeadTracker::computeHeadPose ( )

Compute a new head pose.

This works on the latest available webcam frame. If head pose estimation fails for some reason (e.g. no face could be found), then this function returns false.

◆ filePathFaceLandmarksDat()

static const char* WebcamHeadTracker::filePathFaceLandmarksDat ( )
static

Default path to shape_predictor_68_face_landmarks.dat (location at build time, if it was found)

◆ filePathFrontalFaceXml()

static const char* WebcamHeadTracker::filePathFrontalFaceXml ( )
static

Default path to haarcascade_frontalface_alt.xml (location at build time, if it was found)

◆ getHeadOrientation()

void WebcamHeadTracker::getHeadOrientation ( float *  headOrientation) const

Get the last known head orientation.

Returns the last known head orientation as a quaternion (x, y, z, w).

The head reference point is the center between the left and right eyes. The coordinate system is the usual system in computer graphics: y points upwards, x points to the right, and the user looks along -z (towards the webcam).

◆ getHeadPosition()

void WebcamHeadTracker::getHeadPosition ( float *  headPosition) const

Get the last known head position.

Returns the last known head orientation as a vector (x, y, z).

The head reference point is the center between the left and right eyes. The coordinate system is the usual system in computer graphics: y points upwards, x points to the right, and the user looks along -z (towards the webcam).

◆ getNewFrame()

void WebcamHeadTracker::getNewFrame ( )

Get a new frame from the webcam.

◆ initPoseEstimator()

bool WebcamHeadTracker::initPoseEstimator ( const char *  frontalFaceXml = filePathFrontalFaceXml(),
const char *  faceLandmarksDat = filePathFaceLandmarksDat() 
)

Initialize the pose estimator.

Parameters
frontalFaceXmlFull path to the file haarcascade_frontalface_alt.xml from OpenCV
faceLandmarksDatFull path to the file shape_predictor_68_face_landmarks.dat from dlib

This function loads the two data files from OpenCV and dlib. It returns false if this fails. The default parameters should work fine on development systems and Linux(ish) systems, but you might want to bundle these files with your application and use custom file paths as parameters to this function.

◆ initWebcam()

bool WebcamHeadTracker::initWebcam ( )

Initialize the webcam.

Tries to use the first camera that OpenCV detects. If this fails, no usable webcam is available.

◆ isReady()

bool WebcamHeadTracker::isReady ( ) const
inline

Returns true if this tracker is ready to get a new frame and compute a new head pose.

This returns true once the tracker is successfully initialized. When Debug_Window is set, this can change to false when the user presses 'ESC'.

◆ setDistortionCoefficients()

void WebcamHeadTracker::setDistortionCoefficients ( float  k1,
float  k2,
float  p1,
float  p2,
float  k3 = 0.0f 
)

Set camera distortion coefficients.

Parameters
k1Parameter k1
k2Parameter k2
p1Parameter p1
p2Parameter p2
k3Parameter k3

Calling this function is optional, the defaults should be ok. To find correct values for your webcam, you need to calibrate it. See OpenCV documentation.

◆ setFilter()

void WebcamHeadTracker::setFilter ( enum Filter  filter)

Set the filter that is applied to the pose.

Parameters
filterThe filter

The default is Filter_Double_Exponential.

◆ setFocalLengthsInPixels()

void WebcamHeadTracker::setFocalLengthsInPixels ( float  fx,
float  fy 
)

Set intrinsic camera parameters: focal lengths.

Parameters
fxHorizontal focal length
fyVertical focal length

Calling this function is optional, the defaults should be ok. To find correct values for your webcam, you need to calibrate it. See OpenCV documentation.

◆ setPrincipalPointInPixels()

void WebcamHeadTracker::setPrincipalPointInPixels ( float  cx,
float  cy 
)

Set intrinsic camera parameters: principal points.

Parameters
cxHorizontal principal point
cyVertical principal point

Calling this function is optional, the defaults should be ok. To find correct values for your webcam, you need to calibrate it. See OpenCV documentation.


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