LBF Facemark Tutorial Issue
Hi everyone,
I am trying to work through the OpenCV 3.4.0 LBF Facemark tutorial given in the documentation here. I have encountered two issues.
The first issue is within the myDetector bool function. In the line:
conf->face_cascade.detectMultiScale(gray, faces_, conf->scaleFactor, 2, CASCADE_SCALE_IMAGE, Size(30, 30) );
I cannot find anywhere in the tutorial where face_cascade is defined. Should it be face_detector?
The second issue is with the setFaceDetector method:
facemark->setFaceDetector(myDetector, &config);
The setFaceDetector method does not want to take the myDetector as an argument. I recieve the following error:
argument of type "bool (*)(cv::InputArray image, cv::OutputArray faces, Conf *conf)" is incompatible with parameter of type "cv::face::FN_FaceDetector"
According to the FN_FaceDetector documentation, it seems like this line of code should work. Is there something I have done wrong?
Here is my code:
#include "opencv2/core.hpp"
#include "opencv2/face.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect.hpp"
struct Conf
{
cv::String model_path;
double scaleFactor;
Conf (cv::String s, double d)
{
model_path = s;
scaleFactor = d;
face_detector.load(model_path);
};
cv::CascadeClassifier face_detector;
};
bool myDetector(cv::InputArray image, cv::OutputArray faces, Conf *conf)
{
cv::Mat gray;
if (image.channels() > 1)
cvtColor(image, gray, cv::COLOR_BGR2GRAY);
else
gray = image.getMat().clone();
cv::equalizeHist(gray, gray);
std::vector<cv::Rect> faces_;
//changed face_cascade to face_detector to resolve error!!!
conf->face_detector.detectMultiScale(gray, faces_, conf->scaleFactor, 2, cv::CASCADE_SCALE_IMAGE, cv::Size(30, 30));
cv::Mat(faces_).copyTo(faces);
return true;
}
int main()
{
//create instance of lbf facemark model
cv::face::FacemarkLBF::Params params;
params.model_filename = "lbfmodel.yaml"; //path name to saved lbf facemark model
cv::Ptr<cv::face::Facemark> facemark = cv::face::FacemarkLBF::create(params);
Conf config("lbpcascade_frontalface.xml", 1.4);
//error with myDetector here!!!
facemark->setFaceDetector(myDetector, &config); // we must guarantee proper lifetime of "config" object
}