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'

Sumsuddin Shojib
  • 3,583
  • 3
  • 26
  • 45
lambocrypt
  • 45
  • 7
  • Possible duplicate of [Opencv3 and Python 2.7 on Virtual Environment - AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'](https://stackoverflow.com/questions/33620527/opencv3-and-python-2-7-on-virtual-environment-attributeerror-module-object) – Jeru Luke Jul 27 '18 at 05:45

1 Answers1

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.

Sumsuddin Shojib
  • 3,583
  • 3
  • 26
  • 45
  • 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 – lambocrypt Jul 26 '18 at 16:37
  • I was wrong. There is a weird thing that the method name is changed. I edited the answer. Hopefully it resolves your issue – Sumsuddin Shojib Jul 26 '18 at 17:29