AttributeError: 'module' object has no attribute 'face' error even after installing opencv-contrib
AttributeError: 'module' object has no attribute 'face' error even after installing opencv-contrib
我正在尝试使用 Python、OpenCv2 和 LBPH 实现人脸识别
(从 HERE 下载)
我的python版本是2.7.14
PIP 版本为 9.0.3
OpenCV 版本为 3.4.0
我的代码是
import cv2
import numpy as np
import NameFind
# --- import the Haar cascades for face and eye ditection
face_cascade = cv2.CascadeClassifier('Haar/haarcascade_frontalcatface.xml')
eye_cascade = cv2.CascadeClassifier('Haar/haarcascade_eye.xml')
spec_cascade = cv2.CascadeClassifier('Haar/haarcascade_eye_tree_eyeglasses.xml')
help(cv2.face)
# FACE RECOGNISER OBJECT
LBPH = cv2.face.LBPHFaceRecognizer_create(2, 2, 7, 7, 20)
EIGEN = cv2.face.createEigenFaceRecognizer(10, 5000)
FISHER = cv2.face.createFisherFaceRecognizer(5, 500)
# Load the training data from the trainer to recognise the faces
LBPH.load("Recogniser/trainingDataLBPH.xml")
EIGEN.load("Recogniser/trainingDataEigan.xml")
FISHER.load("Recogniser/trainingDataFisher.xml")
# ------------------------------------ PHOTO INPUT -----------------------------------------------------
img = cv2.imread('Me4.jpg') # ------->>> THE ADDRESS TO THE PHOTO
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Convert the Camera to gray
faces = face_cascade.detectMultiScale(gray, 1.3, 4) # Detect the faces and store the positions
print(faces)
for (x, y, w, h) in faces: # Frames LOCATION X, Y WIDTH, HEIGHT
Face = cv2.resize((gray[y: y+h, x: x+w]), (110, 110)) # The Face is isolated and cropped
ID, conf = LBPH.predict(Face) # LBPH RECOGNITION
print ID
NAME = NameFind.ID2Name(ID, conf)
NameFind.DispID(x, y, w, h, NAME, gray)
ID, conf = EIGEN.predict(Face) # EIGEN FACE RECOGNITION
NAME = NameFind.ID2Name(ID, conf)
NameFind.DispID3(x, y, w, h, NAME, gray)
ID, conf = FISHER.predict(Face) # FISHER FACE RECOGNITION
NAME = NameFind.ID2Name(ID, conf)
NameFind.DispID2(x, y, w, h, NAME, gray)
cv2.imshow('LBPH Face Recognition System', gray) # IMAGE DISPLAY
cv2.waitKey(0)
cv2.destroyAllWindows()
当我 运行 任何人脸识别文件如 Recogniser_Image_All_Algorithms.py
时,我收到此错误
Traceback (most recent call last): File
"Recogniser_Image_All_Algorithms.py", line 11, in
LBPH = cv2.face.LBPHFaceRecognizer_create(2, 2, 7, 7, 20) AttributeError: 'module' object has no attribute 'face'
我用谷歌搜索了错误并找到了与 THIS ONE
相同的答案
检查完这些提要后,我尝试使用 python -m pip install opencv-contrib-python
安装 opencv-contrib
它说
Requirement already satisfied: opencv-contrib-python in
c:\users\rak\anaconda3\lib\site-packages Requirement already
satisfied: numpy>=1.11.3 in c:\users\rak\anaconda3\lib\site-packages
(from opencv-contrib-python)
但错误仍然存在,如何解决此错误。请帮忙
我自己找出问题!问题是我安装了 opencv-python,我 卸载了 opencv-python 和 运行 pip install opencv-contrib-python 它成功了。
Thanks for Downvoting the question for no reason even without telling me what I did wrong, without a comment or reply
我已经使用 sudo apt install python-opencv 为 python 安装了 opencv
& 收到错误 "AttributeError: 'module' object has no attribute 'face'"。
我的系统配置是 OS Ubuntu 16.04 LTS & Python 2.7.12。我使用以下命令来解决问题:
sudo apt remove python-opencv
并使用 pip 安装相同的库
sudo pip install opencv-contrib-python
现在 opencv 工作得非常好。
在我的Rpi
python 版本是 3.5 和 2.7。 opencv版本是3.3.0
将 python 平台从 2.7.x 更改为 3.5.x...
转到程序 /python idle/ properties,desktop entry / browse/ select idle-python3.5
在人脸识别模块中没有属性"face"。更改 python 平台后,此问题将得到解决。
recognizer = cv2.createLBPHFaceRecognizer()
试试这个
我正在尝试使用 Python、OpenCv2 和 LBPH 实现人脸识别 (从 HERE 下载)
我的python版本是2.7.14
PIP 版本为 9.0.3
OpenCV 版本为 3.4.0
我的代码是
import cv2
import numpy as np
import NameFind
# --- import the Haar cascades for face and eye ditection
face_cascade = cv2.CascadeClassifier('Haar/haarcascade_frontalcatface.xml')
eye_cascade = cv2.CascadeClassifier('Haar/haarcascade_eye.xml')
spec_cascade = cv2.CascadeClassifier('Haar/haarcascade_eye_tree_eyeglasses.xml')
help(cv2.face)
# FACE RECOGNISER OBJECT
LBPH = cv2.face.LBPHFaceRecognizer_create(2, 2, 7, 7, 20)
EIGEN = cv2.face.createEigenFaceRecognizer(10, 5000)
FISHER = cv2.face.createFisherFaceRecognizer(5, 500)
# Load the training data from the trainer to recognise the faces
LBPH.load("Recogniser/trainingDataLBPH.xml")
EIGEN.load("Recogniser/trainingDataEigan.xml")
FISHER.load("Recogniser/trainingDataFisher.xml")
# ------------------------------------ PHOTO INPUT -----------------------------------------------------
img = cv2.imread('Me4.jpg') # ------->>> THE ADDRESS TO THE PHOTO
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Convert the Camera to gray
faces = face_cascade.detectMultiScale(gray, 1.3, 4) # Detect the faces and store the positions
print(faces)
for (x, y, w, h) in faces: # Frames LOCATION X, Y WIDTH, HEIGHT
Face = cv2.resize((gray[y: y+h, x: x+w]), (110, 110)) # The Face is isolated and cropped
ID, conf = LBPH.predict(Face) # LBPH RECOGNITION
print ID
NAME = NameFind.ID2Name(ID, conf)
NameFind.DispID(x, y, w, h, NAME, gray)
ID, conf = EIGEN.predict(Face) # EIGEN FACE RECOGNITION
NAME = NameFind.ID2Name(ID, conf)
NameFind.DispID3(x, y, w, h, NAME, gray)
ID, conf = FISHER.predict(Face) # FISHER FACE RECOGNITION
NAME = NameFind.ID2Name(ID, conf)
NameFind.DispID2(x, y, w, h, NAME, gray)
cv2.imshow('LBPH Face Recognition System', gray) # IMAGE DISPLAY
cv2.waitKey(0)
cv2.destroyAllWindows()
当我 运行 任何人脸识别文件如 Recogniser_Image_All_Algorithms.py
时,我收到此错误Traceback (most recent call last): File "Recogniser_Image_All_Algorithms.py", line 11, in LBPH = cv2.face.LBPHFaceRecognizer_create(2, 2, 7, 7, 20) AttributeError: 'module' object has no attribute 'face'
我用谷歌搜索了错误并找到了与 THIS ONE
相同的答案检查完这些提要后,我尝试使用 python -m pip install opencv-contrib-python
安装 opencv-contrib它说
Requirement already satisfied: opencv-contrib-python in c:\users\rak\anaconda3\lib\site-packages Requirement already satisfied: numpy>=1.11.3 in c:\users\rak\anaconda3\lib\site-packages (from opencv-contrib-python)
但错误仍然存在,如何解决此错误。请帮忙
我自己找出问题!问题是我安装了 opencv-python,我 卸载了 opencv-python 和 运行 pip install opencv-contrib-python 它成功了。
Thanks for Downvoting the question for no reason even without telling me what I did wrong, without a comment or reply
我已经使用 sudo apt install python-opencv 为 python 安装了 opencv & 收到错误 "AttributeError: 'module' object has no attribute 'face'"。 我的系统配置是 OS Ubuntu 16.04 LTS & Python 2.7.12。我使用以下命令来解决问题: sudo apt remove python-opencv 并使用 pip 安装相同的库 sudo pip install opencv-contrib-python
现在 opencv 工作得非常好。
在我的Rpi python 版本是 3.5 和 2.7。 opencv版本是3.3.0 将 python 平台从 2.7.x 更改为 3.5.x... 转到程序 /python idle/ properties,desktop entry / browse/ select idle-python3.5 在人脸识别模块中没有属性"face"。更改 python 平台后,此问题将得到解决。
recognizer = cv2.createLBPHFaceRecognizer()
试试这个