Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AvadheshChoudhary opened this issue Sep 23, 2017 · 5 comments
Open

Comments

@AvadheshChoudhary
Copy link

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

@Clanatia
Copy link

'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.

@informramiz
Copy link
Owner

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.

@foysalhaque
Copy link

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?

@AnneJ17
Copy link

AnneJ17 commented Apr 14, 2020

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()

@shashanks33
Copy link

shashanks33 commented May 18, 2020

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants