1
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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

i am using open cv2 so, all the code is according to 2.1.43 documentation. please comment if you need to see my github code
I was wrong. There is a weird thing that the method name is changed. I edited the answer. Hopefully it resolves your issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.