Python 属性错误:模块“cv2.face”没有属性“createlbphfacerecognizer”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45655699/
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
attributeerror: module 'cv2.face' has no attribute 'createlbphfacerecognizer'
提问by Zack Shadid
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
所以我正在做一个小小的个人项目,但是当我尝试创建识别器时,我不断收到这个错误。我有 opencv-contrib 和所有东西。有谁知道这是怎么回事?代码贴在下面
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.
它在最后一行被捕获。我已经尝试重新安装所有模块。不太确定还能做什么。奇怪的是它适用于我的笔记本电脑但不适用于我的台式机。它们都具有相同的模块、相同的 Python 版本并运行完全相同的代码。
回答by Peter
Had the same problem. Use:
有同样的问题。用:
recognizer = cv2.face.LBPHFaceRecognizer_create()
It worked for my program.
它适用于我的程序。
回答by Peter
Under Windows 7, I was able to resolve the issue by simply uninstalling and re-installing opencv:
在 Windows 7 下,我只需卸载并重新安装 opencv 即可解决该问题:
pip uninstall opencv-contrib-python
pip install opencv-contrib-python
The recogniser is called by:
识别器被调用:
recognizer = cv2.face.LBPHFaceRecognizer_create()
回答by Simbarashe Timothy Motsi
There are some missing modules for contributed libraries in the default pip install opencv-python
so you need pip install opencv-contrib-python
默认情况下,贡献的库缺少一些模块,pip install opencv-python
因此您需要pip install opencv-contrib-python
回答by tawfik mourchid
Try to update your opencv by "python -m pip install opencv-contrib-python" ps: you have to delete the CV2 repository from the Python rep and then run this command (in the CMD windows) if it doesn't work
尝试通过“python -m pip install opencv-contrib-python”更新你的opencv ps:如果它不起作用,你必须从Python代表中删除CV2存储库,然后运行这个命令(在CMD窗口中)
回答by Sebastian
Try to use this:
尝试使用这个:
import cv2
import os
import numpy as np
from PIL import Image
# Path for face image database
path = 'dataset'
recognizer = cv2.face_LBPHFaceRecognizer.create()
detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
回答by WannaB_robot
I had this problem running opencv Version 3.4.1. Here is what I did.
我在运行 opencv 3.4.1 版时遇到了这个问题。这是我所做的。
SPECS: Raspberry pi 3B, OS: Raspbian, Version: 9 (Stretch), Python 3, opencv Version 3.4.1
规格:Raspberry pi 3B,操作系统:Raspbian,版本:9(Stretch),Python 3,opencv 版本 3.4.1
Check opencv version in python
import cv2
cv2.__version__
在python中检查opencv版本
import cv2
cv2.__version__
1) sudo pip install opencv-contrib-python
1) sudo pip install opencv-contrib-python
*After this I could not import cv2 in python until I installed the following.
*在此之后,我无法在 python 中导入 cv2,直到我安装了以下内容。
2) sudo apt-get update
2) sudo apt-get update
3) sudo apt-get install libhdf5-dev
3) sudo apt-get install libhdf5-dev
4) sudo apt-get update
4) sudo apt-get update
5) sudo apt-get install libhdf5-serial-dev libqtgui4 libqt4-test
5) sudo apt-get install libhdf5-serial-dev libqtgui4 libqt4-test
回答by Chandan Gupta
I fixed this issue with two commands:
我用两个命令解决了这个问题:
First: sudo pip3 uninstall opencv-contrib-python
第一的: sudo pip3 uninstall opencv-contrib-python
Second: sudo python3 -m pip install opencv-contrib-python==3.3.0.9
第二: 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”
这解决了我的问题。希望它可以帮助某人!此外,如果您使用的是 python2,请将“pip3”替换为“pip”,将“python3”替换为“python”
回答by Yuresh Karunanayake
open cmd , then --> pip install opencv-contrib-python
打开 cmd ,然后 --> pip install opencv-contrib-python
回答by Aquib
You are using Opencv 3.x, in the new version few modules has been removed. You have two options: 1. Add opencv_contrib module to your existing opencv 3.x version. Here's the link https://github.com/opencv/opencv_contrib2.you can use older versions of Opencv. Like opencv 2.4.x
您使用的是 Opencv 3.x,在新版本中删除了几个模块。您有两个选择: 1. 将 opencv_contrib 模块添加到您现有的 opencv 3.x 版本。这是链接https://github.com/opencv/opencv_contrib2.您可以使用旧版本的 Opencv。像opencv 2.4.x
回答by Closed Eagle
I fixed this issue by installing:
sudo pip install opencv-contrib-python
.
我通过安装解决了这个问题:
sudo pip install opencv-contrib-python
.
Then look for correct format.
然后寻找正确的格式。
python2 is default
python2是默认值
Basically the problem is that python3 and python2 have different format of code.
基本上问题在于 python3 和 python2 具有不同的代码格式。
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer = cv2.face.LBPHFaceRecognizer_create()
This is the format of python2.
这是python2的格式。
recognizer = cv2.face.createLBPHFaceRecognizer()
recognizer = cv2.face.createLBPHFaceRecognizer()
This is the format of python3
这是python3的格式