Spaces:
Runtime error
Runtime error
File size: 1,590 Bytes
17752cd a5157c8 c8b64d4 17752cd e0d124e 17752cd e0d124e 17752cd 16864bf 17752cd fd646d5 17752cd e0d124e 7a14c90 2b7111d 7a14c90 e0d124e 326b6ca e0d124e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# face attendance using streamlit
import streamlit as st
import cv2
from deepface import DeepFace
import threading
from streamlit_webrtc import webrtc_streamer
import av
import datetime
import pymongo
import time
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["camera"]
mycol = mydb["attendance"]
person1 = cv2.imread('./bill.jpeg')
person2 = cv2.imread('./elon.jpeg')
attendant = set()
face_match = False
def recogniser(name):
if name not in attendant:
print(name)
attendant.add(name)
add = {
"name": name,
"time": datetime.datetime.now().ctime()
}
mycol.insert_one(add)
def check_face(frame):
global face_match
try:
if DeepFace.verify(frame, person1)['verified']:
face_match = True
recogniser('bill')
elif DeepFace.verify(frame, person2)['verified']:
face_match = True
recogniser('elon')
else:
face_match = False
except ValueError:
face_match = False
def call(frame):
if frame:
img = frame.to_ndarray(format='bgr24')
check_face(img)
if face_match:
cv2.putText(img, 'Match !', (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0), 3)
else:
cv2.putText(img, 'No Match !', (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 3)
return av.VideoFrame.from_ndarray(img, format="bgr24")
else:
st.write('not working ')
webrtc_streamer(key='example', video_frame_callback=call) |