错误的cv::face FacemarkLBF实例化

Wrong cv::face FacemarkLBF instantiation

本文关键字:FacemarkLBF 实例化 face 错误 cv      更新时间:2023-10-16

我在Ubuntu 20.04上使用OpenCV 4.4.0,并安装了最新的OpenCV_contrib额外模块。为了检测人脸标志(基于本教程(,我使用了以下与额外的人脸模块相关的#include和命名空间部分:

#include <opencv2/face.hpp>
using namespace cv::face;

检测到face.hpp文件(因此,我认为opencv_contrib模块安装正确(,但例如行

Ptr<facemark> facemark = FacemarkLBF::create();

抛出错误

error: ‘facemark’ was not declared in this scope

我已经尝试使用cmake gui和cmake终端命令安装额外的模块。结果是一样的。我认为存在与命名空间cv::face相关的错误。你知道我在这里犯了什么错误吗?

最小代码在这里:

#include <opencv2/opencv.hpp>
#include <opencv2/face.hpp>
#include "drawLandmarks.hpp"

using namespace std;
using namespace cv;
using namespace cv::face;

int main(int argc,char** argv)
{
// Load Face Detector
CascadeClassifier faceDetector("haarcascade_frontalface_alt2.xml");
// Create an instance of Facemark
Ptr<facemark> facemark = FacemarkLBF::create();
// Load landmark detector
facemark->loadModel("lbfmodel.yaml");
// Set up webcam for video capture
VideoCapture cam(0);

// Variable to store a video frame and its grayscale 
Mat frame, gray;

// Read a frame
while(cam.read(frame))
{

// Find face
vector<rect> faces;
// Convert frame to grayscale because
// faceDetector requires grayscale image.
cvtColor(frame, gray, COLOR_BGR2GRAY);
// Detect faces
faceDetector.detectMultiScale(gray, faces);

// Variable for landmarks. 
// Landmarks for one face is a vector of points
// There can be more than one face in the image. Hence, we 
// use a vector of vector of points. 
vector< vector<point2f> > landmarks;

// Run landmark detector
bool success = facemark->fit(frame,faces,landmarks);

if(success)
{
// If successful, render the landmarks on the face
for(int i = 0; i < landmarks.size(); i++)
{
drawLandmarks(frame, landmarks[i]);
}
}
// Display results 
imshow("Facial Landmark Detection", frame);
// Exit loop if ESC is pressed
if (waitKey(1) == 27) break;

}
return 0;
}

正如@john和@idclev 463035818所建议的,创建Facemark实例的方法是

Ptr<FacemarkLBF> facemark = FacemarkLBF::create();

例如,如果我想称之为facemark。