Ask Your Question

Revision history [back]

recognizer = cv2.face.LBPHFaceRecognizer_create(); 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) 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/trainningData.yml')

hope this will help

click to hide/show revision 2
No.2 Revision

updated 2018-06-10 04:55:42 -0600

berak gravatar image

recognizer = cv2.face.LBPHFaceRecognizer_create(); 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)
        IDs.append(ID)
        cv2.imshow("training",faceNp)
        cv2.waitKey(10)
    return np.array(IDs), faces

faces

Ids, faces = getImagesWithID(path) recognizer.train(faces, Ids) recognizer.save('recognizer/trainningData.yml')

hope this will help

click to hide/show revision 3
No.3 Revision

updated 2018-06-10 04:56:26 -0600

berak gravatar image

recognizer = cv2.face.LBPHFaceRecognizer_create(); path="dataset"hope this will help:

recognizer = cv2.face.LBPHFaceRecognizer_create();
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)
        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/trainningData.yml')

hope this will help