1
votes
import os
import cv2
import numpy as np
from PIL import Image

recognizer=cv2.createLBPHFaceRecognizer();
path='dataSet'

def getImagesWithID(path):
    imagePaths=[os.path.join(path,f) for f in os.listdir(path)]
    faces=[]
    IDs=[]
    for imagePath in imagePaths:
        faceImg=Image.open(imagePath).convert('L');
        faceNp=np.array(faceImg,'uint8')
        ID=int(os.path.split(imagePath)[-1].split('.')[1])
        faces.append(faceNp)
        print ID
        IDs.append(ID)
        cv2.imshow("training",faceNp)
        cv2.waitKey(10)
    return np.array(IDs), faces
Ids,faces=getImagesWithID(path)
recognizer.train(faces,Ids)
recognizer.save('recognizer/trainingData.yml')
cv2.destroyAllWindows()

Traceback (most recent call last):

File "C:\Users\Documents\basic\engine\trainer.py", line 6, in recognizer=cv2.createLBPHFaceRecognizer(); AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'

1

1 Answers

1
votes

As said here, you have to get and build the opencv_contrib repo. Then you can use the submodule "face".

Or install it using pip,

$ pip install opencv-contrib-python

Then you can use as recognizer=cv2.face.LBPHFaceRecognizer_create() as looks like they have changed the name of the method. If you are still having problems you can further investigate it using

import cv2
print (help(cv2.face))

Which reveals all the methods available. I have found the changed name this way.