简体   繁体   English

无法生成 csv 文件或考勤系统

[英]unable to generate csv file or attendance system

i'm trying to make an attendance system so i check every code i find online and try to run it to see which one works and not so i can make it as my guide.我正在尝试制作一个考勤系统,因此我检查了我在网上找到的每个代码并尝试运行它以查看哪个有效,而不是这样我就可以将其作为我的指南。 Below is the code i am trying to run:下面是我试图运行的代码:

import datetime
import os
import time

import cv2
import pandas as pd


#-------------------------
def recognize_attendence():
    recognizer = cv2.face.LBPHFaceRecognizer_create()  # cv2.createLBPHFaceRecognizer()
    recognizer.read("TrainingImageLabel/Trainner.yml")
    harcascadePath = "haarcascade_frontalface_default.xml"
    faceCascade = cv2.CascadeClassifier(harcascadePath)
    df = pd.read_csv("StudentDetails/StudentDetails.csv")
    cam = cv2.VideoCapture(0)
    font = cv2.FONT_HERSHEY_SIMPLEX
    col_names = ['Id', 'Name', 'Date', 'Time']
    attendance = pd.DataFrame(columns=col_names)

    while True:
        ret, im = cam.read()
        gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
        faces = faceCascade.detectMultiScale(gray, 1.2, 5)
        for(x, y, w, h) in faces:
            cv2.rectangle(im, (x, y), (x+w, y+h), (225, 0, 0), 2)
            Id, conf = recognizer.predict(gray[y:y+h, x:x+w])

            if(conf < 100):
                ts = time.time()
                date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
                timeStamp = datetime.datetime.fromtimestamp(
                    ts).strftime('%H:%M:%S')
                aa = df.loc[df['Id'] == Id]['Name'].values
                tt = str(Id)+"-"+aa
                attendance.loc[len(attendance)] = [Id, aa, date, timeStamp]

            else:
                Id = 'Unknown'
                tt = str(Id)
            if(conf > 1):
                noOfFile = len(os.listdir("unknown"))+1
                cv2.imwrite("unknown/Image"+str(noOfFile) +
                            ".jpg", im[y:y+h, x:x+w])
            cv2.putText(im, str(tt), (x, y+h), font, 1, (255, 255, 255), 2)
        attendance = attendance.drop_duplicates(subset=['Id'], keep='first')
        cv2.imshow('im', im)
        if (cv2.waitKey(1) == ord('q')):
            break
    ts = time.time()
    date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
    timeStamp = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S')
    Hour, Minute, Second = timeStamp.split(":")
    fileName = "Attendance/Attendance_"+date+"_"+Hour+"-"+Minute+"-"+Second+".csv"
    attendance.to_csv(fileName, index=True)
    cam.release()
    cv2.destroyAllWindows()

    print("Attendance Successfull")

basically it will serve as the recognizer of the said system.基本上它将作为所述系统的识别器。 The camera will load to gather face data and then it will check the trained data who is in the gathered data and then after it will generate the result on a csv file which include the name, and id of the recognized data.相机将加载以收集面部数据,然后它将检查收集数据中的训练数据,然后在 csv 文件中生成结果,其中包括识别数据的名称和 ID。 The camera works and it also displays the name and the id of the who is in front of the camera but is unable to generate a csv file.摄像头工作,它还显示在摄像头前面的人的姓名和 ID,但无法生成 csv 文件。 I'm pretty much new to this and i've been practicing so sorry if you find my question basic.我对此很陌生,如果您发现我的问题基本,我一直在练习,非常抱歉。

Try to use a debugger and check if your file path and data are correct.尝试使用调试器并检查您的文件路径和数据是否正确。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM