2

After referring to some Stack Overflow answers I did pip install opencv-contrib, still I am getting those errors.

code for training:

face_recognizer=cv2.face.LBPHFaceRecognizer_create()

code for facial detection:

faces,faceID = fr.labels_for_training_data('C:\\Users\\Desktop\\python tests\\0')
face_recognizer=fr.train_classifier(faces,faceID)
face_recognizer.save('C:\\Users\\Desktop\\python tests\\trainingData.yml')

And Error is :

 File "C:/Users/vsneh/OneDrive/Desktop/python tests/Face_detect_Tester.py", line 15, in <module>
    face_recognizer=fr.train_classifier(faces,faceID)
  File "C:/Users/vsneh/OneDrive/Desktop/python tests\faceRecognition.py", line 47, in train_classifier
    face_recognizer=cv2.faces.LBPHFaceRecognizer_create()
AttributeError: module 'cv2.cv2' has no attribute 'faces'
1

1 Answer 1

4

Try update OpenCV with

pip install opencv-contrib-python
2
  • It worked in my case. Do you know how are these modules: opencv-contrib-python and openCV different?
    – xanjay
    Commented Aug 8, 2019 at 17:39
  • I believe opencv-contrib-python is the unofficial pre-built OpenCV package. It's not the official OpenCV package released by OpenCV.org. There is also opencv-python which contains just the main modules of the OpenCV library while opencv-contrib-python contains both the main modules along with the contrib modules. You don't want to install both, pick only one.
    – nathancy
    Commented Aug 8, 2019 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.