Update app.py
Browse files
app.py
CHANGED
@@ -54,14 +54,15 @@ def load_known_faces():
|
|
54 |
image_path = os.path.join(folder_path, image_name)
|
55 |
image = cv2.imread(image_path)
|
56 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
57 |
-
# Detect face in the image
|
58 |
-
faces = mtcnn.detect(image)
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
65 |
|
66 |
# Train the recognizer with the known faces
|
67 |
face_recognizer.train(known_faces, np.array([i for i in range(len(known_faces))]))
|
@@ -71,7 +72,7 @@ load_known_faces()
|
|
71 |
# Process a single frame
|
72 |
def process_frame(frame):
|
73 |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
74 |
-
faces = mtcnn.detect(frame)
|
75 |
|
76 |
result_text = "" # Initialize result text
|
77 |
|
|
|
54 |
image_path = os.path.join(folder_path, image_name)
|
55 |
image = cv2.imread(image_path)
|
56 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
57 |
+
# Detect face in the image using mtcnn
|
58 |
+
faces, _ = mtcnn.detect(image) # Use the correct method detect()
|
59 |
|
60 |
+
if faces is not None:
|
61 |
+
for face in faces:
|
62 |
+
x, y, w, h = face[0], face[1], face[2], face[3]
|
63 |
+
roi_gray = gray[y:y+h, x:x+w]
|
64 |
+
known_faces.append(roi_gray)
|
65 |
+
known_names.append(image_name.split('.')[0]) # Assuming file name is the person's name
|
66 |
|
67 |
# Train the recognizer with the known faces
|
68 |
face_recognizer.train(known_faces, np.array([i for i in range(len(known_faces))]))
|
|
|
72 |
# Process a single frame
|
73 |
def process_frame(frame):
|
74 |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
75 |
+
faces, _ = mtcnn.detect(frame) # Use the correct detect method
|
76 |
|
77 |
result_text = "" # Initialize result text
|
78 |
|