【问题标题】:OpenCV predict() vs detectMultiScale()OpenCV predict() 与 detectMultiScale()
【发布时间】:2018-10-07 04:31:26
【问题描述】:

我正在使用 OpenCV 进行面部、性别和年龄检测。我有一堆用于训练模型的图像,基本上我目前有以下内容:

Ptr<cv::face::FaceRecognizer> model = cv::face::LBPHFaceRecognizer::create(9, 9);
std::vector<int> labels;
std::vector<std::string> imageFileNames;

for (int currImageIndex = 0; currImageIndex < imageFileNames.size(); currImageIndex++)
{
    cv::Mat currMatrix;
    std::string currentFileName = imageFileNames[currImageIndex];
    std::string gender;
    int currID = -1;

    //Save the image and the corresponding ID to the list(s).
    currMatrix = imread(currentFileName , CV_LOAD_IMAGE_GRAYSCALE);
    if (currMatrix.data != NULL)
    {
        images.push_back(currMatrix);
        labels.push_back(currID);
    }
}

model->train(images, labels);
model->write("C:\\temp.xml");

然后使用temp.xml 启发式,我像这样预测性别:

gendermodel->predict(currMat, predictedLabel, conf);

但是,我使用detectMultiScale()"Cascade Classifier" 遇到了this implementation。有什么区别?与我目前使用的方式相比,使用Cascade Classifier 是否有性能优势? detectMultiScale()predict() 更好用吗?

【问题讨论】:

    标签: c++ opencv image-processing face-detection face


    【解决方案1】:

    CascadeClassifier::detectMultiScale 函数用于对象检测。它返回一个std::vector&lt;cv::Rect&gt; 类型的变量,其中包含检测到的对象的边界矩形。

    FaceRecognizer::predict 函数用于对象分类。它返回输入图像的类标签和预测对象的置信度。

    【讨论】:

    • 是否可以使用 detectMultiScale 进行某种类型的性别检测,或者 FaceRecognizer::predict() 是否总是用于分类?
    • @Katianie... 性别预测是一个分类问题,所以FaceRecognizer::predict 更适合它。可以通过detectMultiScale 来实现,但这会很麻烦,而且可能不够准确。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    • 2015-09-14
    • 2016-02-23
    • 2014-01-15
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多