Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import time
|
|
5 |
import os
|
6 |
from keras.models import load_model
|
7 |
from PIL import Image
|
8 |
-
import
|
9 |
import pymongo
|
10 |
from datetime import datetime
|
11 |
import tempfile
|
@@ -52,11 +52,11 @@ def load_known_faces():
|
|
52 |
image = cv2.imread(image_path)
|
53 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
54 |
# Detect face in the image
|
55 |
-
|
56 |
-
|
57 |
-
)
|
58 |
|
59 |
-
for
|
|
|
60 |
roi_gray = gray[y:y+h, x:x+w]
|
61 |
known_faces.append(roi_gray)
|
62 |
known_names.append(image_name.split('.')[0]) # Assuming file name is the person's name
|
@@ -66,28 +66,21 @@ def load_known_faces():
|
|
66 |
|
67 |
load_known_faces()
|
68 |
|
69 |
-
#
|
70 |
-
|
71 |
|
72 |
# Process a single frame
|
73 |
def process_frame(frame):
|
74 |
-
|
75 |
-
|
76 |
|
77 |
result_text = "" # Initialize result text
|
78 |
|
79 |
-
if
|
80 |
-
for
|
81 |
-
|
82 |
-
h, w, _ = frame.shape
|
83 |
-
bbox = (
|
84 |
-
int(bboxC.xmin * w), int(bboxC.ymin * h),
|
85 |
-
int(bboxC.width * w), int(bboxC.height * h)
|
86 |
-
)
|
87 |
-
x, y, w, h = bbox
|
88 |
-
|
89 |
roi_color = frame[y:y+h, x:x+w]
|
90 |
-
roi_gray =
|
91 |
|
92 |
# Apply histogram equalization for better feature extraction
|
93 |
roi_gray = cv2.equalizeHist(roi_gray)
|
|
|
5 |
import os
|
6 |
from keras.models import load_model
|
7 |
from PIL import Image
|
8 |
+
import dlib
|
9 |
import pymongo
|
10 |
from datetime import datetime
|
11 |
import tempfile
|
|
|
52 |
image = cv2.imread(image_path)
|
53 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
54 |
# Detect face in the image
|
55 |
+
detector = dlib.get_frontal_face_detector()
|
56 |
+
faces = detector(gray)
|
|
|
57 |
|
58 |
+
for face in faces:
|
59 |
+
x, y, w, h = (face.left(), face.top(), face.width(), face.height())
|
60 |
roi_gray = gray[y:y+h, x:x+w]
|
61 |
known_faces.append(roi_gray)
|
62 |
known_names.append(image_name.split('.')[0]) # Assuming file name is the person's name
|
|
|
66 |
|
67 |
load_known_faces()
|
68 |
|
69 |
+
# Dlib face detector
|
70 |
+
detector = dlib.get_frontal_face_detector()
|
71 |
|
72 |
# Process a single frame
|
73 |
def process_frame(frame):
|
74 |
+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
75 |
+
faces = detector(gray)
|
76 |
|
77 |
result_text = "" # Initialize result text
|
78 |
|
79 |
+
if len(faces) > 0:
|
80 |
+
for face in faces:
|
81 |
+
x, y, w, h = (face.left(), face.top(), face.width(), face.height())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
roi_color = frame[y:y+h, x:x+w]
|
83 |
+
roi_gray = gray[y:y+h, x:x+w]
|
84 |
|
85 |
# Apply histogram equalization for better feature extraction
|
86 |
roi_gray = cv2.equalizeHist(roi_gray)
|