sarwansingh commited on
Commit
aa7ee12
·
verified ·
1 Parent(s): d97bd9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -3,7 +3,7 @@ import numpy as np
3
  import cv2
4
  from PIL import Image
5
 
6
- def detect_faces(image ) :
7
  # detect faces
8
  # convert image in to numpy array
9
  image_np = np.array(image)
@@ -11,15 +11,17 @@ def detect_faces(image ) :
11
  gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
12
  # use detectmultiscale function to detect faces using haar cascade
13
  face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
14
- faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
15
  # draw rectangle along detected faces
16
  for (x, y, w, h) in faces:
17
  cv2.rectangle(image_np, (x, y), (x+w, y+h), (255, 0, 0), 5)
18
 
19
  return image_np
20
 
 
 
21
  iface = gr.Interface( fn=detect_faces,
22
- inputs="image",
23
  outputs="image",
24
  title="Face Detection using Haar Cascade Classifier ",
25
  description="Upload an image,and the model will detect faces and draw bounding boxes around them.",
 
3
  import cv2
4
  from PIL import Image
5
 
6
+ def detect_faces(image , slider ) :
7
  # detect faces
8
  # convert image in to numpy array
9
  image_np = np.array(image)
 
11
  gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
12
  # use detectmultiscale function to detect faces using haar cascade
13
  face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
14
+ faces = face_cascade.detectMultiScale(gray_image, scaleFactor=slider, minNeighbors=5, minSize=(30, 30))
15
  # draw rectangle along detected faces
16
  for (x, y, w, h) in faces:
17
  cv2.rectangle(image_np, (x, y), (x+w, y+h), (255, 0, 0), 5)
18
 
19
  return image_np
20
 
21
+ slider = gr.Slider(minimum=1, maximum=2, step=.1, label="Adjust the ScaleFactor")
22
+
23
  iface = gr.Interface( fn=detect_faces,
24
+ inputs=["image","slider"],
25
  outputs="image",
26
  title="Face Detection using Haar Cascade Classifier ",
27
  description="Upload an image,and the model will detect faces and draw bounding boxes around them.",