从使用Python进行人脸识别的图像创建数据集 [英] Creating a dataset from an image with Python for face recognition

查看:1643
本文介绍了从使用Python进行人脸识别的图像创建数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Python中编码一个人脸识别程序(我要应用k-nn算法来分类)。

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

首先,我将图像转换为灰度,然后我创建了一个长列向量(通过使用Opencv's的imageata函数)与图像的像素(128x128 = 16384功能总)

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)

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

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

但是当我把k-nn应用到这个数据集时,是否需要对此数据集应用其他过程,而不是将图像转换为像素表示?

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?

谢谢。

推荐答案

通常,面部识别流水线需要几个阶段才能有效。一定程度的几何归一化对精度至关重要。您需要手动标记基准点,并为每个图像获取变换,或自动检测基准点,为此存在开源基准点检测器。尝试opencv的getAffineTransform函数。此外,照明差异可能导致巨大的问题。你可以尝试照明归一化技术(例如,自商图像),因为它们对漫反射和阴影(不是太多的镜面反射)工作得很好。为了降维,主成分分析(PCA)或线性判别分析(LDA)是开始的好地方。而不是原始像素的功能,但你可能会考虑更有意义的功能,如LBP,HOG或SIFT。此外,您将能够获得比KNN更高精度的更复杂(虽然更复杂)的分类器,如SVM。

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.

这篇关于从使用Python进行人脸识别的图像创建数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆