Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,15 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
image_np= np.array(image)
|
| 7 |
gray_image= cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
|
| 8 |
face_cascade= cv2.CascadeClassifier(cv2.data.haarcascades +
|
| 9 |
"haarcascade_frontalface_default.xml")
|
| 10 |
-
faces = face_cascade.detectMultiScale(gray_image,
|
| 11 |
-
scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
|
| 12 |
for (x, y, w, h) in faces:
|
| 13 |
-
|
| 14 |
return image_np
|
| 15 |
|
| 16 |
iface= gr.Interface(fn=detect_faces,inputs="image",outputs="image",title="Face Detection",description="Upload an image, and the model will detect faces and draw bounding boxes around them.",)
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import cv2
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from PIL import Image
|
| 5 |
+
def detect_faces(image):
|
| 6 |
image_np= np.array(image)
|
| 7 |
gray_image= cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
|
| 8 |
face_cascade= cv2.CascadeClassifier(cv2.data.haarcascades +
|
| 9 |
"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,inputs="image",outputs="image",title="Face Detection",description="Upload an image, and the model will detect faces and draw bounding boxes around them.",)
|