I just recognized some faces with 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.
thank you!
You can find a section on setting thresholds in the documentation on cv::FaceRecognizer
at:
It works just the same for the OpenCV Python Wrapper, which you can easily see when calling help(cv2.createFaceRecognizer)
in Python:
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
. Anything below this will yield -1
in the prediction, which means this face is 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. 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. You always have to call FaceRecognizer::train
for these two algorithms to learn the model. The Local Binary Patterns Histograms (LBPH) model, which you can create with cv2.createLBPHFaceRecognizer
, supports updating a model without recalculating the other training samples. See the API Documentation on this:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.