import os
import cv2
import numpy as np
from PIL import Image
recognizer = cv2.face.LBPHFaceRecognizer_create()
detector= cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
def getImagesAndLabels(path):
imagePaths=[os.path.join(path,f) for f in os.listdir(path)]
faceSamples=[]
Ids=[]
for imagePath in imagePaths:
pilImage=Image.open(imagePath).convert('L')
imageNp=np.array(pilImage,'uint8')
Id=int(os.path.split(imagePath)[-1].split(".")[1])
faces=detector.detectMultiScale(imageNp)
for (x,y,w,h) in faces:
faceSamples.append(imageNp[y:y+h,x:x+w])
Ids.append(Id)
return faceSamples,Ids
faces,Ids = getImagesAndLabels('dataSet')
recognizer.train(faces, np.array(Ids))
recognizer.save('trainner/trainner.yml')
当我运行上面的代码时,它抛出一个错误,指出这一点
模块实例没有LBHPFaceRecognizer_create()成员
如何解决此错误?
答案 0 :(得分:0)
尝试安装opencv-contrib-python软件包,
0 13.30
1 9.40
2 24.09
3 24.41
4 35.73
编辑1:
您使用的是旧版软件包,如果是,则模块名称已更改,https://github.com/opencv/opencv/issues/7187
您可以快速查看pip install opencv-contrib-python
软件包中可用的模块。
cv2.face