-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
71 lines (48 loc) · 1.76 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# import cv2
# import streamlit as st
# import numpy as np
# import tempfile
# # Use this line to capture video from the webcam
# cap = cv2.VideoCapture(0)
# # Set the title for the Streamlit app
# st.title("Video Capture with OpenCV")
# frame_placeholder = st.empty()
# # Add a "Stop" button and store its state in a variable
# stop_button_pressed = st.button("Stop")
# while cap.isOpened() and not stop_button_pressed:
# ret, frame = cap.read()
# if not ret:
# st.write("The video capture has ended.")
# break
# # You can process the frame here if needed
# # e.g., apply filters, transformations, or object detection
# # Convert the frame from BGR to RGB format
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# # Display the frame using Streamlit's st.image
# frame_placeholder.image(frame, channels="RGB")
# # Break the loop if the 'q' key is pressed or the user clicks the "Stop" button
# if cv2.waitKey(1) & 0xFF == ord("q") or stop_button_pressed:
# break
# cap.release()
# cv2.destroyAllWindows()
import cv2
import streamlit as st
# Set the title of the Streamlit app
st.title("Webcam Feed")
# Create a checkbox to start/stop the webcam
run = st.checkbox("Run")
# Create an empty placeholder to display the webcam feed
FRAME_WINDOW = st.image([])
# Initialize the webcam
camera = cv2.VideoCapture(0)
while run:
# Read a frame from the webcam
_, frame = camera.read()
# Convert the frame from BGR to RGB color format
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Resize the frame to 100px x 100px
frame = cv2.resize(frame, (100, 100))
# Display the resized frame in the placeholder
FRAME_WINDOW.image(frame)
# Release the webcam when the loop ends
camera.release()