sarwansingh commited on
Commit
55e73d0
·
verified ·
1 Parent(s): e7a7dd3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import cv2
3
+ import gradio as gr
4
+ from PIL import Image
5
+
6
+ def detect_faces(image):
7
+ image_np = np.array(image)
8
+ gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
9
+ face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
10
+ faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
11
+ for (x, y, w, h) in faces:
12
+ cv2.rectangle(image_np, (x, y), (x+w, y+h), (0, 255, 0), 2)
13
+ return image_np
14
+
15
+ iface = gr.Interface( fn=detect_faces,
16
+ inputs="image",
17
+ outputs="image",
18
+ title="Face Detection using Haar Cascade Classifier ",
19
+ description="Upload an image,and the model will detect faces and draw bounding boxes around them.",
20
+ )
21
+ iface.launch()