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'
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'
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.
Do this:
pip uninstall opencv_contrib_python
and install again:
pip install opencv_contrib_python