LovnishVerma commited on
Commit
7dc8b9f
·
verified ·
1 Parent(s): 2c28041

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -42,6 +42,7 @@ emotion_labels = ['angry', 'fear', 'happy', 'neutral', 'sad', 'surprise']
42
  # Initialize MTCNN for face detection
43
  mtcnn = MTCNN()
44
 
 
45
  # Load known faces and names
46
  known_faces = []
47
  known_names = []
@@ -59,13 +60,15 @@ def load_known_faces():
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))]))
 
69
 
70
  load_known_faces()
71
 
@@ -78,7 +81,8 @@ def process_frame(frame):
78
 
79
  if faces is not None and len(faces) > 0:
80
  for face in faces:
81
- x, y, w, h = face[0], face[1], face[2], face[3]
 
82
  roi_color = frame[y:y+h, x:x+w]
83
  roi_gray = gray[y:y+h, x:x+w]
84
 
@@ -120,6 +124,7 @@ def process_frame(frame):
120
 
121
  return frame, result_text
122
 
 
123
  # Video feed display
124
  def video_feed(video_source):
125
  frame_placeholder = st.empty() # Placeholder for displaying video frames
 
42
  # Initialize MTCNN for face detection
43
  mtcnn = MTCNN()
44
 
45
+ # Load known faces and names
46
  # Load known faces and names
47
  known_faces = []
48
  known_names = []
 
60
 
61
  if faces is not None:
62
  for face in faces:
63
+ # Convert bounding box coordinates to integers
64
+ x, y, w, h = map(int, face) # Ensure the coordinates are integers
65
  roi_gray = gray[y:y+h, x:x+w]
66
  known_faces.append(roi_gray)
67
  known_names.append(image_name.split('.')[0]) # Assuming file name is the person's name
68
 
69
  # Train the recognizer with the known faces
70
+ if known_faces: # Only train if we have faces
71
+ face_recognizer.train(known_faces, np.array([i for i in range(len(known_faces))]))
72
 
73
  load_known_faces()
74
 
 
81
 
82
  if faces is not None and len(faces) > 0:
83
  for face in faces:
84
+ # Convert bounding box coordinates to integers
85
+ x, y, w, h = map(int, face) # Ensure the coordinates are integers
86
  roi_color = frame[y:y+h, x:x+w]
87
  roi_gray = gray[y:y+h, x:x+w]
88
 
 
124
 
125
  return frame, result_text
126
 
127
+
128
  # Video feed display
129
  def video_feed(video_source):
130
  frame_placeholder = st.empty() # Placeholder for displaying video frames