python - 基于人脸识别的考勤系统
问题描述
我正在尝试创建一个基于人脸识别的考勤系统,但出现以下错误。如果有人可以提供帮助,我将不胜感激。这是代码
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'
解决方案
推荐阅读
- python - sklearn KFold 的类型提示
- node.js - 不同页面中的 Node JS Express app.get() 脚本
- spring-boot - 请参阅已解决的多配置文件 Spring Boot 配置
- javascript - 风格不因班级而异
- javascript - 内联 JavaScript 以分隔 JavaScript 文件
- python-3.x - 在python中对音频剪辑进行阈值过滤后无法播放音频
- json - SIM808,未收到来自 openweathermap 的完整 json 字符串
- django-rest-framework - Django REST - PUT 和 PATCH 创建新对象而不是更新
- javascript - 如何统计所有使用 v13 的在线会员?
- python - 赋值表达式的求值顺序(海象运算符)