Spaces:
Sleeping
Sleeping
KIRANKALLA
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import face_recognition
|
3 |
+
import cv2
|
4 |
+
import numpy as np
|
5 |
+
import pickle
|
6 |
+
from PIL import Image
|
7 |
+
import pandas as pd
|
8 |
+
|
9 |
+
pickle1 = open('rce_face_encodings.pkl','rb')
|
10 |
+
rce_face_encodings = pickle.load(pickle1)
|
11 |
+
pickle2 = open('rce_face_names.pkl','rb')
|
12 |
+
rce_face_names = pickle.load(pickle2)
|
13 |
+
pickle1.close()
|
14 |
+
pickle2.close()
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
face_locations = []
|
19 |
+
face_names=[]
|
20 |
+
|
21 |
+
|
22 |
+
st.header('RCEE :: FACE RECOGNTION')
|
23 |
+
st.title('AI&DS')
|
24 |
+
|
25 |
+
image = st.file_uploader('Pick any Image')
|
26 |
+
if image:
|
27 |
+
st.image(image)
|
28 |
+
image = Image.open(image)
|
29 |
+
image = np.array(image)
|
30 |
+
face_locations = face_recognition.face_locations(image)
|
31 |
+
face_encodings = face_recognition.face_encodings(image,face_locations)
|
32 |
+
|
33 |
+
|
34 |
+
for face_encoding in face_encodings:
|
35 |
+
matches = face_recognition.compare_faces(rce_face_encodings, face_encoding)
|
36 |
+
name = "Unknown"
|
37 |
+
face_distances = face_recognition.face_distance(rce_face_encodings, face_encoding)
|
38 |
+
best_match_index = np.argmin(face_distances)
|
39 |
+
if matches[best_match_index]:
|
40 |
+
name = rce_face_names[best_match_index]
|
41 |
+
face_names.append(name)
|
42 |
+
for (top, right, bottom, left), name in zip(face_locations, face_names):
|
43 |
+
cv2.rectangle(image, (left, top), (right, bottom), (0, 0, 255), 2)
|
44 |
+
cv2.rectangle(image, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
|
45 |
+
font = cv2.FONT_HERSHEY_DUPLEX
|
46 |
+
cv2.putText(image, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
|
47 |
+
|
48 |
+
|
49 |
+
image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
|
50 |
+
cv2.imshow('Face Recognition', image)
|
51 |
+
df = pd.DataFrame({'Student_Name':face_names})
|
52 |
+
st.dataframe(df)
|
53 |
+
cv2.waitKey(0)
|
54 |
+
cv2.destroyAllWindows()
|