# Robust face detection

I am detecting the face using Haar Detection , But the detection is very slow and not very accurate ? So I was thinking if I could use kalman filter for face detction things would be much better . Any body who worked on this before please help ?

Edit : Is there any other way I can make the face detection robust ? I am working on real time video capture .

Edit : I am using a PTZ camera to track the face and move the camera accordingly so as to maintain the face in the center region . Are there ways we can predict the position of the face ?? Note that here the camera has motion , ie pan and tilt . So what are the ways we can predict the future position of the face ??

edit retag close merge delete

Sort by » oldest newest most voted

I did, some time ago, a face tracking algorithm using template matching and kalman filter in order to reduce the window to perform template matching. I implemented a simple class that i called "FaceKalman" based on this mouse kalman. The code (cpp) is something like this:

FaceKalman::FaceKalman(){
// TODO Auto-generated constructor stub

}

KalmanFilter FaceKalman::initKalman(Point coord)
{
/*
(x, y, Vx, Vy)
position of the object (x,y)
velocity (Vx,Vy)
*/

this->measurement =  Mat(2,1,DataType<float>::type);

KalmanFilter KF(4, 2, 0);

KF.statePre.at<float>(0) = coord.x;
KF.statePre.at<float>(1) = coord.y;
KF.statePre.at<float>(2) = 0;
KF.statePre.at<float>(3) = 0;

//VELOCITY NOT TAKEN INTO ACCOUNT
//KF.transitionMatrix = *(Mat_<float>(4, 4) << 1,0,0,0,   0,1,0,0,  0,0,1,0,  0,0,0,1);

//VELOCITY TAKEN INTO ACCOUNT
KF.transitionMatrix = *(Mat_<float>(4, 4) << 1,0,1,0,   0,1,0,1,  0,0,1,0,  0,0,0,1);

setIdentity(KF.measurementMatrix);
setIdentity(KF.processNoiseCov, Scalar::all(1e-4));
setIdentity(KF.measurementNoiseCov, Scalar::all(1e-1));
setIdentity(KF.errorCovPost, Scalar::all(.1));

return KF;
}

Point FaceKalman::updateKalman(KalmanFilter KF, Point coord)
{
//predict
Mat prediction = KF.predict();
Point predictPt(prediction.at<float>(0),prediction.at<float>(1));

this->measurement(0) = coord.x;
this->measurement(1) = coord.y;

//correct
Mat estimated = KF.correct(this->measurement);
Point estimatedPoint(estimated.at<float>(0),estimated.at<float>(1));
return estimatedPoint;
}


Then, you can use your FaceKalman class for face detection in order to reduce the window to look for the face.

more

Is the coord.x in the " KF.statePre.at<float>(0) = coord.x; " and in the " this->measurement(0) = coord.x; " same ??

( 2013-06-28 14:48:53 -0500 )edit

coord is the measurement that you want to filter over time.

coord.x = x component of the measurement

KF.statePre.at<float>(0) = coord.x; //here it is the first measure

this->measurement(0) = coord.x; // here it is the new measure to filter

( 2013-07-01 01:42:05 -0500 )edit

i try to use but this->measurement doesn't work because the compiler says that class has no member called "measurement", must i add it? and how?

( 2015-07-20 05:33:14 -0500 )edit

yes, you should add it to the .h file

( 2015-07-21 01:26:50 -0500 )edit

ok, another information, if you can. I try to declare this variable mat in the h file, but it reports always error. In which way must i declare it? I use opencv and this class from a few time and i see the contructors in documentation, but it still doesn't work.

( 2015-07-21 03:57:43 -0500 )edit

cv::Mat_<float> measurement;

( 2015-07-21 06:20:17 -0500 )edit

thank you very much!!

( 2015-07-22 04:11:14 -0500 )edit

Edit : Is there any other way I can make the face detection robust ? I am working on real time video capture

Face detection:

Given an arbitrary image, the goal of face detection is to determine whether or not there are any faces in the image and, if present, return the location and extent of each face.

Viola & Jones algorithm is commonly applied to face detection. Viola and Jones introduced their object detection framework that can be applied to human faces. At runtime, the algorithm is capable of processing images extremely rapidly. It uses a boosted cascade of simple classifiers based on rectangular Haar-like features that can be computed rapidly.

Face tracking:

Track a detected face over time. In order to track a human face, the system not only needs to locate a face, but also needs to find it in a sequence of images. You can use color information, estimate the motion, and so on. There are a lot of algorithms and approaches that perform face tracking in real time.

You can perform face tracking with opencv functions and methods. For example:

Also you can use TLD algorithm to track the face . There are some C++ implementations: tld C++ implementation, tld C++ implementation 2, TLD face tracking video

Or for example this one: Zhang, K., Zhang, L., & Yang, M. H. (2012). Real-time compressive tracking. In Computer Vision–ECCV 2012 (pp. 864-877). Springer Berlin Heidelberg. Project web page. It includes matlab code and c++ code. Compressive tracking video

more

Heyy thanks for that quick reply :) I am trying to track a face using a PTZ Camera . For now I am doing face detection using Viola Jones , then I am tracking the detected face using camshift tracking and moving the camera accordingly . But this works a bit slowly . I want to make this more robust and faster , Can you help me with any ideas for faster tracking ??

( 2013-06-21 06:54:39 -0500 )edit

The simplest answer would be to reduce the size of the input image (before applying Camshift) And you can you Camshift + Kalman (http://www.youtube.com/watch?v=dhYwCmKGU3w)

( 2013-06-21 07:19:43 -0500 )edit

I recommend you to see this tutorial: http://www.youtube.com/watch?v=bSeFrPrqZ2A

( 2013-06-21 07:21:50 -0500 )edit

Official site

GitHub

Wiki

Documentation