Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def detect_face(image):
|
| 6 |
+
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
|
| 7 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 8 |
+
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
|
| 9 |
+
for (x, y, w, h) in faces:
|
| 10 |
+
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
| 11 |
+
return image
|
| 12 |
+
|
| 13 |
+
st.title("Face Detection App")
|
| 14 |
+
|
| 15 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 16 |
+
if uploaded_image is not None:
|
| 17 |
+
image = cv2.imdecode(np.fromstring(uploaded_image.read(), np.uint8), 1)
|
| 18 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 19 |
+
|
| 20 |
+
if st.button("Detect Faces"):
|
| 21 |
+
result_image = detect_face(image)
|
| 22 |
+
st.image(result_image, caption="Image with Detected Faces", use_column_width=True)
|
| 23 |
+
|
| 24 |
+
st.write("This is a simple face detection app using Streamlit and OpenCV.")
|