Python AttributeError: 模块“cv2.cv2”没有属性“createLBHFaceRecognizer”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44633378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:16:47  来源:igfitidea点击:

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

pythonwindowsopencv

提问by Manjurul Ahsan

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.

我正在使用 Windows 平台。python 3.6 版本。提前致谢。

回答by ?eljko Krnji?

You need to install opencv-contrib

你需要安装 opencv-contrib

pip install opencv-contrib-python

It should work after that.

在那之后它应该工作。

回答by Priyansh gupta

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

如果您使用的是 python3.x 和 opencv==4.1.0 然后使用以下命令首先

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

after that use this in the python script

之后在python脚本中使用它

cv2.face.LBPHFaceRecognizer_create() 

回答by prateek parab

Use the following

使用以下

recognizer = **cv2.face.LBPHFaceRecognizer_create()**

After you install:

安装后:

pip install opencv-contrib-python

If using anaconda then in anaconda prompt:

如果使用 anaconda,则在 anaconda 提示符下:

conda install pip

then

然后

pip install opencv-contrib-python

回答by Raj Krishnan R

You might be running Python3 and therefore you are supposed to use pip3 to install the opencv-contrib package :

您可能正在运行 Python3,因此您应该使用 pip3 来安装 opencv-contrib 包:

pip3 install opencv-contrib-python

This worked for me.

这对我有用。

回答by Arpit Solanki

opencv has changed some functions and moved them to their opencv_contribrepo so you have to call the mentioned method with:

opencv 更改了一些函数并将它们移到他们的opencv_contrib 存储库中,因此您必须使用以下方法调用提到的方法:

recognizer = cv2.face.createLBPHFaceRecognizer()

Note: You can see this issueabout missing docs. Try using help function help(cv2.face.createLBPHFaceRecognizer)for more details.

注意:您可以查看有关缺少文档的问题。尝试使用帮助功能help(cv2.face.createLBPHFaceRecognizer)了解更多详情。

回答by skyCode

For me changing createLBPHFaceRecognizer() to

对我来说,将 createLBHFaceRecognizer() 更改为

recognizer = cv2.face.LBPHFaceRecognizer_create()

fixed the problem

解决了问题

回答by Hasan A Yousef

I got openCV installed smoothly in my mac by:

我通过以下方式在我的 mac 中顺利安装了 openCV:

$ brew install opencv
$ brew link --overwrite --dry-run opencv // to force linking
$ pip3 install opencv-contrib-python

I got it at windows 10 using:

我在 Windows 10 上使用:

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()

回答by Cloud Cho

For me, I had to have OpenCV (3.4.2), Py-OpenCV (3.4.2), LibOpenCV (3.4.2).

对我来说,我必须有 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.

我的 Python 是 3.5.6 版,在 Windows OS 10 中使用 Anaconda。

回答by Andrea Cassigoli

I had a similar problem:

我有一个类似的问题:

module cv2 has no attribute "cv2.TrackerCSRT_create"

模块 cv2 没有属性“cv2.TrackerCSRT_create”

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

我的python版本是windows 10下的3.8.0,问题是opencv版本安装的。

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

所以我以这种方式修复(具有管理员权限的 cmd 提示):

  1. Uninstalled opencv-python: pip uninstall opencv-python
  2. Installed onlyopencv-contrib-python: pip install opencv-contrib-python
  1. 卸载opencv-python: pip uninstall opencv-python
  2. 安装opencv-contrib-python:pip install opencv-contrib-python

Anyway you can read the following guide:

无论如何,您可以阅读以下指南:

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

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

回答by snehit vaddi

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

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

执行此操作后,只需重新启动系统,然后如果您使用的是 Opencv >= 4.* ,请使用:
recognizer = cv2.face.LBPHFaceRecognizer_create()

This should solve 90% of the problem.

这应该可以解决 90% 的问题。