Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,22 @@
|
|
| 1 |
-
import
|
| 2 |
-
import gradio as gr
|
| 3 |
|
| 4 |
-
# Load the
|
| 5 |
-
face_cascade =
|
| 6 |
|
| 7 |
# Load the input image
|
| 8 |
-
img =
|
| 9 |
|
| 10 |
# Convert the image to grayscale
|
| 11 |
-
gray =
|
| 12 |
|
| 13 |
# Detect faces in the grayscale image using the Haar cascade
|
| 14 |
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
graph = gr.Graph()
|
| 18 |
-
|
| 19 |
-
# Add the input image to the graph
|
| 20 |
-
graph.add_node(gr.ImageNode(img, 'Input Image'))
|
| 21 |
-
|
| 22 |
-
# Add the detected faces to the graph
|
| 23 |
for (x, y, w, h) in faces:
|
| 24 |
-
|
| 25 |
-
graph.add_node(gr.ImageNode(face_img, f'Face {x}, {y}'))
|
| 26 |
|
| 27 |
-
# Display the
|
| 28 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
import opencv2
|
|
|
|
| 2 |
|
| 3 |
+
# Load the cascade classifier for face detection
|
| 4 |
+
face_cascade = opencv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
|
| 5 |
|
| 6 |
# Load the input image
|
| 7 |
+
img = opencv2.imread('input_image.jpg')
|
| 8 |
|
| 9 |
# Convert the image to grayscale
|
| 10 |
+
gray = opencv2.cvtColor(img, opencv2.COLOR_BGR2GRAY)
|
| 11 |
|
| 12 |
# Detect faces in the grayscale image using the Haar cascade
|
| 13 |
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
|
| 14 |
|
| 15 |
+
# Draw rectangles around the detected faces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
for (x, y, w, h) in faces:
|
| 17 |
+
opencv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)
|
|
|
|
| 18 |
|
| 19 |
+
# Display the output image with the detected faces
|
| 20 |
+
opencv2.imshow('Output', img)
|
| 21 |
+
opencv2.waitKey(0)
|
| 22 |
+
opencv2.destroyAllWindows()
|