简体   繁体   English

OpenCV的predict()与detectMultiScale()

[英]OpenCV predict() vs detectMultiScale()

I'm working on doing some Face, Gender, and Age detection using OpenCV. 我正在使用OpenCV进行面部,性别和年龄检测。 I have a bunch of images I use to train the models, Essentally I currently have the following: 我有一堆用于训练模型的图像,基本上,我目前有以下图像:

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");

Then using the temp.xml heuristic, I predict the geneder like so: 然后,使用temp.xml启发式算法,如下预测该生成器:

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

However, I came across this implementation using detectMultiScale() and a "Cascade Classifier" . 不过,我碰到这个实现使用detectMultiScale()"Cascade Classifier" What is the diffrence? 有什么区别? Is there a performance advantage to using a Cascade Classifier vs the way I am currently doing it? 与我目前使用的方式相比,使用Cascade Classifier在性能上有优势吗? Does detectMultiScale() work better then predict() ? detectMultiScale()效果好于predict()吗?

CascadeClassifier::detectMultiScale function is used for object detection . CascadeClassifier::detectMultiScale函数用于对象检测 It returns a variable of type std::vector<cv::Rect> which contains bounding rectangles of detected objects. 它返回一个std::vector<cv::Rect>类型的变量,其中包含检测到的对象的边界矩形。

FaceRecognizer::predict function is used for object classification . FaceRecognizer::predict函数用于对象分类 It returns the class label of input image and the confidence with which the object is predicted. 它返回输入图像的类别标签和预测对象的置信度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM