简体   繁体   English

如何使用opencv计算人脸识别的百分比格式预测置信度?

[英]How to calculate percentage format prediction confidence of face recognition using opencv?

I am doing a two-faces comparison work using OpenCV FaceRecognizer of LBP type. 我正在使用LBP类型的OpenCV FaceRecognizer比较工作。 My question is how to calculate the percentage format prediction confidence? 我的问题是如何计算百分比格式预测置信度? Giving the following code( javacv ): 提供以下代码( javacv ):

int n[] = new int[1];
double p[] = new double[1];
personRecognizer.predict(mat, n, p);
int confidence = p[0];

but the confidence is a double value, how should I convert it into a percentage % value of probability ? 但是信心是双重值, how应该how convert其转换为probability percentage %值? Is there an existing formula? 有现成的配方吗?

Sorry if I didn't state my question in a clear way. 对不起,如果我没有以明确的方式陈述我的问题。 Ok, here is the scenario: 好的,这是场景:

I want to compare two face images and get out the likeliness of the two face, for example input John's pic and his classmate Tom's pic, and let's say the likeliness is 30%; 我想比较两张脸部图像,并得出两张脸的可能性,例如输入约翰的照片和他的同学汤姆的照片,让我们说可能性是30%; and then input John's pic and his brother Jack's pic, comes the likeliness is 80%. 然后输入约翰的照片和他的兄弟杰克的照片,可能性是80%。 These two likeliness factor shows that Jack is more like his brother John than Tom does... so the likeliness factor in percentage format is what i want, more the value means more likeliness of the two input face. 这两个可能性因素表明,杰克更像是他的兄弟约翰,而不是汤姆...所以百分比格式的可能性因素是我想要的,更多的价值意味着两个输入面的更多可能性。 Currently I did this by computing the confidence value of the input using opencv function FaceRecognizer.predict, but the confidence value actually stands for the distance between the inputs in their feature vectors space, so how can I scale the distance(confidence) into the likeliness percentage format? 目前我通过使用opencv函数FaceRecognizer.predict计算输入的置信度值来做到这一点,但置信度值实际上代表了特征向量空间中输入之间的距离,因此如何将距离(置信度)扩展为可能性百分比格式?

You are digging too deep by your question. 你的问题正在深入挖掘。 Well, according to the OpenCV documentation: predict() 好吧,根据OpenCV文档: predict()

Predicts a label and associated confidence (eg distance) for a given input image 预测给定输入图像的标签和相关置信度(例如距离)

I am not sure what are you looking for here but the question is not really easy to be answered. 我不确定你在这里找什么,但问题并不容易回答。 Intra-person face variants (variation of the same person) are vast and inter-person face variation (faces from different persons) can be more compact (eg when both face front while the intra-person second facial image is profile) so this is a whole topic that expect an answer. 人物内部变形(同一人的变化)是巨大的,并且人际面部变化(来自不同人的面部)可以更紧凑(例如,当面向前面而人体内第二面部图像是轮廓时)所以这是一个期待答案的整个主题。

Probably you should have a ground truth (ie some faces with labels already known) and deduct form this set the percentage you want associating the distances with the labels. 可能你应该有一个基本的事实(即一些已经知道标签的面孔)并从此设置中扣除你想要将距离与标签相关联的百分比。 Though this is also often inaccurate as distance would not coincide with your perception of similarity (as mentioned before inter-person faces can vary a lot). 虽然这也常常不准确,因为距离与你对相似性的感知不一致(如之前提到的人际面孔可能变化很大)。

Edit: 编辑:

First of all, there is no universal human perception of face similarity. 首先,人类对面部相似性的看法并不普遍。 On the other half, most people would recognize a face that belongs to the same person in various poses and postures. 在另一半,大多数人会认出一个面对各种姿势和姿势的同一个人的脸。 Most word here is important. 这里的大多数词都很重要。 As you pressure the limits the human perception will start to diverge, eg when asked to recognize a face over the years and the time span becomes quite large (child vs adolescence vs old person). 当你施加压力时,人类的感知会开始出现分歧,例如,当被要求多年来识别一张脸并且时间跨度变得非常大时(儿童与青春期与老人相比)。

You are asking to compute the similarity of noses/eyes etc? 你要求计算鼻子/眼睛等的相似性? If so, I think the best way is to find a set of noses/eyes belonging to the same persons and train over this and then check your performance on a different set from different persons. 如果是这样,我认为最好的方法是找到属于同一个人的一组鼻子/眼睛,并训练一下,然后检查你在不同人的不同场景上的表现。

The usual approach as I know is to train and test using pairs of images comprising positive and negative samples. 我所知道的常用方法是使用包含正样本和负样本的图像对进行训练和测试。 A positive sample is a pair of images belonging to the same person while a negative one is an image pair belong to two different ones. 正样本是属于同一人的一对图像,而负片样本是属于两个不同的图像对。

I am not sure what you are asking exactly so maybe you can check out this link . 我不确定你究竟在问什么,也许你可以查看这个链接

Hope it helped. 希望它有所帮助。

Edit 2: 编辑2:

Well, since you want to convert the distance that you are getting to a similarity expressed as percentage you can somehow invert the distance to get the similarity. 好吧,因为你想要将你得到的距离转换为以百分比表示的相似度,你可以以某种方式反转距离以获得相似性。 There are some problems arising here though: 但是这里出现了一些问题:

  • There is a value for absolute match, that is dis = 0; 有一个绝对匹配的值,即dis = 0; or equivalently similarity is sim = 100% but there is no value explicit for total mismatch: dis = infinite so sim = 0% . 或等效相似度为sim = 100%但没有明确的总不匹配值: dis = infinite因此sim = 0% On the other hand the inverse progress has explicit boundaries 0% - 100% . 另一方面,逆进展具有明确的边界0% - 100%
  • Since extreme values include 0 and infinite there must be a smarter conversion than simple inversion. 由于极值包括0和无穷大,因此必须有比简单反转更智能的转换。

You can easily assign 1.0 (or 100% to similarity) corresponding to the absolute match but what you are going to take as total mismatch is not clear. 您可以轻松地分配对应于绝对匹配的1.0 (或100%相似性),但是您将要采取的是因为总不匹配不明确。 You can consider an arbitrary high value as 0.0 (since you there is no big difference eg in using distance 10000 to 11000 I guess) and all values higher than this (distance values that is) to be considered 0.0 . 您可以将任意高值视为0.0 (因为您没有大的差异,例如在使用距离10000到11000时我猜)并且所有高于此值的值(距离值)都被视为0.0

To find which value that should be I would suggest to compare two quite distinct images and use the distance between them as 0.0. 为了找到应该是哪个值,我建议比较两个截然不同的图像,并使用它们之间的距离为0.0。

Let's suppose that this value is disMax = 250.0; 我们假设这个值是disMax = 250.0; and simMax = 100.0; simMax = 100.0; then a simple approach could be: double sim = simMax - simMax/disMax*dis; 然后一个简单的方法可能是:double sim = simMax - simMax / disMax * dis;

which gives a 100.0 similarity for 0 distance and 0.0 for 250 distance. 它给出0距离的100.0相似度和250距离的0.0。 Values larger than 250 would give negative similarity values which should be considered 0.0. 大于250的值将给出负相似值,其应被视为0.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM