AttributeError: module 'cv2.cv2' has no attribute 'createLBPHFaceRecognizer'

224,854

Solution 1

You need to install opencv-contrib

pip install opencv-contrib-python

It should work after that.

Solution 2

if you are using python3.x and opencv==4.1.0 then use following commands First of all

python -m pip install --user opencv-contrib-python

after that use this in the python script

cv2.face.LBPHFaceRecognizer_create() 

Solution 3

python -m pip install --user opencv-contrib-python

After doing this just Restart your system and then if you are on Opencv >= 4.* use :
recognizer = cv2.face.LBPHFaceRecognizer_create()

This should solve 90% of the problem.

Solution 4

I have some problem while executing :

import cv2 as cv
face_recognizer = cv.face.LBPHFaceRecognizer_create()

generating an error : cv2.cv2 has no face attributes.

if i try to install with :

sudo pip install opencv-contrib-python

it will take hours to compile and finally nothing works !

But on the site : https://www.piwheels.org/project/opencv-contrib-python/#install only version 4.4.0.46 has files !

Then I try this :

sudo pip3 install opencv-contrib-python==4.4.0.46

installation is instantaneous !!!

I need to install some other libraries :

sudo apt install libaec0 libaom0 libatk-bridge2.0-0 libatk1.0-0 libatlas3-base libatspi2.0-0 libavcodec58 libavformat58 libavutil56 libbluray2 libcairo-gobject2 libcairo2 libchromaprint1 libcodec2-0.8.1 libcroco3 libdatrie1 libdrm2 libepoxy0 libfontconfig1 libgdk-pixbuf2.0-0 libgfortran5 libgme0 libgraphite2-3 libgsm1 libgtk-3-0 libharfbuzz0b libhdf5-103 libilmbase23 libjbig0 libmp3lame0 libmpg123-0 libogg0 libopenexr23 libopenjp2-7 libopenmpt0 libopus0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpixman-1-0 librsvg2-2 libshine3 libsnappy1v5 libsoxr0 libspeex1 libssh-gcrypt-4 libswresample3 libswscale5 libsz2 libthai0 libtheora0 libtiff5 libtwolame0 libva-drm2 libva-x11-2 libva2 libvdpau1 libvorbis0a libvorbisenc2 libvorbisfile3 libvpx5 libwavpack1 libwayland-client0 libwayland-cursor0 libwayland-egl1 libwebp6 libwebpmux3 libx264-155 libx265-165 libxcb-render0 libxcb-shm0 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxinerama1 libxkbcommon0 libxrandr2 libxrender1 libxvidcore4 libzvbi0

It works well since when using import cv2 face !!

I have now in pip3 freeze :

opencv-contrib-python==4.4.0.46
opencv-python==4.5.1.48

Hope this will be usefull !!!!!

Solution 5

I had a similar problem:

module cv2 has no attribute "cv2.TrackerCSRT_create"

My Python version is 3.8.0 under Windows 10. The problem was the opencv version installation.

So I fixed this way (cmd prompt with administrator privileges):

  1. Uninstalled opencv-python: pip uninstall opencv-python
  2. Installed only opencv-contrib-python: pip install opencv-contrib-python

Anyway you can read the following guide:

https://github.com/skvark/opencv-python

Share:
224,854
Manjurul Ahsan
Author by

Manjurul Ahsan

Updated on July 09, 2022

Comments

  • Manjurul Ahsan
    Manjurul Ahsan almost 2 years

    I am facing some attribute error while running face recognizing the code. My face detects code run perfectly.But while I try to run the face recognizing code it shows some attribute error. I googled and tried to follow all the steps. But still, it shows the same error. Here is my code:

    face recognition

    enter link description here

    and I get the following error:

    C:\Users\MAN\AppData\Local\Programs\Python\Python36\python.exe C:/Users/MAN/PycharmProjects/facerecognition/Recognise/recognize1.py
    Traceback (most recent call last):
      File "C:/Users/MAN/PycharmProjects/facerecognition/Recognise/recognize1.py", line 4, in <module>
        recognizer = cv2.createLBPHFaceRecognizer()
    AttributeError: module 'cv2.cv2' has no attribute 'createLBPHFaceRecognizer'
    
    Process finished with exit code 1.
    

    I am using Windows platform. python 3.6 version.Thanks in advance.