bisoye commited on
Commit
f15defa
1 Parent(s): 6792c33

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +65 -64
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
- results = DeepFace.verify(webcam_image,
32
- actual_image,
33
- model_name='Facenet',
34
- detector_backend="retinaface",
35
- distance_metric="cosine",
36
- enforce_detection=True,
37
- anti_spoofing=True,
38
- align=True,
39
- normalization="Facenet")
40
- result = results['verified']
41
- if results['verified'] == True:
42
- result = f"Verification check complete! Successfully verified student: {data['last_name']} {data['first_name']} with matriculation number {data['matric_no']}"
43
- else:
44
- result = f"Verification check complete! You are not student {data['last_name']} {data['first_name']} with matriculation number {data['matric_no']}"
45
-
46
- cropped_input_image, cropped_returned_image = extract_faces(webcam_image, actual_image, results)
47
- return result, cropped_input_image, cropped_returned_image, actual_image
48
-
49
-
50
- def main(last_name, matric_no, input_image):
51
-
52
- #df = pd.read_csv('students_df.csv')
53
- db_path = 'students_database.db'
54
- #create_db(db_path, df)
55
-
56
- result, cropped_input_image, cropped_returned_image, actual_image = verify_student(db_path,
57
- last_name,
58
- matric_no,
59
- input_image)
60
-
61
- #os.remove('students_database.db')
62
- return result, cropped_input_image, cropped_returned_image, actual_image
63
-
64
- if __name__ == '__main__':
 
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()