gpt4 book ai didi

python - 从训练有素的分类器中获取结果 - 图像处理

转载 作者:行者123 更新时间:2023-11-30 09:37:15 25 4
gpt4 key购买 nike

我正在研究一个使用 OpenCV 和 Python 编码的图像性别检测项目。

我找到了this博客文章和 this opencv教程。在这些网站中,他们建议使用fisherfaces 方法和NearestNeighbor 算法来制作性别分类模型。

这是我的问题:

我是机器学习的新手,所以在这个分类部分之后,我找不到如何将另一个图像应用到这个分类器并采取如下结果形式:

"This person is Male."
"This person is Female."

如何从分类器中获取上述结果?

最佳答案

使用引用数据来教授分类器。你给他每堂课(培训)的例子。假设有 500 张女孩的照片和 500 张男孩的照片。您告诉分类器每张图片的性别。然后,您向分类器提供一张未知图像,他将使用经过训练的“知识”来选择一个类别(如果可能)。

仔细阅读 OpenCV 演示代码。你需要的一切都在那里。

从第 100 行开始:

Mat testSample = images[images.size() - 1];
int testLabel = labels[labels.size() - 1];
images.pop_back();
labels.pop_back();
// The following lines create an Fisherfaces model for
// face recognition and train it with the images and
// labels read from the given CSV file.
// If you just want to keep 10 Fisherfaces, then call
// the factory method like this:
//
// cv::createFisherFaceRecognizer(10);
//
// However it is not useful to discard Fisherfaces! Please
// always try to use _all_ available Fisherfaces for
// classification.
//
// If you want to create a FaceRecognizer with a
// confidence threshold (e.g. 123.0) and use _all_
// Fisherfaces, then call it with:
//
// cv::createFisherFaceRecognizer(0, 123.0);
//
Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
model->train(images, labels);
// The following line predicts the label of a given
// test image:
int predictedLabel = model->predict(testSample);

在他们使用 CSV 文件加载图像和标签之前。然后,出于演示目的,他们从矢量中取出最后一个图像,将其从矢量中删除,并将其用作测试中的图像。 (因此被测试的图像不会在训练数据中)。然后他们使用剩余的图像训练 Fisher 事物并将其应用到图像“testSample”

因此,您所需要做的就是将 testSample 替换为您的一张图像,并根据找到的标签打印出一个句子。

关于python - 从训练有素的分类器中获取结果 - 图像处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35201438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com