Rasleen commited on
Commit
b973445
·
verified ·
1 Parent(s): a2cd93d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -49
app.py CHANGED
@@ -1,60 +1,28 @@
1
  import gradio as gr
2
-
3
-
4
  import numpy as np
5
-
6
  import cv2
7
-
8
  from PIL import Image
9
 
10
-
11
-
12
  def detect_faces(image , slider ) :
13
-
14
- # detect faces
15
-
16
- # convert image in to numpy array
17
-
18
- image_np = np.array(image)
19
-
20
- # convert image into gray
21
-
22
- gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
23
-
24
- # use detectmultiscale function to detect faces using haar cascade
25
-
26
- face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
27
-
28
- faces = face_cascade.detectMultiScale(gray_image, scaleFactor=slider, minNeighbors=5, minSize=(30, 30))
29
-
30
- # draw rectangle along detected faces
31
-
32
- for (x, y, w, h) in faces:
33
-
34
- cv2.rectangle(image_np, (x, y), (x+w, y+h), (255, 0, 0), 5)
35
-
36
-
37
-
38
  return image_np
39
 
 
40
 
41
-
42
- slider = gr.Slider(minimum=1, maximum=2, step=.1, label="Adjust the ScaleFactor")
43
-
44
-
45
-
46
- iface = gr.Interface( fn=detect_faces,
47
-
48
- inputs=["image","slider"],
49
-
50
- outputs="image",
51
-
52
- title="Face Detection using Haar Cascade Classifier ",
53
-
54
- description="Upload an image,and the model will detect faces and draw bounding boxes around them.",
55
-
56
- )
57
-
58
-
59
 
60
  iface.launch()
 
1
  import gradio as gr
 
 
2
  import numpy as np
 
3
  import cv2
 
4
  from PIL import Image
5
 
 
 
6
  def detect_faces(image , slider ) :
7
+ # detect faces
8
+
9
+ # convert image in to numpy array
10
+ image_np = np.array(image)
11
+
12
+ # convert image into gray
13
+ gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
14
+
15
+ # use detectmultiscale function to detect faces using haar cascade
16
+ face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
17
+ faces = face_cascade.detectMultiScale(gray_image, scaleFactor=slider, minNeighbors=5, minSize=(30, 30))
18
+
19
+ # draw rectangle along detected faces
20
+ for (x, y, w, h) in faces:
21
+ cv2.rectangle(image_np, (x, y), (x+w, y+h), (255, 0, 0), 5)
 
 
 
 
 
 
 
 
 
 
22
  return image_np
23
 
24
+ slider = gr.Slider(1, 2, step=.1, label="Adjust the ScaleFactor", value=1.5)
25
 
26
+ iface = gr.Interface( fn=detect_faces,inputs=["image","slider"],outputs="image",title="Face Detection using Haar Cascade Classifier ",description="Upload an image,and the model will detect faces and draw bounding boxes around them.",)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  iface.launch()