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'
nathancy
  • 42,661
  • 14
  • 115
  • 137
  • Possible duplicate of [attributeerror: module 'cv2.face' has no attribute 'createlbphfacerecognizer'](https://stackoverflow.com/questions/45655699/attributeerror-module-cv2-face-has-no-attribute-createlbphfacerecognizer) – Edeki Okoh Apr 08 '19 at 20:33

1 Answers1

4

Try update OpenCV with

pip install opencv-contrib-python
nathancy
  • 42,661
  • 14
  • 115
  • 137
  • It worked in my case. Do you know how are these modules: opencv-contrib-python and openCV different? – xanjay Aug 08 '19 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 Aug 08 '19 at 19:51