BrainAI-1 commited on
Commit
ae169a4
·
verified ·
1 Parent(s): b9fad9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
app.py CHANGED
@@ -1,23 +1,20 @@
1
  import streamlit as st
2
  import cv2
3
  import numpy as np
 
4
 
5
- st.set_page_config(page_title="Live Webcam", page_icon="📷")
6
 
7
- st.title("📷 Live Webcam Stream")
8
- st.write("This app captures video from your webcam and displays it live.")
9
 
10
- # Access webcam
11
- frame_window = st.image([])
12
- cap = cv2.VideoCapture(0) # Open webcam
13
 
14
- while cap.isOpened():
15
- ret, frame = cap.read()
16
- if not ret:
17
- st.error("Failed to capture video")
18
- break
19
-
20
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Convert BGR to RGB
21
- frame_window.image(frame, use_column_width=True)
22
-
23
- cap.release()
 
1
  import streamlit as st
2
  import cv2
3
  import numpy as np
4
+ from PIL import Image
5
 
6
+ st.set_page_config(page_title="Webcam App", page_icon="📷")
7
 
8
+ st.title("📷 Streamlit Webcam App")
 
9
 
10
+ # Use Streamlit's built-in camera input
11
+ image_file = st.camera_input("Take a picture")
 
12
 
13
+ if image_file:
14
+ # Convert image to OpenCV format
15
+ img = Image.open(image_file)
16
+ img = np.array(img) # Convert to NumPy array
17
+ img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) # Convert to OpenCV BGR format
18
+
19
+ # Show the captured image
20
+ st.image(img, caption="Captured Image", use_column_width=True)