LovnishVerma commited on
Commit
3c41a6c
·
verified ·
1 Parent(s): 3ab75c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
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)[0] # Use the correct detect method
59
 
60
- for face in faces:
61
- x, y, w, h = face[0], face[1], face[2], face[3]
62
- roi_gray = gray[y:y+h, x:x+w]
63
- known_faces.append(roi_gray)
64
- known_names.append(image_name.split('.')[0]) # Assuming file name is the person's name
 
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)[0] # Use the correct detect method
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