使用 Python 从图像创建数据集以进行人脸识别

发布于 2024-10-02 00:46:52 字数 387 浏览 9 评论 0原文

我正在尝试用 Python 编写一个人脸识别程序(我将应用 k-nn 算法进行分类)。

首先,我将图像转换为灰度,然后使用图像的像素(128x128= 16384 个特征)创建一个长列向量(通过使用 Opencv 的 imagedata 函数),

所以我得到了如下所示的数据集(最后一列是类)标签,我只显示了数据集的前 7 个特征,而不是 16384)。

176, 176, 175, 175, 177, 173, 178, 1 
162, 161, 167, 162, 167, 166, 166, 2

但是当我将 k-nn 应用于这个数据集时,我得到了尴尬的结果。我是否需要对此数据集应用额外的处理,而不仅仅是将图像转换为像素表示?

谢谢。

I am trying to code a face-recognition program in Python (I am going to apply k-nn algorithm to classify).

First of all, I converted the images into greyscale and then I created a long column vector (by using Opencv's imagedata function) with the image's pixels (128x128= 16384 features total)

So I got a dataset like the following (last column is the class label and I only showed first 7 features of the dataset instead of 16384).

176, 176, 175, 175, 177, 173, 178, 1 
162, 161, 167, 162, 167, 166, 166, 2

But when I apply k-nn to this dataset, I get awkward results. Do I need to apply additional processes to this dataset instead of just converting the image to pixel representation?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

硪扪都還晓 2024-10-09 00:46:53

您可能需要将眼睛、鼻尖和嘴巴对齐。

您可能还需要更复杂的图像表示方法。例如,梯度方向和自商图像将是很好的起点。

You will probably need the eyes, tip of nose and mouth aligned.

You will probably also need a more sophisticated image representation method. For example, direction of gradient and self quotient image would be good starting points.

猫瑾少女 2024-10-09 00:46:53

你如何打印这个?您是否尝试过使用重塑功能?它将 2D 图像转换为具有/不具有多个通道的 1D 图像。

此外,图像的像素不是特征。脸部后面可以有很多不同的物体 - 窗帘、书籍、其他脸部等。脸部边界、眼睛之间的距离等对这些东西来说更不变。

How do you print this? Did you try using the reshape function? It converts 2D images into 1D images with/without multiple channels.

Also, an image's pixels aren't features. You can have a lot of different objects behind the face - curtains, books, other faces, etc. Things like boundary of the face, distance between eyes, etc are more invariant to such things.

白龙吟 2024-10-09 00:46:52

通常,人脸识别管道需要几个阶段才能有效。一定程度的几何标准化对于准确性至关重要。您要么需要手动标记基准点并获取每个图像的变换,要么自动检测基准点(有开源基准点检测器)。尝试opencv的getAffineTransform函数。此外,照明差异可能会导致巨大的问题。您可以尝试照明归一化技术(例如,自商图像),因为它们对于漫反射和阴影(而不是镜面反射)非常有效。对于降维,主成分分析 (PCA) 或线性判别分析 (LDA) 是很好的起点。不过,您可能会考虑更有意义的特征,例如 LBP、HOG 或 SIFT,而不是原始像素特征。此外,使用更复杂(尽管更复杂)的分类器(例如 SVM),您将能够获得比 KNN 更高的准确度。

Usually, a face recognition pipeline needs several stages in order to be effective. Some degree of geometric normalization is critical to accuracy. You either need to manually label fiducial points and acquire a transform for each image, or automatically detect fiducial points, for which there are open source fiducial point detectors. Try opencv's getAffineTransform function. Also, lighting discrepancies can cause huge problems. You might try lighting normalization techniques (e.g., self quotient image), as they work pretty well for diffuse reflection and shadows (not so much specular reflection). For dimensionality reduction, principal components analysis (PCA) or linear discriminant analysis (LDA) are good places to start. Rather than raw pixel features, though, you might consider more meaningful features like LBP, HOG, or SIFT. Also, you will be able to attain higher accuracy than KNN with more sophisticated (although more complicated) classifiers such as SVM's.

生生不灭 2024-10-09 00:46:52

如果你想让它运行良好,是的,你需要进行功能转换。

PCA 或 LDA 效果很好。 PCA 将获取输入向量的集合(在本例中为矢量化图像)并找到跨越该组输入的特征脸。然后,在测试过程中,您将输入向量(即图像)投影到这组特征脸上,并使用生成的坐标向量作为特征向量。有关详细信息,请参阅 [特克和彭特兰,1991]。

我在 PIE 数据库 成功。

If you want it to work well, yes, you need to do a feature transformation.

PCA or LDA work well. PCA will take a collection of input vectors (in this case, your vectorized images) and find the Eigenfaces that span the set of inputs. Then, during testing, you project your input vector (i.e., image) onto this set of Eigenfaces and use the resulting coordinate vector as your feature vector. For more information, see [Turk and Pentland, 1991].

My personal experiments using this basic PCA method on the PIE database were successful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文