c++ - OpenCV predict() 与 detectMultiScale()

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

我正在使用 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);

然而,我遇到了this implementation使用 detectMultiScale()“级联分类器”。有什么不同?与我目前使用的方式相比,使用 Cascade Classifier 是否有性能优势? detectMultiScale() 是否比 predict() 更好?

最佳答案

CascadeClassifier::detectMultiScale 函数用于对象检测。它返回类型为 std::vector<cv::Rect> 的变量其中包含检测到的对象的边界矩形。

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

关于c++ - OpenCV predict() 与 detectMultiScale(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50043584/

相关文章:

c++ - constexpr 初始化是否应该在其他初始化之前发生

python - Raspberry Pi 3 上的 OpenCV 多 USB 摄像头

.net - 如何在 webapi 中手动优化文件夹中的多个图像(减小文件大小)?

javascript - 带有 HTML5 Canvas 的 putImageData 的掩码?

c# - 从 PHP 最快访问密集型函数?

c++ - C++中的Waitpid创建问题

C++/Win32 枚举属于我的进程的窗口并关闭它们

c - OpenCV 2.1 : Runtime error

python - 执行图像配准时图像之间的匹配不当

opengl - 用于图像处理的 GPU 编程