Spaces:
Sleeping
Sleeping
File size: 2,601 Bytes
3dfac81 |
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 |
import os
import warnings
os.environ['TF_ENABLE_ONEDNN_OPTS']=str(0)
warnings.filterwarnings('ignore')
#import pandas as pd
import numpy as np
from deepface import DeepFace
from db import create_db, get_student_row
from helper_fns import binary_to_pil, extract_faces
def verify_student(db_path, last_name, matric_no, input_image):
data = get_student_row(db_path, last_name, matric_no)
if data is not None:
binary_image = data['image']
else:
raise ValueError('No student having last name {last_name} and matric no: {matric_no} exists in this database.')
actual_image =np.array(binary_to_pil(binary_image))
webcam_image = input_image
if webcam_image is None:
raise ValueError(f'No image')
else:
print('Received image')
results = DeepFace.verify(webcam_image,
actual_image,
model_name='Facenet',
detector_backend="retinaface",
distance_metric="cosine",
enforce_detection=True,
anti_spoofing=True,
align=True,
normalization="Facenet")
result = results['verified']
if results['verified'] == True:
result = f"Verification check complete! Successfully verified student: {data['last_name']} {data['first_name']} with matriculation number {data['matric_no']}"
else:
result = f"Verification check complete! You are not student {data['last_name']} {data['first_name']} with matriculation number {data['matric_no']}"
cropped_input_image, cropped_returned_image = extract_faces(webcam_image, actual_image, results)
return result, cropped_input_image, cropped_returned_image, actual_image
def main(last_name, matric_no, input_image):
#df = pd.read_csv('students_df.csv')
db_path = 'students_database.db'
#create_db(db_path, df)
result, cropped_input_image, cropped_returned_image, actual_image = verify_student(db_path,
last_name,
matric_no,
input_image)
#os.remove('students_database.db')
return result, cropped_input_image, cropped_returned_image, actual_image
if __name__ == '__main__':
main() |