无法使用OpenCV 4C ++创建FisherFaceRecognizer

问题描述

我正在学习基于C ++中基于OpenCV的人脸识别的旧教程,并且遇到了我无法解决错误。相关代码段:

#include "opencv2/core/core.hpp"
#include "opencv2/face.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
...
Ptr<face::FaceRecognizer> model = face::createFisherFaceRecognizer();
model->train(images,labels);
...

我已经使用contrib模块正确编译了OpenCV,并包含了它们,但是仍然出现错误

error: 'createFisherFaceRecognizer()' is not a member of 'cv::face'

我也试了一下:

Ptr<face::FaceRecognizer> model = face::FisherFaceRecognizer_create();
error: 'FisherFaceRecognizer_create()' is not a member of 'cv::face'

我查找了face.hpp,并且该类具有“创建”功能,因此我尝试使用它,但这也失败了:

Ptr<face::FaceRecognizer> model = face::FisherFaceRecognizer.create();
error: expected primary-expression before '.' token

这很奇怪,因为该函数具有带有认值的参数。我提出的所有在线解决方案都失败了。在较新的OpenCV版本中进行了哪些更改,如何正确创建人脸识别器对象?

解决方法

根据official document

Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_components=0,double threshold=DBL_MAX)

用于openCV2。由于您使用的是openCV 4,因此必须遵循适用于openCV 4的documentation

尝试一下:

static Ptr<FisherFaceRecognizer> cv::face::FisherFaceRecognizer::create (int    num_components = 0,double  threshold = DBL_MAX )

this page的顶部,您可以调整所拥有的openCV库的版本。