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
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.
You might be running Python3 and therefore you are supposed to use pip3 to install the opencv-contrib package :
pip3 install opencv-contrib-python
This worked for me.
Check your OpenCV version
import cv2
cv2.__version__
If your are running Python v3.x and OpenCV v4 and above:
pip install opencv-contrib-python
Try running your program again. This should now work.
For me, I had to have OpenCV (3.4.2), Py-OpenCV (3.4.2), LibOpenCV (3.4.2).
My Python was version 3.5.6 with Anaconda in Windows OS 10.
I got openCV installed smoothly in my mac by:
$ brew install opencv
$ brew link --overwrite --dry-run opencv // to force linking
$ pip3 install opencv-contrib-python
I got it at windows 10 using:
c:\> pip3 install opencv-python
c:\> pip3 install opencv-contrib-python
Then I got it tested by
$ python3
Python 3.7.3 (default, Mar 27 2019, 09:23:15)
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.1.0'
>>> exit()
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):
pip uninstall opencv-python
pip install opencv-contrib-python
Anyway you can read the following guide:
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.
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()
opencv has changed some functions and moved them to their opencv_contrib repo so you have to call the mentioned method with:
recognizer = cv2.face.createLBPHFaceRecognizer()
Note: You can see this issue about missing docs. Try using help function help(cv2.face.createLBPHFaceRecognizer)
for more details.
For me changing createLBPHFaceRecognizer() to
recognizer = cv2.face.LBPHFaceRecognizer_create()
fixed the problem
Use the following
recognizer = **cv2.face.LBPHFaceRecognizer_create()**
After you install:
pip install opencv-contrib-python
If using anaconda then in anaconda prompt:
conda install pip
then
pip install opencv-contrib-python
I tried all of the different things but nothing seems to be working then I just restarted my IDE and it worked like charm.
Still, if it does not work then try restarting your system.
FYI, I am working on the following versions
opencv-contrib-python==4.4.0.46
opencv-python==4.1.2.30
You need to install opencv-contrib
pip install opencv-contrib-python
It should work after that.
Source: Stackoverflow.com