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