-1

In the following code, i am getting error at following step:

model = cv2.face.LBPHFaceRecognizer_create()

[]

Error:

AttributeError: module 'cv2.cv2' has no attribute 'face'
2

2 Answers 2

3

The face module isn't actually a part of the opencv library proper. Rather, face is part of the opencv-contrib library. From the readme:

This repository [opencv-contrib] is intended for development of so-called "extra" modules, contributed functionality. New modules quite often do not have stable API, and they are not well-tested. Thus, they shouldn't be released as a part of official OpenCV distribution, since the library maintains binary compatibility, and tries to provide decent performance and stability.

opencv-contrib needs to be installed separately. As @james pointed out (in a now deleted comment), the current easy way to get the Python version is to just do:

pip install opencv-contrib-python

After you run the above pip call, your code should work.

1
  • I had installed it Commented Jan 12, 2019 at 12:10
3

Do this:

pip uninstall opencv_contrib_python

and install again:

pip install opencv_contrib_python

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.