-4

I'm trying to create a face recognition system for my project, but I can't train my code to recognize faces because it keeps on failing.

Here's the error:

>>> import cv2
>>> print(dir(cv2.face))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'cv2' has no attribute 'face'

I typed this on terminal to try and check if it worked but it doesn't. I already tried every solution that I found online but it still doesn't work. I already uninstalled and installed opencv-contrib-python multiple times. I uninstall opencv-python. Installed cmake and dlib.

I used Python 3.9.13, Windows, and Pycharm.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • The module `cv2` does not have `face` as an attribute, doing `cv2.face` is causing this error. What are you trying to get out of `dir(cv2.face)`? – Shorn Mar 14 '23 at 06:00
  • 1
    It seems like the cv2 module in your system does not have the face submodule. This could be due to several reasons such as outdated cv2 version or not installing the required dependencies. – iamkw97 Mar 14 '23 at 06:00
  • @Shorn I'm trying to run recognizer = cv2.face.LBPHFaceRecognizer_create() – Newbees Mar 15 '23 at 07:17
  • @iamkw97 my cv2 is updated to the latest version, can you give an example for the required dependencies? – Newbees Mar 15 '23 at 07:19
  • This question received heavy downvoting. There may be two reasons why: (1) the repeated "please help me" messages are needy and unnecessary, please avoid them; (2) the duplication of material in the post to get past a Stack Overflow quality filter. – halfer Mar 18 '23 at 20:37

1 Answers1

0

You need to install opencv-contrib

pip install opencv-contrib-python

It should work after that.

Dev
  • 7
  • 8
  • I already did that, and it still doesn't work – Newbees Mar 15 '23 at 07:12
  • try going through these threads: [https://stackoverflow.com/questions/45655699/attributeerror-module-cv2-face-has-no-attribute-createlbphfacerecognizer] and [https://stackoverflow.com/questions/46288224/opencv-attributeerror-module-cv2-has-no-attribute-face] you might find your answer there. – Dev Mar 16 '23 at 06:10