我正在使用 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"
遇到了 这个实现。有什么区别?与我目前的做法相比,使用
Cascade Classifier
是否有性能优势? detectMultiScale()
比 predict()
效果更好吗?
CascadeClassifier::detectMultiScale
功能用于对象检测。它返回一个类型为 std::vector<cv::Rect>
的变量,其中包含检测到的对象的边界矩形。
FaceRecognizer::predict
函数用于对象分类。它返回输入图像的类标签以及预测对象的置信度。