1 | initial version |
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.