Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from PIL import Image
|
|
| 7 |
import numpy as np
|
| 8 |
import cv2
|
| 9 |
import dlib
|
|
|
|
| 10 |
|
| 11 |
# Get the current working directory
|
| 12 |
current_directory = os.path.dirname(os.path.abspath(__file__))
|
|
@@ -62,15 +63,28 @@ def create_user(email, password):
|
|
| 62 |
return False, None
|
| 63 |
|
| 64 |
# Update load_and_encode function to return encodings for all detected faces
|
| 65 |
-
def load_and_encode(
|
| 66 |
try:
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
else:
|
| 75 |
return None
|
| 76 |
else:
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
import cv2
|
| 9 |
import dlib
|
| 10 |
+
from io import BytesIO
|
| 11 |
|
| 12 |
# Get the current working directory
|
| 13 |
current_directory = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
| 63 |
return False, None
|
| 64 |
|
| 65 |
# Update load_and_encode function to return encodings for all detected faces
|
| 66 |
+
def load_and_encode(image_file):
|
| 67 |
try:
|
| 68 |
+
# Read the uploaded file as bytes
|
| 69 |
+
image_bytes = image_file.read()
|
| 70 |
+
|
| 71 |
+
# Convert the bytes to a NumPy array
|
| 72 |
+
nparr = np.frombuffer(image_bytes, np.uint8)
|
| 73 |
+
|
| 74 |
+
# Decode the NumPy array as an image
|
| 75 |
+
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
| 76 |
+
|
| 77 |
+
aligned_faces = detect_and_align_faces(image)
|
| 78 |
+
|
| 79 |
+
if aligned_faces is not None:
|
| 80 |
+
encodings = []
|
| 81 |
+
for aligned_face in aligned_faces:
|
| 82 |
+
encoding = face_recognition.face_encodings(aligned_face)
|
| 83 |
+
if encoding:
|
| 84 |
+
encodings.append(encoding[0])
|
| 85 |
+
|
| 86 |
+
if encodings:
|
| 87 |
+
return encodings
|
| 88 |
else:
|
| 89 |
return None
|
| 90 |
else:
|