我正在为我的学术项目开发人脸识别系统。我想将员工第一次被确认为他的首次上班时间,并将下一次被确认为雇员的时间记录为上一次上班时间,然后根据第一上班时间和上一次上班时间计算总上班时间。
我尝试使用以下代码,但仅获取当前系统时间作为开始时间。有人可以帮我解决我做错的事情吗。
代码:
data = pickle.loads(open(args [“ encodings”],“ rb”)。read())
vs = VideoStream(src = 0).start()
作家=无
time.sleep(2.0)
为True时
frame = vs.read()
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
rgb = imutils.resize(frame, width=750)
r = frame.shape[1] / float(rgb.shape[1])
boxes = face_recognition.face_locations(rgb)
encodings = face_recognition.face_encodings(rgb, boxes)
names = []
face_names = []
for encoding in encodings:
matches = face_recognition.compare_faces(data["encodings"],
encoding)
name = "Unknown"
if True in matches:
matchedIdxs = [i for (i, b) in enumerate(matches) if b]
counts = {}
for i in matchedIdxs:
name = data["names"][i]
counts[name] = counts.get(name, 0) + 1
name = max(counts, key=counts.get)
names.append(name)
if names != []:
for i in names:
first_active_time = datetime.now().strftime('%H:%M')
last_active_time = datetime.now().strftime('%H:%M')
difference = datetime.strptime(first_active_time, '%H:%M') - datetime.strptime(last_active_time, '%H:%M')
difference = difference.total_seconds()
total_hours = time.strftime("%H:%M", time.gmtime(difference))
face_names.append([i, first_active_time, last_active_time, total_hours])