AttributeError: module ‘cv2.cv2‘ has no attribute ‘face‘

Source
FacialRecognition % python3 02_face_training.py
Traceback (most recent call last):
  File "02_face_training.py", line 21, in <module>
    recognizer = cv2.face.LBPHFaceRecognizer_create()
AttributeError: module 'cv2.cv2' has no attribute 'face'

问题解决方法

下载我们需要的相关的包

pip install opencv-contrib-python

或

pip3 install opencv-contrib-python

如果直接安装不行,就要全部卸载一遍,然后重新安装。

pip uninstall opencv-contrib-python
 
pip uninstall opencv-python
 
pip install opencv-python
 
pip install opencv-contrib-python


 

看到successfully之后就可以运行代码啦!