问题
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 :
AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'
without venv in terminal:
gkhan@Gkan ~/Masaüstü/face_recognizer $ python face_recognizer.py
Yol :./sinif/114.jpg.
114 Yuz Tanindi 12
with venv in terminal:
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:
#!/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
回答1:
From OpenCV 3, you have to get and build the opencv_contrib repo. Then you can use the submodule "face".
Help on module cv2.face in cv2:
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()
回答2:
The easiest way for me was to use anaconda package:
conda install -c menpo opencv3=3.1.0
Once installed, use cv2.face.createLBPHFaceRecognizer()
or other face recognizers. Hope this helps
回答3:
try this
run this command to install the contrib
python -m pip install opencv-contrib-python
after this is done use this attribute
recoginizer = cv2.face.LBPHFaceRecognizer_create()
回答4:
for python versions as 3.6 uses:
rec = cv2.face.LBPHFaceRecognizer_create();
回答5:
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.whl is what I used. If you are 32 bit then choose the 32 bit version.
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:
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()
回答6:
For Python version 3.6.x, do this:
Open your terminal and install 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))
来源:https://stackoverflow.com/questions/33620527/opencv3-and-python-2-7-on-virtual-environment-attributeerror-module-object