Search code examples
pythonpython-3.xopencvopencv3.0face-recognition

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


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

  • Python 3.6.2 :: Anaconda custom (64-bit)
  • Anaconda 4.3.23
  • OpenCV 3.3.0

When I try to train the face recognizer:

face_recognizer = cv2.face.createLBPHFaceRecognizer()

I get this error:

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

Update:

I've tried to do this:

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

Also:

conda install -c menpo opencv3=3.3.0

And I still have the error.


Solution

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

    The essential steps are:

    • Go to C:/PythonXX/lib/site-packeges (the site-packages folder where your python is installed), and delete cv2.pyd if present.
    • Download OpenCV with extra modules
    • Create a Visual Studio project with CMake
    • Open Python IDLE and enter import cv2. If there is no error, then the installation is successful.