Ask Your Question

How to calculate face recognition rate and choose threshold when using LBPHFaceRecognizer in OpenCV

asked 2019-07-26 03:34:37 -0500

Pain gravatar image

updated 2020-11-14 05:42:20 -0500

I am using OpenCV on python to identify faces. A quick tool to help me deploy it is OpenCV's LBPHFaceRecognizer. However, I am wondering about the following parameters. When I use

recognizer = cv2.face.LBPHFaceRecognizer_create()'ckpt_face/trainer.yml')
id, confidence_face = recognizer.predict(face)

id will help me know who this face is among the trained faces. but confidence_face is not the corresponding face recognition rate. How do I know the face recognition rate? How much confidence_face do you choose in a range? Thank you everyone for your help

edit retag flag offensive close merge delete


You will have to do if/else condition block.

supra56 gravatar imagesupra56 ( 2019-07-26 06:22:11 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-07-26 11:46:32 -0500

phillity gravatar image

LBPHFaceRecognizer performs facial identification using KNN. LBPH is used to extract facial features.

During prediction, features are extracted from a given query face. Then the id of the subject with training features which are closest to the query face feature is returned. The confidence value is the distance between the query feature and the closest training feature.

If the query face feature does not belong to any of the training subjects, the confidence distance will (hopefully) be large. You need to perform an experiment in order to set a confidence distance threshold.

Your threshold should be based on your application as it presents a tradeoff between false acceptances and rejections. For example, if you don't mind some false rejections, you can set this threshold low.

edit flag offensive delete link more


Thank you. This is all I need

Pain gravatar imagePain ( 2019-07-28 21:00:41 -0500 )edit

Is there any case where the confidence distance <0?

Pain gravatar imagePain ( 2019-07-28 21:40:45 -0500 )edit

No, confidence should be a Euclidean distance. If you get a negative value that would be an indication there is something going wrong

phillity gravatar imagephillity ( 2019-07-29 17:22:29 -0500 )edit

Thank you for your anwer

Pain gravatar imagePain ( 2019-07-29 23:35:53 -0500 )edit

Question Tools

1 follower


Asked: 2019-07-26 03:34:37 -0500

Seen: 1,086 times

Last updated: Jul 26 '19