attributeerror: module 'cv2.face' has no a

2020-03-04 07:33发布

So i'm doing a little personal project but i keep getting this error when I try to create the recognizer. i have opencv-contrib and everything. Does anyone know whats going on? code posted below

import cv2, os
import numpy as np
from PIL import Image

cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath)

recognizer = cv2.face.createLBPHFaceRecognizer()

it gets caught on that last line. I've tried reinstalling all modules already. Not really sure what else to do. The weird thing is it works on my laptop but not my desktop. They both have the same modules, same python release and running the exact same code.

12条回答
疯言疯语
2楼-- · 2020-03-04 07:47

Had the same problem. Use:

recognizer = cv2.face.LBPHFaceRecognizer_create()

It worked for my program.

查看更多
男人必须洒脱
3楼-- · 2020-03-04 07:47

I fixed this issue with two commands:

First: sudo pip3 uninstall opencv-contrib-python

Second: sudo python3 -m pip install opencv-contrib-python==3.3.0.9

This fixed my issues. Hope it helps somebody! Also, if you are using python2, replace “pip3” with “pip” and “python3” with “python”

查看更多
闹够了就滚
4楼-- · 2020-03-04 07:53

Even I had this problem when I ran the code using Jupyter Notebook. If you are running it on Jupyter Notebook , then download it as pyhton(.py) file and try to run it in Anaconda Prompt or Command Prompt. This solved the problem for me. Thank You.

查看更多
疯言疯语
5楼-- · 2020-03-04 07:58

Under Windows 7, I was able to resolve the issue by simply uninstalling and re-installing opencv:

pip uninstall opencv-contrib-python
pip install opencv-contrib-python

The recogniser is called by:

recognizer = cv2.face.LBPHFaceRecognizer_create()
查看更多
等我变得足够好
6楼-- · 2020-03-04 07:58

I fixed this issue by installing: sudo pip install opencv-contrib-python.

Then look for correct format.

python2 is default

Basically the problem is that python3 and python2 have different format of code.

recognizer = cv2.face.LBPHFaceRecognizer_create()

This is the format of python2.

recognizer = cv2.face.createLBPHFaceRecognizer()

This is the format of python3

查看更多
看我几分像从前
7楼-- · 2020-03-04 08:01

open cmd , then --> pip install opencv-contrib-python

查看更多
登录 后发表回答