Ask Your Question

Revision history [back]

Face Landmarks and stabilization

How I can stabilize my face landmark?

Face Landmarks and stabilization

Points on my landmarks is 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;
}

How I can stabilize my face landmark?

Face Landmarks and stabilization

Points on my landmarks is 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;
}

How I can stabilize my face landmark?

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;
}

How I can stabilize my face landmark?