libwebcamheadtracker
1.0.0
A library for webcam-based head tracking
|
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... | |
Webcam-based head tracker.
Filter types.
WebcamHeadTracker::WebcamHeadTracker | ( | unsigned int | debugOptions = 0 | ) |
Constructor.
debugOptions | Bitwise combination of DebugOption flags. |
WebcamHeadTracker::~WebcamHeadTracker | ( | ) |
Destructor.
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.
|
static |
Default path to shape_predictor_68_face_landmarks.dat
(location at build time, if it was found)
|
static |
Default path to haarcascade_frontalface_alt.xml
(location at build time, if it was found)
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).
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).
void WebcamHeadTracker::getNewFrame | ( | ) |
Get a new frame from the webcam.
bool WebcamHeadTracker::initPoseEstimator | ( | const char * | frontalFaceXml = filePathFrontalFaceXml() , |
const char * | faceLandmarksDat = filePathFaceLandmarksDat() |
||
) |
Initialize the pose estimator.
frontalFaceXml | Full path to the file haarcascade_frontalface_alt.xml from OpenCV |
faceLandmarksDat | Full 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.
bool WebcamHeadTracker::initWebcam | ( | ) |
Initialize the webcam.
Tries to use the first camera that OpenCV detects. If this fails, no usable webcam is available.
|
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'.
void WebcamHeadTracker::setDistortionCoefficients | ( | float | k1, |
float | k2, | ||
float | p1, | ||
float | p2, | ||
float | k3 = 0.0f |
||
) |
Set camera distortion coefficients.
k1 | Parameter k1 |
k2 | Parameter k2 |
p1 | Parameter p1 |
p2 | Parameter p2 |
k3 | Parameter 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.
void WebcamHeadTracker::setFilter | ( | enum Filter | filter | ) |
Set the filter that is applied to the pose.
filter | The filter |
The default is Filter_Double_Exponential.
void WebcamHeadTracker::setFocalLengthsInPixels | ( | float | fx, |
float | fy | ||
) |
Set intrinsic camera parameters: focal lengths.
fx | Horizontal focal length |
fy | Vertical 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.
void WebcamHeadTracker::setPrincipalPointInPixels | ( | float | cx, |
float | cy | ||
) |
Set intrinsic camera parameters: principal points.
cx | Horizontal principal point |
cy | Vertical 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.