虚拟环境中的 Opencv3 和 Python 2.7 - AttributeError: 'module' 对象没有属性 'createLBPHFaceRecognizer'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33620527/
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
Opencv3 and Python 2.7 on Virtual Environment - AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'
提问by Gkan
I have a python function with opencv 3. it works without virtual environment.Also I installed opencv on venv from:pyimagesearch. i am trying to run that python function on venv, then it gives an error :
我有一个带有 opencv 3 的 python 函数。它在没有虚拟环境的情况下工作。此外,我在 venv 上安装了 opencv:pyimagesearch。我试图在 venv 上运行那个 python 函数,然后它给出了一个错误:
AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'
without venv in terminal:
在终端中没有 venv:
gkhan@Gkan ~/Masaüstü/face_recognizer $ python face_recognizer.py
Yol :./sinif/114.jpg.
114 Yuz Tanindi 12
with venv in terminal:
在终端中使用 venv:
gkhan@Gkan ~/Masaüstü/face_recognizer $ workon cv
(cv)gkhan@Gkan ~/Masaüstü/face_recognizer $ python face_recognizer.py
Traceback (most recent call last):
File "face_recognizer.py", line 15, in <module>
recognizer = cv2.createLBPHFaceRecognizer()
AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'
my python code:
我的python代码:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cv2, os
import numpy as np
from PIL import Image
# For Test
if 0==0:
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath)
recognizer = cv2.createLBPHFaceRecognizer()
...
I am running Opencv3 with python 2.7 on Linux Mint 64 Bit
我在 Linux Mint 64 位上使用 python 2.7 运行 Opencv3
采纳答案by Rick
From OpenCV 3, you have to get and build the opencv_contribrepo. Then you can use the submodule "face".
从 OpenCV 3 开始,您必须获取并构建opencv_contrib 存储库。然后你可以使用子模块“face”。
Help on module cv2.face in cv2:
cv2 中模块 cv2.face 的帮助:
NAME
cv2.face
FILE
(built-in)
FUNCTIONS
createEigenFaceRecognizer(...)
createEigenFaceRecognizer([, num_components[, threshold]]) -> retval
createFisherFaceRecognizer(...)
createFisherFaceRecognizer([, num_components[, threshold]]) -> retval
createLBPHFaceRecognizer(...)
createLBPHFaceRecognizer([, radius[, neighbors[, grid_x[, grid_y[, threshold]]]]]) -> retval
Voila~ You can now use cv2.face.createLBPHFaceRecognizer()
瞧~你现在可以使用 cv2.face.createLBPHFaceRecognizer()
回答by Chandan Purohit
The easiest way for me was to use anaconda package:
对我来说最简单的方法是使用 anaconda 包:
conda install -c menpo opencv3=3.1.0
Once installed, use cv2.face.createLBPHFaceRecognizer()
or other face recognizers. Hope this helps
安装后,使用cv2.face.createLBPHFaceRecognizer()
或其他人脸识别器。希望这可以帮助
回答by Explorer 24
For windows users using python 3, you can get the opencv_contrib from here. My system is 64 bit so opencv_python?3.3.0+contrib?cp36?cp36m?win_amd64.whlis what I used. If you are 32 bit then choose the 32 bit version.
对于使用 python 3 的 Windows 用户,您可以从这里获取 opencv_contrib 。我的系统是 64 位,所以opencv_python?3.3.0+contrib?cp36?cp36m?win_amd64.whl是我使用的。如果您是 32 位,则选择 32 位版本。
Open command prompt and navigate to the download folder and use the command
打开命令提示符并导航到下载文件夹并使用命令
pip install opencv_python-3.3.0+contrib-cp36-cp36m-win_amd64.whl
Note: Use a command similar to the file you just downloaded and make sure to uninstall an older version before installing the new one with the contrib. I had to run:
注意:使用类似于您刚刚下载的文件的命令,并确保在使用 contrib 安装新版本之前卸载旧版本。我不得不跑:
pip uninstall opencv_python-3.3.0-cp36-cp36m-win_amd64.whl
before making the new installation.
在进行新安装之前。
Then make sure it's successful
然后确保它成功
>>>import cv2
>>>cv2.face
<module 'cv2.face'>
Instead of createLBPHFaceRecognizer(), you must use LBPHFaceRecognizer_create()
您必须使用 LBPHFaceRecognizer_create() 而不是 createLBHFaceRecognizer()
回答by learnkevin
try this
尝试这个
run this command to install the contrib
运行此命令以安装 contrib
python -m pip install opencv-contrib-python
python -m pip install opencv-contrib-python
after this is done use this attribute
完成后使用此属性
recoginizer = cv2.face.LBPHFaceRecognizer_create()
回答by Sleider
for python versions as 3.6 uses:
对于 3.6 版本的 python 版本,使用:
rec = cv2.face.LBPHFaceRecognizer_create();
回答by Shubham Gupta
For Python version 3.6.x, do this:
对于 Python 3.6.x 版,请执行以下操作:
Open your terminal and install opencv-contrib-python
打开终端并安装 opencv-contrib-python
python -m pip install opencv-contrib-python
when you done with it use this
当你完成它使用这个
recoginizer = cv2.face.LBPHFaceRecognizer_create()
For More option you can do it like this way:
对于更多选项,您可以这样做:
print(help(cv2.face))