How create cv::face::drawFacemarks ?

asked 2019-12-06 09:33:22 -0600

Mihailllll gravatar image

updated 2019-12-06 10:21:04 -0600

berak gravatar image

Hi! How create cv::face::drawFacemarks ? Here I found an example:

std::vector<Rect> faces;
std::vector<std::vector<Point2f> > landmarks;
facemark->getFaces(img, faces);
facemark->fit(img, faces, landmarks);
for(int j=0;j<rects.size();j++){
    face::drawFacemarks(frame, landmarks[j], Scalar(0,0,255));
}

But I did not understand how to make this example work? Is there a working code with an example? I tried to do so, but the compiler returns errors:

    std::vector<cv::Rect> faces;
    std::vector<std::vector<cv::Point2f> > landmarks;
    cv::Ptr<cv::face::Facemark> facemark = cv::face::createFacemarkLBF();
    //cv::Ptr<cv::face::Facemark> facemark = cv::face::createFacemarkAAM();

    facemark->getFaces(img, faces);
    facemark->fit(img, faces, landmarks);
    for(int j=0;j<rects.size();j++){
        cv::face::drawFacemarks(frame, landmarks[j], Scalar(0,0,255));
    }
edit retag flag offensive close merge delete

Comments

and the error is ?

berak gravatar imageberak ( 2019-12-06 10:21:19 -0600 )edit
1

facemark not have function getFaces() From the code it is not clear what facemark is

Mihailllll gravatar imageMihailllll ( 2019-12-06 10:25:54 -0600 )edit

https://docs.opencv.org/4.1.1/db/dd8/...

(you'll have to supply your own prior face detection)

((there is only a java sample but you'll get the idea))

berak gravatar imageberak ( 2019-12-06 11:28:10 -0600 )edit

Please tell me what I need to put in place of the model?

cv::face::Facemark::loadModel   (   String  model   )
Mihailllll gravatar imageMihailllll ( 2019-12-06 11:57:52 -0600 )edit

I did so. How can face recognition be completed?

        std::vector<cv::Rect> faces;
    std::vector<std::vector<cv::Point2f> > landmarks;
    cv::Ptr<cv::face::Facemark> facemark = cv::face::createFacemarkLBF();
    //cv::Ptr<cv::face::Facemark> facemark = cv::face::createFacemarkAAM();
    //cv::Ptr<cv::face::Facemark> facemark = cv::face::createFacemarkKazemi();
    facemark->loadModel("lbfmodel.yaml");
    CascadeClassifier faceDetector("haarcascade_frontalface_alt2.xml");
    Mat frame, gray;
    frame = cvMatOriginal;
    cvtColor(frame, gray, COLOR_BGR2GRAY);
    faceDetector.detectMultiScale(gray, faces);
Mihailllll gravatar imageMihailllll ( 2019-12-09 07:36:35 -0600 )edit