Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,65 +1,66 @@
|
|
1 |
-
import os
|
2 |
-
import warnings
|
3 |
-
|
4 |
-
os.environ['TF_ENABLE_ONEDNN_OPTS']=str(0)
|
5 |
-
warnings.filterwarnings('ignore')
|
6 |
-
|
7 |
-
#import pandas as pd
|
8 |
-
import numpy as np
|
9 |
-
|
10 |
-
from deepface import DeepFace
|
11 |
-
from db import create_db, get_student_row
|
12 |
-
from helper_fns import binary_to_pil, extract_faces
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
def verify_student(db_path, last_name, matric_no, input_image):
|
18 |
-
data = get_student_row(db_path, last_name, matric_no)
|
19 |
-
|
20 |
-
if data is not None:
|
21 |
-
binary_image = data['image']
|
22 |
-
else:
|
23 |
-
raise ValueError('No student having last name {last_name} and matric no: {matric_no} exists in this database.')
|
24 |
-
actual_image =np.array(binary_to_pil(binary_image))
|
25 |
-
|
26 |
-
webcam_image = input_image
|
27 |
-
if webcam_image is None:
|
28 |
-
raise ValueError(f'No image')
|
29 |
-
else:
|
30 |
-
print('Received image')
|
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 |
main()
|
|
|
1 |
+
import os
|
2 |
+
import warnings
|
3 |
+
|
4 |
+
os.environ['TF_ENABLE_ONEDNN_OPTS']=str(0)
|
5 |
+
warnings.filterwarnings('ignore')
|
6 |
+
|
7 |
+
#import pandas as pd
|
8 |
+
import numpy as np
|
9 |
+
|
10 |
+
from deepface import DeepFace
|
11 |
+
from db import create_db, get_student_row
|
12 |
+
from helper_fns import binary_to_pil, extract_faces
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
def verify_student(db_path, last_name, matric_no, input_image):
|
18 |
+
data = get_student_row(db_path, last_name, matric_no)
|
19 |
+
|
20 |
+
if data is not None:
|
21 |
+
binary_image = data['image']
|
22 |
+
else:
|
23 |
+
raise ValueError('No student having last name {last_name} and matric no: {matric_no} exists in this database.')
|
24 |
+
actual_image =np.array(binary_to_pil(binary_image))
|
25 |
+
|
26 |
+
webcam_image = input_image
|
27 |
+
if webcam_image is None:
|
28 |
+
raise ValueError(f'No image')
|
29 |
+
else:
|
30 |
+
print('Received image')
|
31 |
+
print(type(webcam_image))
|
32 |
+
results = DeepFace.verify(webcam_image,
|
33 |
+
actual_image,
|
34 |
+
model_name='Facenet',
|
35 |
+
detector_backend="retinaface",
|
36 |
+
distance_metric="cosine",
|
37 |
+
enforce_detection=True,
|
38 |
+
anti_spoofing=True,
|
39 |
+
align=True,
|
40 |
+
normalization="Facenet")
|
41 |
+
result = results['verified']
|
42 |
+
if results['verified'] == True:
|
43 |
+
result = f"Verification check complete! Successfully verified student: {data['last_name']} {data['first_name']} with matriculation number {data['matric_no']}"
|
44 |
+
else:
|
45 |
+
result = f"Verification check complete! You are not student {data['last_name']} {data['first_name']} with matriculation number {data['matric_no']}"
|
46 |
+
|
47 |
+
cropped_input_image, cropped_returned_image = extract_faces(webcam_image, actual_image, results)
|
48 |
+
return result, cropped_input_image, cropped_returned_image, actual_image
|
49 |
+
|
50 |
+
|
51 |
+
def main(last_name, matric_no, input_image):
|
52 |
+
|
53 |
+
#df = pd.read_csv('students_df.csv')
|
54 |
+
db_path = 'students_database.db'
|
55 |
+
#create_db(db_path, df)
|
56 |
+
|
57 |
+
result, cropped_input_image, cropped_returned_image, actual_image = verify_student(db_path,
|
58 |
+
last_name,
|
59 |
+
matric_no,
|
60 |
+
input_image)
|
61 |
+
|
62 |
+
#os.remove('students_database.db')
|
63 |
+
return result, cropped_input_image, cropped_returned_image, actual_image
|
64 |
+
|
65 |
+
if __name__ == '__main__':
|
66 |
main()
|