简体   繁体   English

openCV的特征脸

[英]eigenfaces with openCV

I just recognized some faces with cv2.createEigenFaceRecognizer . 我刚刚用cv2.createEigenFaceRecognizer识别了一些面孔。 But what I want is to know how much the input face looks like the calculated eigenfaces. 但我想要的是知道输入面看起来像计算的特征脸多少。 The idea is that you can rerecognize persons that are not in the database. 这个想法是你可以重新识别不在数据库中的人。

EDIT: 编辑:

for example: I have face A, B and C trained on my model, then I see face C and D. I want to be able to differentiate face C from D. 例如:我在我的模型上训练了面部A,B和C,然后我看到面部C和D.我希望能够将面部C与D区分开来。

thank you! 谢谢!

You can find a section on setting thresholds in the documentation on cv::FaceRecognizer at: 您可以在cv::FaceRecognizer的文档中找到有关设置阈值的部分:

It works just the same for the OpenCV Python Wrapper, which you can easily see when calling help(cv2.createFaceRecognizer) in Python: 它与OpenCV Python Wrapper的工作原理相同,在Python中调用help(cv2.createFaceRecognizer)时可以很容易地看到它:

Help on built-in function createEigenFaceRecognizer in module cv2:

createEigenFaceRecognizer(...)
    createEigenFaceRecognizer([, num_components[, threshold]]) -> retval

So in the code you would create the model with a threshold, I'll set it to 100.0 . 因此,在代码中,您将使用阈值创建模型,我将其设置为100.0 Anything below this will yield -1 in the prediction, which means this face is unknown : 低于此值的任何东西在预测中都会产生-1 ,这意味着这个面孔是unknown

# Create the Eigenfaces model. We are going to use the default
# parameters for this simple example, please read the documentation
# for thresholding:
model = cv2.createEigenFaceRecognizer(threshold=100.0)

As shown in the demo, you can get the prediction and associated confidence (which is the distance to the nearest neighbor in the your training dataset) with: 如演示中所示,您可以通过以下方式获得预测和相关置信度(这是与训练数据集中最近邻居的距离):

[predicted_label, predicted_confidence] = model.predict(image)

So if you train your model on the subjects A , B , C AND you are using a threshold, then a prediction for D should yield -1 , while A , B or C should be recognized. 因此,如果您在主题ABC上训练您的模型并且您正在使用阈值,那么D的预测应该产生-1 ,而应该识别ABC Given the fact, that you are using a threshold. 鉴于事实,您正在使用阈值。

As for adding new faces iteratively without re-estimating the whole model. 至于迭代地添加新面部而不重新估计整个模型。 This is not possible for the Eigenfaces or Fisherfaces method. 这对于特征脸或Fisherfaces方法是不可能的。 You always have to call FaceRecognizer::train for these two algorithms to learn the model. 您总是需要为这两种算法调用FaceRecognizer::train来学习模型。 The Local Binary Patterns Histograms (LBPH) model, which you can create with cv2.createLBPHFaceRecognizer , supports updating a model without recalculating the other training samples. 可以使用cv2.createLBPHFaceRecognizer创建的局部二进制模式直方图(LBPH)模型支持更新模型,而无需重新计算其他训练样本。 See the API Documentation on this: 请参阅以下API文档:

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

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