java OpenCV/JavaCV 人脸识别 - 非常相似的置信度值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11315157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:38:32  来源:igfitidea点击:

OpenCV/JavaCV face recognition - Very similar confidence values

javaopencvjavacveigenvector

提问by Fábio Constantino

I will explain what I am trying to do, as it seems to be relevant in order to understand my question.

我将解释我正在尝试做什么,因为它似乎与理解我的问题有关。

I am currently trying to do face recognition of people that step in front of a camera, based on known pictures in the database.

我目前正在尝试根据数据库中的已知图片对站​​在相机前的人进行面部识别。

These known pictures are being collected from an identifying Smart Card (which contains only a single frontal face picture) or a frontal face profile picture from a social network. From what I've read so far, it seems that for a good face recognition, a good amount of training images is required (50+). As such, since my collected images are very few to create a reliable training set, I instead tried using my live camera frame captures (currently using 150) as the training set, and the identified pictures collected previously as the test set. I'm not sure if what I'm trying with this is correct, so please let me know if I'm screwing up.

这些已知图片是从识别智能卡(仅包含一张正面图片)或来自社交网络的正面个人资料图片中收集的。从我目前所读到的内容来看,对于良好的人脸识别,似乎需要大量的训练图像(50+)。因此,由于我收集的图像很少,无法创建可靠的训练集,因此我尝试使用我的实时相机帧捕获(目前使用 150 个)作为训练集,并将之前收集的识别图片作为测试集。我不确定我的尝试是否正确,所以如果我搞砸了,请告诉我。

So, the problem is that after I have let's say, 5 identified pictures that I got from Smart Cards, I tried to do face recognition using as a training set, the 150 frames which the camera captured of my face. When trying to recognize, the confidence values for each of the 5 test faces is EXTREMELY similar, making the whole program useless, because I cannot accurately recognize anyone. Often, using different camera captures as training I get higher confidence values from pictures of random people than the picture of myself.

所以,问题是,在我从智能卡中获得 5 张已识别的图片后,我尝试使用相机拍摄的 150 帧作为训练集进行人脸识别。在尝试识别时,5 个测试人脸中的每一个的置信度值都非常相似,这使得整个程序毫无用处,因为我无法准确识别任何人。通常,使用不同的相机捕获作为训练,我从随机人物的照片中获得比我自己的照片更高的置信度值。

I would appreciate any help you can give me, because I'm at a loss here.

我很感激你能给我的任何帮助,因为我在这里不知所措。

Thank you.

谢谢你。

Note: I'm using the JavaCV wrapper for OpenCV to make my program, and the haarcascades that come included in the package. Eigenfaces being the algorithm used.

注意:我使用 OpenCV 的 JavaCV 包装器来制作我的程序,以及包中包含的 haarcascades。特征脸是使用的算法。

回答by bytefish

Face Recognition

人脸识别

Intro

介绍

I want to add this. libfacerechas been included into the official OpenCV 2.4.2, see:

我想添加这个。libfacerec已包含在官方OpenCV 2.4.2 中,请参阅:

That means if you are using OpenCV 2.4.2, then you have the new cv::FaceRecognizerin the contribmodule. I know a Python wrapper has been added lately (thanks for that!), probably Java is also wrapped at time of writing this.

这意味着如果您使用的是 OpenCV 2.4.2,那么您在contrib模块中有新的cv::FaceRecognizer。我知道最近添加了一个 Python 包装器(谢谢!),可能在编写本文时 Java 也被包装了。

cv::FaceRecognizercomes with an extensive documentation, that'll show you how to do face recognition with lotsof full source code examples:

cv::FaceRecognizer附带了一个广泛的文档,它将向您展示如何使用大量完整的源代码示例进行人脸识别:

If you want to know how the available face recognition algorithms (Eigenfaces, Fisherfaces, Local Binary Patterns Histograms) work, then especially read the Guide To Face Recognition with OpenCV. In there I explain how the algorithms work and mention their shortcomings:

如果您想了解可用的人脸识别算法(Eigenfaces、Fisherfaces、Local Binary Patterns Histograms)是如何工作的,那么请特别阅读OpenCV 人脸识别指南。在那里我解释了算法的工作原理并提到了它们的缺点:

Face Recognition with few images

少量图像的人脸识别

Now to your original problem of recognizing faces, when your training dataset is small. I'll write you a thorough answer, so it probably helps people coming here from Google.

现在,当您的训练数据集很小时,您识别人脸的原始问题。我会给你写一个详尽的答案,所以它可能会帮助从谷歌来到这里的人。

Actually Eigenfaces and Fisherfaces should not be used, when you only have very few samples per person in your data set. You need data for these models to work, I can't stress that enough. The more the better. These methods are based on estimating the variance in your data, so give them some data to estimate your model from! A while ago I ran a small test on the AT&T Facedatabase (with the facerec framework), which shows the performance of these methods with a varying number of images per person:

实际上,不应该使用 Eigenfaces 和 Fisherfaces,因为您的数据集中每个人只有很少的样本。您需要这些模型的数据才能工作,这一点再怎么强调也不为过。越多越好。这些方法基于估计数据中的方差,所以给他们一些数据来估计你的模型!不久前,我在 AT&T Facedatabase(使用facerec 框架)上进行了一个小测试,它显示了这些方法在每个人不同数量的图像的情况下的性能:

enter image description here

在此处输入图片说明

I am not writing a publication here, nor will I back these figures with a detailed mathematical analysis. It has been done before, so I recommend everyone doubting these figures to look into (2), in order to see a very detailed analysis of the PCA (Eigenfaces) and LDA (Fisherfaces) for small training data sets.

我不是在这里写出版物,也不会用详细的数学分析来支持这些数字。之前已经做过了,所以推荐大家对这些数字有疑问的去看看(2),以便看到对小训练数据集的PCA(Eigenfaces)和LDA(Fisherfaces)的非常详细的分析。

So what I suggest is using Local Binary Patterns Histograms (3) for Face Recognition in the small sample scenario. These are also included in the OpenCV FaceRecognizerand have been proven to perform very well on small training data sets. If you combine this with a TanTriggs Preprocessing (4), you should have a really robust Face Recognition model. The TanTriggs Preprocessing is a 8-liner (or so) in Python, see https://github.com/bytefish/facerec/blob/master/py/facerec/preprocessing.py#L41for the implementation. That should be easy to adapt to Java (or I can implement it with OpenCV, if people request it).

所以我建议在小样本场景中使用 Local Binary Patterns Histograms (3) 进行人脸识别。这些也包含在 OpenCV FaceRecognizer 中,并且已被证明在小型训练数据集上表现非常好。如果将此与 TanTriggs 预处理 (4) 结合使用,您应该拥有一个非常强大的人脸识别模型。TanTriggs 预处理是 Python 中的 8 行(左右),有关实现,请参见https://github.com/bytefish/facerec/blob/master/py/facerec/preprocessing.py#L41。这应该很容易适应 Java(或者我可以用 OpenCV 实现它,如果人们要求的话)。

Literature

文学

  • (1) Belhumeur, P. N., Hespanha, J., and Kriegman, D. Eigenfaces vs. Fisherfaces: Recognition Using Class Specific Linear Projection.IEEE Transactions on Pattern Analysis and Machine Intelligence 19, 7 (1997), 711–720.
  • (2) Martinez, A and Kak, A. PCA versus LDAIEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 23, No.2, pp. 228-233, 2001.
  • (3) Ahonen, T., Hadid, A., and Pietikainen, M. Face Recognition with Local Binary Patterns.Computer Vision - ECCV 2004 (2004), 469–481.
  • (4) Tan, X., and Triggs, B. Enhanced local texture feature sets for face recognition under difficult lighting conditions.IEEE Transactions on Image Processing 19 (2010), 1635–650.
  • (1) Belhumeur, PN, Hespanha, J. 和 Kriegman, D. Eigenfaces 与 Fisherfaces:使用类特定线性投影进行识别。IEEE Transactions on Pattern Analysis and Machine Intelligence 19, 7 (1997), 711–720。
  • (2) Martinez, A 和 Kak, A. PCA 与 LDAIEEE 模式分析和机器智能交易,卷。23, No.2, pp. 228-233, 2001。
  • (3) Ahonen, T.、Hadid, A. 和 Pietikainen, M.使用局部二进制模式进行人脸识别。计算机视觉 - ECCV 2004 (2004), 469–481。
  • (4) Tan, X. 和 Triggs, B.增强的局部纹理特征集,用于困难光照条件下的人脸识别。IEEE 图像处理汇刊 19 (2010), 1635–650。

回答by lukaskrieger

What you want to know is how you can perform a face recognition with only one training image. This is possible but also depends on the number of different persons you want to classify.

您想知道的是如何仅使用一张训练图像进行人脸识别。这是可能的,但也取决于您要分类的不同人员的数量。

50+ training images are certainly not needed. For a basic face recognition you need around 50 faces to calculate your face space (eigenfaces). Perhaps you mixed it up with that. See that you have lots of variations in this faces (skin colour, glasses, form ...) You can take these faces from any face database you like. http://www.face-rec.org/lists several databases and explains different algorithms.

50 多个训练图像当然是不需要的。对于基本的人脸识别,您需要大约 50 张人脸来计算您的人脸空间(特征脸)。也许你把它和那个混在一起了。看到您的面孔有很多变化(肤色、眼镜、形状……)您可以从您喜欢的任何面孔数据库中获取这些面孔。http://www.face-rec.org/列出了几个数据库并解释了不同的算法。

After you calculated your face space you train with as many faces you have. In your case you have only one. Depending on how many different subjects you want to classify this could already work.

在计算出您的人脸空间后,您可以使用尽可能多的人脸进行训练。在您的情况下,您只有一个。根据您要分类的不同主题的数量,这可能已经奏效。

If you get too many false classifications I would take a look at hybrid methods. Hybrid methods combine a template matching algorithm (eigenfaces, fisherfaces) with a feature based one. In this case you take the output of your first algorithm and match the eyes, nose, eyebrows, chin shape etc. with your test face.

如果你得到太多错误分类,我会看看混合方法。混合方法将模板匹配算法(特征脸、fisherfaces)与基于特征的算法相结合。在这种情况下,您使用第一个算法的输出并将眼睛、鼻子、眉毛、下巴形状等与您的测试脸相匹配。

In short:

简而言之:

  1. extract faces from each image with haarcascades
  2. calculate your face space
  3. train for each face
  4. ask for a face classification
  5. take the most likely classifications and check for face features
  1. 使用 haarcascades 从每个图像中提取人脸
  2. 计算你的面部空间
  3. 训练每张脸
  4. 要求人脸分类
  5. 采取最可能的分类并检查面部特征

In case you haven't found it, OpenCV has also a face recognition library: https://github.com/bytefish/libfacerec

如果你还没有找到,OpenCV 还有一个人脸识别库:https: //github.com/bytefish/libfacerec

EDIT: I wouldn't use more than 10-15 components (eigenfaces).

编辑:我不会使用超过 10-15 个组件(特征脸)。