我在Ubuntu 20.04上使用OpenCV 4.4.0,安装了最新的 opencv_contrib 额外模块。为了检测面部标志(基于this教程),我使用了以下与额外 face 模块相关的#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 terminal命令安装额外的模块。结果是一样的。我假设有一个与 namespace 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;
}
1条答案
按热度按时间cvxl0en21#
正如@john和@idclev 463035818所建议的,创建Facemark示例的方法是
例如,如果我想称之为Facemark。