Face Landmarks and stabilization
Points on my landmarks are jitter.
How I can stabilize my face landmark?
Do I can use calcOpticalFlowPyrLK?
How I can use calcOpticalFlowPyrLK?
My code:
#include <iostream>
#include <cmath>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/face.hpp>
using cv::Scalar;
using cv::Point;
int main(int argc, char** argv)
{
cv::CascadeClassifier faceDetector("haarcascade_frontalface_alt2.xml");
cv::Ptr<cv::face::Facemark>facemark = cv::face::FacemarkLBF::create();
facemark->loadModel("lbfmodel.yaml");
cv::VideoCapture vc(0);
while (true)
{
cv::Mat frame, gray;
vc.read(frame);
cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
//
std::vector<cv::Rect> faces;
faceDetector.detectMultiScale(gray, faces);
std::vector< std::vector<cv::Point2f> > landmarks;
//// Run landmark detector
bool success = facemark->fit(frame, faces, landmarks);
for (size_t i = 0; i < landmarks.size(); i++)
{
for (size_t j = 0; j < landmarks[i].size(); j++)
{
cv::circle(frame, cv::Point(landmarks[i][j].x, landmarks[i][j].y), 2, Scalar(255, 0, 0), 2);
}
}
cv::imshow("1", frame);
if ((char)cv::waitKey(20) == 27)
break;
}
return 0;
}
usually, it's the face detection, which is noisy. this can be overcome by using a Tracker, like CSRT or MOSSE instead of consecutively detecting faces.
@berak, UPD
UPD means ?
@berak, UPD - UPDate
ahh, ok, should have finished my coffee before reading ;)
how would sparse optical flow help here ? again, to my exp., it's the cascade detection, which introduces the noise.
@berak, ok, but I can't understand, how fix that?
@berak, is it hard?
try, if you get a more stable box from this, using CSRT or MOSSE
@berak, oh, I stabilize my cascade detection, but landmarks aren't stabilize in box. I can save prev box and if new box changed is small I use prev box. but points are jitters :(
@berak, ??