facedetection / app.py
likhithAIML24's picture
Create app.py
1162f54 verified
raw
history blame
628 Bytes
import cv2
import gradio as gr
def detect_faces(image):
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5)
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (255, 0, 0), 2)
return image, f"Number of faces detected: {len(faces)}"
iface = gr.Interface(fn=detect_faces, inputs=gr.inputs.Image(shape=(480, 640), source="webcam"), outputs=["image", "text"], title="Face Detection App")
iface.launch()