opencv-face-recognition-python icon indicating copy to clipboard operation
opencv-face-recognition-python copied to clipboard

TypeError: list indices must be integers or slices, not tuple

Open AvadheshChoudhary opened this issue 7 years ago • 5 comments

Preparing data... Data prepared Total faces: 23 Total labels: 23 Predicting images... Traceback (most recent call last): File "/Users/avadhesh/Downloads/opencv-face-recognition-python-master/OpenCV-Face-Recognition-Python.py", line 329, in predicted_img1 = predict(test_img1) File "/Users/avadhesh/Downloads/opencv-face-recognition-python-master/OpenCV-Face-Recognition-Python.py", line 309, in predict label_text = subjects[label] TypeError: list indices must be integers or slices, not tuple

Process finished with exit code 1

AvadheshChoudhary avatar Sep 23 '17 12:09 AvadheshChoudhary

'label' is two value-> (1, 0.0)

first value is subjects label text count , second is.. I don't know.

so I change like this -> label_text = subjects[label[0]]

it's work.

Clanatia avatar Sep 27 '17 07:09 Clanatia

Latest versions of OpenCV's predict function returns a (label, confidence) tuple. The first value is the label of the subject identified and the second value is the confidence score for that subject. You can use the confidence to filter out low confidence images as unknown subjects. So @Clanatia is right

changing following

label_text = subjects[label]

to

label_text = subjects[label[0]]

should work fine on OpenCV versions which give this error.

informramiz avatar Sep 29 '17 21:09 informramiz

AttributeError Traceback (most recent call last) in () ----> 1 face_recognizer = cv2.face.createLBPHFaceRecognizer() 2

AttributeError: module 'cv2' has no attribute 'face' Why is this problem occurring?

foysalhaque avatar Jul 12 '18 10:07 foysalhaque

AttributeError Traceback (most recent call last) in () ----> 1 face_recognizer = cv2.face.createLBPHFaceRecognizer() 2

AttributeError: module 'cv2' has no attribute 'face' Why is this problem occurring?

Use this instead: face_recognizer = cv2.face.LBPHFaceRecognizer_create()

AnneJ17 avatar Apr 14 '20 17:04 AnneJ17

AttributeError Traceback (most recent call last) in () ----> 1 face_recognizer = cv2.face.createLBPHFaceRecognizer() 2

AttributeError: module 'cv2' has no attribute 'face' Why is this problem occurring?

Try to install opencv using: python -m pip install --user opencv-contrib-python And then try cv2.face.HBPHFaceRecognizer_create()

shashanks33 avatar May 18 '20 09:05 shashanks33