OpenCV:AttributeError:模块"cv2"没有属性"face"

问题描述:

我正在以下版本上使用Python和OpenCV创建人脸识别系统:

I am creating a face recognition system using Python and OpenCV on these versions:

  • Python 3.6.2 :: Anaconda自定义(64位)
  • Anaconda 4.3.23
  • OpenCV 3.3.0

当我尝试训练人脸识别器时:

When I try to train the face recognizer:

face_recognizer = cv2.face.createLBPHFaceRecognizer()

我收到此错误:

AttributeError:模块'cv2'没有属性'face'

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

更新:

我试图做到这一点:

pip install opencv_python‑3.3.0+contrib‑cp36‑cp36m‑win_amd64.whl

也:

conda install -c menpo opencv3=3.3.0

我仍然有错误.

我找到了解决我问题的方法,您必须按照本教程

I found the solution to my issue, you have to follow this tutorial OpenCV with extra modules.

基本步骤是:

  • 转到C:/PythonXX/lib/site-packeges(安装python的site-packages文件夹),然后删除cv2.pyd(如果存在).
  • 下载带有附加模块的OpenCV
  • 使用CMake创建Visual Studio项目
  • 打开Python IDLE,然后输入import cv2.如果没有错误,则表示安装成功.