So i got here is a code that detect if the face in the image is in my encodings. So my problem is what if the face is not in the Encodings can i pass a string variable to a OneToOneField() or can i set a default value to it? and also how can i link the image it is in a Numpy Array format yeah i already think about just saving it inside my MEDIA folder but how can i link it to ImageField()?
Here's my code:
models.py
def log_image_path(instance, filename):
extention = filename.split('.')[-1]
return os.path.join(settings.LOGS_ROOT, f"{uuid.uuid4()}.{extention}")
class MonitorLog(models.Model):
student_info = models.OneToOneField(Student, on_delete=models.CASCADE)
log_image = models.ImageField(upload_to=log_image_path)
log_time = models.DateTimeField(default=timezone.now)
tasks.py
def identify_face(arr):
master_encodings = pickle.loads(open(settings.TRAINING_FILE_DIR, 'rb').read())
arr = np.asarray(arr)
rgb = arr[:,:,::-1]
faces = face_recognition.face_locations(rgb, model='hog')
enc = face_recognition.face_encodings(rgb, faces)
main_enc = [encs for encs in enc]
for encoding in main_enc:
matches = face_recognition.compare_faces(master_encodings['encodings'], encoding)
name = 'Unknown'
if True in matches:
encIds = [encIndex for (encIndex, value) in enumerate(matches) if value]
counts = {}
for num in encIds:
name = master_encodings['student_number'][num]
counts[name] = counts.get(name, 0) + 1
name = max(counts, key=counts.get)
if name != "Unknown":
stud_ins = models.Student.objects.get(student_number=name)