Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ from PIL import Image
|
|
8 |
from io import BytesIO
|
9 |
import base64
|
10 |
import cv2
|
|
|
11 |
import queue
|
12 |
|
13 |
# ππ₯ Initialize session state like a galactic DJ spinning tracks!
|
@@ -35,7 +36,7 @@ class CamThread(threading.Thread):
|
|
35 |
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
36 |
cam.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')) # Use MJPG for better USB compatibility
|
37 |
if not cam.isOpened():
|
38 |
-
st.error(f"π¨ Failed to open {self.preview_name}")
|
39 |
return
|
40 |
|
41 |
while self.running:
|
@@ -81,6 +82,7 @@ def auto_capture(frame_queues):
|
|
81 |
# ποΈ Sidebar config like a spaceship control panel!
|
82 |
with st.sidebar:
|
83 |
st.header("ποΈπΈ Snap Shack")
|
|
|
84 |
if st.button("β° Start Auto-Snap"):
|
85 |
st.session_state['auto_capture_running'] = True
|
86 |
threading.Thread(target=auto_capture, args=(frame_queues,), daemon=True).start()
|
@@ -102,7 +104,6 @@ with st.sidebar:
|
|
102 |
st.title("πΈ OpenCV Snap Craze")
|
103 |
|
104 |
# πΈπ· Start camera threads
|
105 |
-
frame_queues = [queue.Queue(maxsize=1), queue.Queue(maxsize=1)]
|
106 |
threads = [
|
107 |
CamThread("Camera 0", 0, frame_queues[0]),
|
108 |
CamThread("Camera 1", 1, frame_queues[1])
|
@@ -166,7 +167,7 @@ if st.session_state['file_history']:
|
|
166 |
else:
|
167 |
st.write("π³οΈ Nothing snapped yet!")
|
168 |
|
169 |
-
# Cleanup on app exit
|
170 |
def cleanup():
|
171 |
for thread in threads:
|
172 |
thread.stop()
|
|
|
8 |
from io import BytesIO
|
9 |
import base64
|
10 |
import cv2
|
11 |
+
import numpy as np
|
12 |
import queue
|
13 |
|
14 |
# ππ₯ Initialize session state like a galactic DJ spinning tracks!
|
|
|
36 |
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
37 |
cam.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')) # Use MJPG for better USB compatibility
|
38 |
if not cam.isOpened():
|
39 |
+
st.error(f"π¨ Failed to open {self.preview_name}. Check connection or index.")
|
40 |
return
|
41 |
|
42 |
while self.running:
|
|
|
82 |
# ποΈ Sidebar config like a spaceship control panel!
|
83 |
with st.sidebar:
|
84 |
st.header("ποΈπΈ Snap Shack")
|
85 |
+
frame_queues = [queue.Queue(maxsize=1), queue.Queue(maxsize=1)] # Define frame_queues here
|
86 |
if st.button("β° Start Auto-Snap"):
|
87 |
st.session_state['auto_capture_running'] = True
|
88 |
threading.Thread(target=auto_capture, args=(frame_queues,), daemon=True).start()
|
|
|
104 |
st.title("πΈ OpenCV Snap Craze")
|
105 |
|
106 |
# πΈπ· Start camera threads
|
|
|
107 |
threads = [
|
108 |
CamThread("Camera 0", 0, frame_queues[0]),
|
109 |
CamThread("Camera 1", 1, frame_queues[1])
|
|
|
167 |
else:
|
168 |
st.write("π³οΈ Nothing snapped yet!")
|
169 |
|
170 |
+
# Cleanup on app exit
|
171 |
def cleanup():
|
172 |
for thread in threads:
|
173 |
thread.stop()
|