编程语言
首页 > 编程语言> > python – AttributeError:即使在安装opencv-contrib之后,’module’对象也没有属性’face’错误

python – AttributeError:即使在安装opencv-contrib之后,’module’对象也没有属性’face’错误

作者:互联网

我试图使用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一样的答案

在检查这些feed之后,我尝试使用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)

但错误仍然相同,如何解决此错误.请帮助

解决方法:

我使用sudo apt install python-opencv为python安装了opencv
&安培;收到错误“AttributeError:’module’对象没有属性’face’”.
我的系统配置是OS Ubuntu 16.04 LTS& Python 2.7.12.我使用以下命令来解决此问题:
sudo apt删除python-opencv
并使用pip安装了相同的库
sudo pip install opencv-contrib-python

现在opencv工作得非常好.

标签:python,python-2-7,opencv,face-detection,lbph-algorithm
来源: https://codeday.me/bug/20190527/1162239.html