【问题标题】:Cannot create FisherFaceRecognizer with OpenCV 4 (C++)无法使用 OpenCV 4 (C++) 创建 FisherFaceRecognizer
【发布时间】:2021-01-09 21:59:21
【问题描述】:

我正在学习基于 C++ 中 OpenCV 的人脸识别的较早教程,但遇到了一个我无法解决的错误。相关代码sn -p:

#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);
...

我的 OpenCV 使用 contrib 模块正确编译,包含它们,但它仍然给出错误:

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,发现这个类有一个函数'create',所以我尝试使用它,但也失败了:

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

这很奇怪,因为该函数的参数具有默认值。我尝试的所有在线解决方案都失败了。较新的 OpenCV 版本发生了哪些变化?如何正确创建人脸识别器对象?

【问题讨论】:

    标签: c++ opencv opencv3.0 face-recognition opencv-contrib


    【解决方案1】:

    根据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库的版本。

    【讨论】:

    • 这对我有帮助,谢谢!想知道为什么我的谷歌搜索没有抛出这个...
    猜你喜欢
    • 2022-01-06
    • 1970-01-01
    • 2011-08-12
    • 2023-01-04
    • 2020-04-20
    • 2021-03-13
    • 2015-03-27
    • 2011-12-13
    • 2020-08-11
    相关资源
    最近更新 更多