Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,72 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import cv2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
st.set_page_config(page_title="Streamlit WebCam App")
|
6 |
-
st.title("Webcam Display Steamlit App")
|
7 |
-
st.caption("Powered by OpenCV, Streamlit")
|
8 |
-
cap = cv2.VideoCapture(0)
|
9 |
-
frame_placeholder = st.empty()
|
10 |
-
stop_button_pressed = st.button("Stop")
|
11 |
-
while cap.isOpened() and not stop_button_pressed:
|
12 |
-
ret, frame = cap.read()
|
13 |
-
if not ret:
|
14 |
-
st.write("Video Capture Ended")
|
15 |
-
break
|
16 |
-
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
17 |
-
frame_placeholder.image(frame,channels="RGB")
|
18 |
-
if cv2.waitKey(1) & 0xFF == ord("q") or stop_button_pressed:
|
19 |
-
break
|
20 |
-
cap.release()
|
21 |
-
cv2.destroyAllWindows()
|
22 |
-
|
23 |
-
if __name__ == "__main__":
|
24 |
-
main()
|
|
|
1 |
+
# face attendance using streamlit
|
2 |
+
|
3 |
import streamlit as st
|
4 |
import cv2
|
5 |
+
from deepface import DeepFace
|
6 |
+
import threading
|
7 |
+
import datetime
|
8 |
+
import pymongo
|
9 |
+
|
10 |
+
camera = cv2.VideoCapture(0)
|
11 |
+
window = st.image([])
|
12 |
+
|
13 |
+
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
|
14 |
+
mydb = myclient["camera"]
|
15 |
+
mycol = mydb["attendance"]
|
16 |
+
|
17 |
+
run = st.checkbox('Run')
|
18 |
+
|
19 |
+
person1 = cv2.imread('./bill.jpeg')
|
20 |
+
person2 = cv2.imread('./elon.jpeg')
|
21 |
+
attendant = set()
|
22 |
+
|
23 |
+
face_match = False
|
24 |
+
|
25 |
+
def recogniser(name):
|
26 |
+
if name not in attendant:
|
27 |
+
print(name)
|
28 |
+
attendant.add(name)
|
29 |
+
add = {
|
30 |
+
"name": name,
|
31 |
+
"time": datetime.datetime.now().ctime()
|
32 |
+
}
|
33 |
+
mycol.insert_one(add)
|
34 |
+
|
35 |
+
def check_face(frame):
|
36 |
+
global face_match
|
37 |
+
try:
|
38 |
+
if DeepFace.verify(frame, person1)['verified']:
|
39 |
+
face_match = True
|
40 |
+
recogniser('bill')
|
41 |
+
|
42 |
+
elif DeepFace.verify(frame, person2)['verified']:
|
43 |
+
face_match = True
|
44 |
+
recogniser('elon')
|
45 |
+
else:
|
46 |
+
face_match = False
|
47 |
+
|
48 |
+
except ValueError:
|
49 |
+
face_match = False
|
50 |
+
|
51 |
+
|
52 |
+
counter = 0
|
53 |
+
|
54 |
+
while run:
|
55 |
+
success, frame = camera.read()
|
56 |
+
img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
57 |
+
|
58 |
+
if success:
|
59 |
+
if counter % 30 == 0:
|
60 |
+
try:
|
61 |
+
threading.Thread(target=check_face, args=(img.copy(),)).start()
|
62 |
+
except ValueError:
|
63 |
+
pass
|
64 |
+
counter += 1
|
65 |
+
|
66 |
+
if face_match:
|
67 |
+
cv2.putText(img, 'Match !', (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0), 3)
|
68 |
+
|
69 |
+
else:
|
70 |
+
cv2.putText(img, 'No Match !', (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 3)
|
71 |
|
72 |
+
window.image(img)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|