sdafd commited on
Commit
366b72d
1 Parent(s): 375923e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -3,33 +3,33 @@ from mtcnn.mtcnn import MTCNN
3
  import cv2
4
  import numpy as np
5
 
6
- # Function to perform face detection using MTCNN
7
  def detect_faces(image):
8
- # Load the image
9
- img = cv2.imdecode(np.frombuffer(image.read(), np.uint8), -1)
10
 
11
- # Create an MTCNN detector
12
  detector = MTCNN()
 
13
 
14
- # Detect faces in the image
15
- faces = detector.detect_faces(img)
16
-
17
- # Draw bounding boxes around the faces
18
  for face in faces:
19
  x, y, width, height = face['box']
20
- cv2.rectangle(img, (x, y), (x + width, y + height), (0, 255, 0), 2)
21
-
22
- # Convert the image to RGB format for Gradio
23
- img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
24
 
25
- return img_rgb
26
 
27
- # Create a Gradio interface
28
  iface = gr.Interface(
29
  fn=detect_faces,
30
- inputs=gr.Image(),
31
- outputs="image"
 
 
 
 
 
32
  )
33
 
34
- # Launch the Gradio interface
35
  iface.launch()
 
3
  import cv2
4
  import numpy as np
5
 
6
+ # Function to detect faces using MTCNN
7
  def detect_faces(image):
8
+ # Convert image to RGB format
9
+ image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
10
 
11
+ # Detect faces using MTCNN
12
  detector = MTCNN()
13
+ faces = detector.detect_faces(image_rgb)
14
 
15
+ # Draw bounding boxes around detected faces
 
 
 
16
  for face in faces:
17
  x, y, width, height = face['box']
18
+ cv2.rectangle(image, (x, y), (x + width, y + height), (255, 0, 0), 2)
 
 
 
19
 
20
+ return image
21
 
22
+ # Gradio Interface
23
  iface = gr.Interface(
24
  fn=detect_faces,
25
+ inputs=gr.Image(type="numpy", label="Input Image"),
26
+ outputs=gr.Image(type="numpy", label="Output Image"),
27
+ live=True,
28
+ capture_session=True,
29
+ interpretation="default",
30
+ title="MTCNN Face Detection",
31
+ description="Detect faces in an image using MTCNN.",
32
  )
33
 
34
+ # Launch the Gradio Interface
35
  iface.launch()