简体   繁体   English

我正在开发一个面部识别和考勤系统,该系统将姓名和时间写入 CSV 文件,但同一个人被多次记录

[英]I am working on a facial recognition and attendance system which writes the name and time in a CSV file, but the same person is logged multiple times

I am working on a facial recognition and attendance system which writes the name and time in a CSV file.In order to avoid logging the same person for multiple 'in' times i am writtng a logic which checks if the name is present in the attendance log already,if not then the attendance is looged.But the same name is logged over and over inspite of it being already logged once,i am unable to understand the problem.我正在开发一个面部识别和考勤系统,该系统将姓名和时间写入 CSV 文件。为了避免多次“进入”时间记录同一个人,我正在编写一个逻辑来检查姓名是否出现在考勤中已经记录了,如果没有,则记录了出勤率。但是,尽管已经记录了一次,但同名的却一遍又一遍地登录,我无法理解问题所在。

this is the code snippet:这是代码片段:

Draw a label with a name below the face画一个label,脸下面有名字

    cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
    font = cv2.FONT_HERSHEY_DUPLEX
    cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
    #markAttendance(name)
    with open('ATTLOG.csv', "r+") as g:
        myDatalist = g.readlines()
        nameList=[]
        for line in myDatalist:
            entry = line.split(',')
            nameList.append(entry[0])
            if name not in nameList:
                now=datetime.now()
                dtString = now.strftime('%H:%M:%S')
                g.writelines(f'\n{name},{dtString}')

You have a logic bug: you read the whole file into nameList , then you check if the current name is in the first item of nameList .您有一个逻辑错误:您将整个文件读入nameList ,然后检查当前名称是否在nameList第一项中。 If not you write it into the file: If your current name comes later in nameList , you will write it although you should not.如果不是,则将其写入文件:如果您的当前名称稍后出现在nameList中,您将写入它,尽管您不应该这样做。

You need to read the whole file, then check if it is anywhere in your nameList and then decide if you write or not.您需要阅读整个文件,然后检查它是否在您的nameList中的任何位置,然后决定是否写入。

For checking you should use a set() - checking for "is in" is way faster then with a list.对于检查,您应该使用set() - 检查“在”中比使用列表要快得多。

already_in_file = set()
with open('ATTLOG.csv', "r") as g:       # just read
    for line in g:
        already_in_file.add(line.split(",")[0])

# process your current entry:
if name not in already_in_file:
    with open('ATTLOG.csv', "a") as g:   # append
        now = datetime.now()
        dtString = now.strftime('%H:%M:%S')
        g.writelines(f'\n{name},{dtString}')

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

相关问题 我正在使用 pyqt5 制作人脸考勤系统,即使该人已登录,该系统也会多次写入考勤 - i'm making face attendance system using pyqt5 that writes attendance multiple times even when the person is logged in 在python中使用多个摄像头进行面部识别时,有没有办法确定哪个摄像头在直播stream中识别出一个人 - Is there a way to determine which camera has recognized a person in live stream when using multiple cameras for facial recognition in python 使用 Twilio 通过 SMS 进行面部识别考勤 - Facial Recognition Attendance with SMS using Twilio 我的人脸识别考勤打分系统退出按钮不能用 - In my face recognition attendance marking system exit button cannot working 无法生成 csv 文件或考勤系统 - unable to generate csv file or attendance system 如何在 csv 文件中删除多行同一个人 id - How to remove multiple rows of the same person id in csv file 当我写入CSV文件时,它只会第二次写入 - When I write into CSV file, it writes only the second time sqlite同时多次写入 - sqlite multiple writes at same time 如何计算人脸识别系统的准确率? - How to calculate accuracy for facial recognition system? 当我导入正在打印的同一个文件时,为什么 Python 会打印我的输出两次? - Why Python print my output two times when I import the same file in which I am printing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM