Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,36 @@
|
|
1 |
import cv2
|
2 |
import numpy as np
|
3 |
import streamlit as st
|
4 |
-
|
5 |
from camera_input_live import camera_input_live
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
|
|
10 |
image = camera_input_live()
|
11 |
|
12 |
if image is not None:
|
13 |
-
|
|
|
|
|
|
|
14 |
bytes_data = image.getvalue()
|
15 |
cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
st.write(data)
|
24 |
-
with st.expander("Show details"):
|
25 |
-
st.write("BBox:", bbox)
|
26 |
-
st.write("Straight QR code:", straight_qrcode)
|
|
|
1 |
import cv2
|
2 |
import numpy as np
|
3 |
import streamlit as st
|
|
|
4 |
from camera_input_live import camera_input_live
|
5 |
|
6 |
+
# Load Haarcascade for face detection
|
7 |
+
cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
|
8 |
+
|
9 |
+
# Streamlit app title
|
10 |
+
st.title("Live Object Detection with Camera")
|
11 |
+
st.subheader("Hold your face in front of the webcam to see real-time detection.")
|
12 |
|
13 |
+
# Capture live camera input
|
14 |
image = camera_input_live()
|
15 |
|
16 |
if image is not None:
|
17 |
+
# Display the captured image
|
18 |
+
st.image(image, caption="Live Camera Input", use_column_width=True)
|
19 |
+
|
20 |
+
# Convert the image to OpenCV format
|
21 |
bytes_data = image.getvalue()
|
22 |
cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
|
23 |
|
24 |
+
# Convert to grayscale for face detection
|
25 |
+
gray = cv2.cvtColor(cv2_img, cv2.COLOR_BGR2GRAY)
|
26 |
+
|
27 |
+
# Detect faces in the image
|
28 |
+
faces = cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=3)
|
29 |
|
30 |
+
# Draw rectangles around detected faces
|
31 |
+
for (x, y, w, h) in faces:
|
32 |
+
cv2.rectangle(cv2_img, (x, y), (x + w, y + h), (0, 255, 0), 3)
|
33 |
+
cv2.putText(cv2_img, "Face", (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
|
34 |
|
35 |
+
# Display the annotated image
|
36 |
+
st.image(cv2_img, channels="BGR", caption="Detected Faces", use_column_width=True)
|
|
|
|
|
|
|
|