首页 > 解决方案 > 基于人脸识别的考勤系统

问题描述

我正在尝试创建一个基于人脸识别的考勤系统,但出现以下错误。如果有人可以提供帮助,我将不胜感激。这是代码

import os,cv2
import numpy as np
from PIL import Image
recognizer = cv2.face_LBPHFaceRecognizer.create()

def getImagesAndLabels(path):
    #get the path of all the files in the folder
    imagePaths=[os.path.join(path,f) for f in os.listdir(path)]
    #create empth face list
    faceSamples=[]
    #create empty ID list
    Ids=[]
    #now looping through all the image paths and loading the Ids and the images
    for imagePath in imagePaths:
        #loading the image and converting it to gray scale
        pilImage=Image.open(path).convert('L')
        #Now we are converting the PIL image into numpy array
        imageNp=np.array(pilImage,'uint8')
        #getting the Id from the image
        Id=int(os.path.split(imagePath)[-1].split(".")[1])
        # extract the face from the training image sample
        faces=detector.detectMultiScale(imageNp)
        #If a face is there then append that in the list as well as Id of it
        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')
s = recognizer.train(faces, np.array(Ids))
print("Successfully trained")
recognizer.write('trainingData.yml')
[evaluate training_dataSet.py]
Traceback (most recent call last):
  File "c:/Users/ADMIN/PycharmProjects/Face-Recognition-Attendance-System/attendance/training_dataSet.py", line 30, in <module>
    s = recognizer.train(faces, np.array(Ids))
cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-i1s8y2i1\opencv_contrib\modules\face\src\lbph_faces.cpp:362: error: (-210:Unsupported format or combination of formats) Empty training data was given. You'll need more than one sample to learn a model. in function 'cv::face::LBPH::train'

标签: pythonnumpypython-imaging-libraryface-recognitionopencv-python

解决方案


推荐阅读