jentz2909 commited on
Commit
2db55d1
·
1 Parent(s): 1c29168

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +17 -3
  2. haarcascade_frontalface_default.xml +0 -0
app.py CHANGED
@@ -1,18 +1,32 @@
1
  import streamlit as st
2
  import cv2
3
 
 
 
 
4
  # Create a Streamlit app
5
- st.title("Webcam Capture")
6
 
7
  # Initialize the webcam
8
  cap = cv2.VideoCapture(0)
9
  cap.set(3, 640)
10
  cap.set(4, 480)
11
 
12
- # Create a button to capture images
13
- if st.button("Capture Image"):
14
  ret, img = cap.read()
15
  if ret:
 
 
 
 
 
 
 
 
 
 
 
16
  st.image(img, channels="BGR")
17
 
18
  # Release the webcam when the app is done
 
1
  import streamlit as st
2
  import cv2
3
 
4
+ # Load the Haar Cascade XML file for face detection
5
+ face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
6
+
7
  # Create a Streamlit app
8
+ st.title("Face Detection")
9
 
10
  # Initialize the webcam
11
  cap = cv2.VideoCapture(0)
12
  cap.set(3, 640)
13
  cap.set(4, 480)
14
 
15
+ # Create a button to perform face detection
16
+ if st.button("Detect Faces"):
17
  ret, img = cap.read()
18
  if ret:
19
+ # Convert the image to grayscale for face detection
20
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
21
+
22
+ # Perform face detection
23
+ faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5)
24
+
25
+ # Draw rectangles around detected faces
26
+ for (x, y, w, h) in faces:
27
+ cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
28
+
29
+ # Display the image with detected faces
30
  st.image(img, channels="BGR")
31
 
32
  # Release the webcam when the app is done
haarcascade_frontalface_default.xml ADDED
The diff for this file is too large to render. See raw diff