0Hojoon0 commited on
Commit
a096f35
·
verified ·
1 Parent(s): c09c610

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -1,28 +1,22 @@
1
- import cv2
2
- import gradio as gr
3
 
4
- # Load the Haar cascade for face detection
5
- face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
6
 
7
  # Load the input image
8
- img = cv2.imread('input_image.jpg')
9
 
10
  # Convert the image to grayscale
11
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
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
- # Create a Gradio graph to display the input image and the detected faces
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
- face_img = gray[y:y+h, x:x+w]
25
- graph.add_node(gr.ImageNode(face_img, f'Face {x}, {y}'))
26
 
27
- # Display the graph
28
- graph.display()
 
 
 
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()