Opencv: module 'cv2.cv2' has no attribute 'face'

Created on 16 Feb 2019  ·  37Comments  ·  Source: opencv/opencv

  • OpenCV => : opencv-python==4.0.0.21
  • Operating System / Platform => :Mack
  • Compiler => jupyter notebook
Detailed description

when I execute it tells me
module 'cv2.cv2' has no attribute 'face'

Steps to reproduce

the error occurs when I use the following line
reconocimiento = cv2.face.createLBPHFaceRecognizer()

I've tried installing

pip3 install opencv-contrib-python

i put
pip3 freeze

appnope==0.1.0
backcall==0.1.0
decorator==4.3.0
ipykernel==4.8.2
ipython==6.5.0
ipython-genutils==0.2.0
jedi==0.12.1
jupyter-client==5.2.3
jupyter-core==4.4.0
nltk==3.4
numpy==1.15.4
opencv-contrib-python==4.0.0.21
opencv-python==4.0.0.21
pandas==0.23.4
parso==0.3.1
pexpect==4.6.0
pickleshare==0.7.4
Pillow==5.4.1
prompt-toolkit==1.0.15
ptyprocess==0.6.0
Pygments==2.2.0
python-dateutil==2.7.3
pytz==2018.7
pyzmq==17.1.0
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.11.0
tornado==5.1
traitlets==4.3.2
virtualenv==16.0.0
wcwidth==0.1.7

I've read some solutions and I've already tried

reconocimiento = cv2.face.LBPHFaceRecognizer_create() .
reconocimiento = cv2.face.createLBPHFaceRecognizer()
reconocimiento = cv2.face.createLBPHFaceRecognizer()

but it doesn't work. He tells me he hasn't found the attribute 'face' yet.

how to add the 'face' attribute?

image
image

contrib invalid question (invalid tracker)

Most helpful comment

write
pip install opencv-contrib-python --upgrade
if gives error then
write
pip install opencv-contrib-python --user
it will work fine for cv2.face.LBPHFaceRecognizer_create();

All 37 comments

Hey have you found the solution cause I ve same as you

No, I don't have the solution yet, but if you find it, please share it with me.

even i have the same problem. but try uninstalling it by

pip uninstall opencv_contrib_python
and install again
pip install opencv_contrib_python

Incluso tengo el mismo problema. pero intenta desinstalarlo por

pip desinstala opencv_contrib_python
e instala de nuevo
pip instala opencv_contrib_python

I tried, but the mistake persists.

recognizer=cv2.face.EigenFaceRecognizer_create()
try this

print(help(cv2.face))

those who got an error like this :

recognizer = cv2.face.LBPHFaceRecognizer_create()
AttributeError: module 'cv2.cv2' has no attribute 'face'

Solution :

1) print(dir (cv2.face)) //on python shell
2) recognizer = cv2.face.LBPHFaceRecognizer_create()

those who got an error like this :

recognizer = cv2.face.LBPHFaceRecognizer_create()
AttributeError: module 'cv2.cv2' has no attribute 'face'

Solution :

  1. print(dir (cv2.face)) //on python shell
  2. recognizer = cv2.face.LBPHFaceRecognizer_create()

nope that dosnt work

write
pip install opencv-contrib-python --upgrade
if gives error then
write
pip install opencv-contrib-python --user
it will work fine for cv2.face.LBPHFaceRecognizer_create();

  1. print(dir (cv2.face))

Find the exact name of the function from the directory and choose that

problem comes with the new versions of opencv. need a solution for that....

first uninstall opencv-python
-pip uninstall opencv-python
then install opencv-contrib-python
-pip install opencv-contrib-python

I have faced same problem 'cv2.cv2' has no attribute 'face'

Only installing below didn't solve the problem for me.
$pip install opencv-contrib-python

but when upgraded it solved the problem for me.
$pip install opencv-contrib-python --upgrade

nothing is working

try this it works for me
write
pip install opencv-contrib-python --user
it will work fine for cv2.face.LBPHFaceRecognizer_create()

try this it works for me
write
pip install opencv-contrib-python --user
it will work fine for cv2.face.LBPHFaceRecognizer_create()

thank you.its working

anyone with error even intalating opencv-contrib-python use VScode, was using pycharm when I switched to vscode worked.

PyCharm
pycharm

VSCode
vscode

Use dumping of cv.__file__ and sys.path for investigation of configuration problems (misconfigured build environments can't be fixed from OpenCV side).

anyone with error even intalating opencv-contrib-python use VScode, was using pycharm when I switched to vscode worked.
PyCharm

VSCode

I followed your steps it worked for me but I wanted to use PyCharm IDE only so I found the solution for this to work on PyCharm IDE. Install the package opencv-contrib-python in the same way as we install opencv package on Pycharm IDE. Go to Settings, click on the plus sign. Available packages dialog box will open and type opencv-contrib-python and click on install package.

I try the two kind of opencv-contrib-python, and two kind version can run successful.

Enviorment:
Windows 10 Pro
VSCode: 1.41.0
python: 3.6.6
opencv-contrib-python: 4.0.0.21、4.1.2.30

Command:
pip install --force-reinstall opencv-contrib-python==4.1.2.30
pip install --no-cache --force-reinstall opencv-contrib-python==4.0.0.21

try this it works for me
write
pip install opencv-contrib-python --user
it will work fine for cv2.face.LBPHFaceRecognizer_create()

thank you.its working

python -m pip install --user opencv-contrib-python
After doing this, if you are using OpenCV == 4.* then
Restart your system then use cv2.face.LBPHFaceRecognizer_create()

90% of the time this method should solve the problem.

hey guys found the solution pip install opencv-contrib-python==3.4.7.28 try like this we have to specifically say the version try lesser version mine was 4.x so I did and no error popped up

opencv_contrib-python is the C++ binding of opencv and opencv_contrib libs
opencv-python is the C++ binding of opencv lib

You must not install opencv-python if you want to use opencv_contrib-python

Read doc https://pypi.org/project/opencv-contrib-python/ :

Installation and Usage

If you have previous/other manually installed (= not installed via pip) version of OpenCV installed (e.g. cv2 module in the root of Python's site-packages), remove it before installation to avoid conflicts.

Thank You Sir

On Tue, 4 Feb 2020 at 13:49, LaurentBerger notifications@github.com wrote:

opencv_contrib-python is the C++ binding of opencv and opencv_contrib libs
opencv-python is the C++ binding of opencv lib

You must not install opencv-python if you want to use opencv_contrib-python

Read doc https://pypi.org/project/opencv-contrib-python/ :
Installation and Usage If you have previous/other manually installed (=
not installed via pip) version of OpenCV installed (e.g. cv2 module in the
root of Python's site-packages), remove it before installation to avoid
conflicts.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/opencv/opencv/issues/13848?email_source=notifications&email_token=ANAEPG5QBZWIDHFNH6SRQR3RBEQKFA5CNFSM4GX4CPWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKWXKBA#issuecomment-581793028,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ANAEPG65QM5CPA7Y5B3HXZ3RBEQKFANCNFSM4GX4CPWA
.

  • "python3 -m pip install opencv-contrib-python" installs the latest version of OpenCV on the pi which isn't compatible with Raspberry pi 3b

    • if you try installing OpenCV with any other command missing the "contrib" phrase, it will not include some important libraries, eg: Face.

For raspberry pi 3B try this:

  • try installing an older version by running this script on cmd line "sudo pip3 install opencv-contrib-python==3.4.6.27"

recognizer=cv2.face.EigenFaceRecognizer_create()
try this

The problem is cv2.cv2 has no attribute face, using EigenFaceRecognizer_create() does not provide a solution.

I try the two kind of opencv-contrib-python, and two kind version can run successful.

Enviorment:
Windows 10 Pro
VSCode: 1.41.0
python: 3.6.6
opencv-contrib-python: 4.0.0.21、4.1.2.30

Command:
pip install --force-reinstall opencv-contrib-python==4.1.2.30
pip install --no-cache --force-reinstall opencv-contrib-python==4.0.0.21

Thank you this solved my problem!

Ok so in case anyone run into the same problem:

I was using opencv 4.2 version on Mac, and it gives me

qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: cocoa, minimal, offscreen.

Installing back to version 4.1 solves this "platform" problem but it gives out the 'cv2.cv2' has no attribute 'face' as described in the issue. And simply pip installopencv-contrib-python does not sovle this problem. Have to use pip install --force-reinstall opencv-contrib-python==4.1.2.30 to solve it.

Thanks once again!

  1. print(dir (cv2.face))

Find the exact name of the function from the directory and choose that

foolish person

write
pip install opencv-contrib-python --upgrade
if gives error then
write
pip install opencv-contrib-python --user
it will work fine for cv2.face.LBPHFaceRecognizer_create();
this works perfectly for me:pip install opencv-contrib-python --user

write
pip install opencv-contrib-python --upgrade
if gives error then
write
pip install opencv-contrib-python --user
it will work fine for cv2.face.LBPHFaceRecognizer_create();
this works perfectly for me:pip install opencv-contrib-python --user
thanks a lot

try this it works for me
write
pip install opencv-contrib-python --user
it will work fine for cv2.face.LBPHFaceRecognizer_create()

thank you.its working

Perfect... This is the best answer. Worked well!!

anyone with error even intalating opencv-contrib-python use VScode, was using pycharm when I switched to vscode worked.

PyCharm
pycharm

VSCode
vscode

Your are using system library there.
That means you have perfect version of opencv in your system library.
If the code has to run in pycharm then do the following steps:
go to file | settings | project interpreter | then remove opencv-python (if installed already) | while installing opencv-python check the "specify version" box then install the lower version..
This should work because there is a bug in the current version of opencv...

You can solve this problem by deleting everything on your computer related to OPENCV,. If you are using pycharm go to settings -> Project Interpreter and delete all the opencv related packages. Then to pip install opencv-contrib-python.

This worked for me after 2 days of searching the web.

The opencv-contrib consists of contrib modules and face is one of them, but it will not work if you already have the main modules of opencv installed.

I have faced same problem 'cv2.cv2' has no attribute 'face'

Only installing below didn't solve the problem for me.
$pip install opencv-contrib-python

but when upgraded it solved the problem for me.
$pip install opencv-contrib-python --upgrade

This solved the problem. Thank you.

I try the two kind of opencv-contrib-python, and two kind version can run successful.

Enviorment:
Windows 10 Pro
VSCode: 1.41.0
python: 3.6.6
opencv-contrib-python: 4.0.0.21、4.1.2.30

Command:
pip install --force-reinstall opencv-contrib-python==4.1.2.30
pip install --no-cache --force-reinstall opencv-contrib-python==4.0.0.21
this worked for me ,thanks

try this it works for me
write
pip install opencv-contrib-python --user
it will work fine for cv2.face.LBPHFaceRecognizer_create()

thank you.its working

works for me also .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ekudritski picture ekudritski  ·  40Comments

Algomorph picture Algomorph  ·  56Comments

edelsohn picture edelsohn  ·  48Comments

PuchatekwSzortach picture PuchatekwSzortach  ·  59Comments

brian208579 picture brian208579  ·  41Comments