nikshep01 commited on
Commit
9556539
·
verified ·
1 Parent(s): 0029c21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -60,39 +60,39 @@ if file_name is not None:
60
 
61
  # Checking if faces are detected
62
  if len(encodesCurFrame) > 0:
63
- # Assuming that encodeListknown is defined and populated in your code
64
  for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame):
65
- # Get the top-left and bottom-right coordinates of the face
66
- top, right, bottom, left = faceLoc
67
-
68
- # Draw a rectangle around the face
69
- cv2.rectangle(image, (left*4, top*4), (right*4, bottom*4), (0, 255, 0), 2)
70
-
71
- # Assuming that classnames is defined and populated in your code
72
  matches = face_recognition.compare_faces(encodeListknown, encodeFace)
73
  faceDis = face_recognition.face_distance(encodeListknown, encodeFace)
74
 
75
  # Initialize name as Unknown
76
  name = "Unknown"
77
-
78
  # Check if there's a match with known faces
79
  if True in matches:
80
  matchIndex = np.argmin(faceDis)
81
  name = classnames[matchIndex].upper()
82
-
83
- # Draw text label with the recognized name above the rectangle
84
- cv2.putText(image, name, (left*4, top*4 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
 
 
 
 
 
 
 
85
 
86
  # Store attendance in SQLite database
87
  add_attendance(name)
88
-
89
  # Display the image with recognized faces
90
  st.image(image, use_column_width=True, output_format="PNG")
91
 
92
-
93
  # Display recognized names
94
  st.write("Recognized Names:")
95
  for i, name in enumerate(recognized_names):
96
  st.write(f"Face {i+1}: {name}")
97
  else:
98
  st.warning("No faces detected in the image. Face recognition failed.")
 
 
60
 
61
  # Checking if faces are detected
62
  if len(encodesCurFrame) > 0:
 
63
  for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame):
64
+ # Assuming that encodeListknown is defined and populated in your code
 
 
 
 
 
 
65
  matches = face_recognition.compare_faces(encodeListknown, encodeFace)
66
  faceDis = face_recognition.face_distance(encodeListknown, encodeFace)
67
 
68
  # Initialize name as Unknown
69
  name = "Unknown"
70
+
71
  # Check if there's a match with known faces
72
  if True in matches:
73
  matchIndex = np.argmin(faceDis)
74
  name = classnames[matchIndex].upper()
75
+
76
+ # Append recognized name to the list
77
+ recognized_names.append(name)
78
+
79
+ # Draw rectangle around the face
80
+ y1, x2, y2, x1 = faceLoc
81
+ y1, x2, y2, x1 = (y1 * 4), (x2 * 4), (y2 * 4) ,(x1 * 4)
82
+ image = image.copy()
83
+ cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
84
+ cv2.putText(image, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
85
 
86
  # Store attendance in SQLite database
87
  add_attendance(name)
88
+
89
  # Display the image with recognized faces
90
  st.image(image, use_column_width=True, output_format="PNG")
91
 
 
92
  # Display recognized names
93
  st.write("Recognized Names:")
94
  for i, name in enumerate(recognized_names):
95
  st.write(f"Face {i+1}: {name}")
96
  else:
97
  st.warning("No faces detected in the image. Face recognition failed.")
98
+