Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import cv2
|
|
| 3 |
import numpy as np
|
| 4 |
import datetime
|
| 5 |
import os
|
|
|
|
| 6 |
from camera_input_live import camera_input_live
|
| 7 |
|
| 8 |
def save_image(image):
|
|
@@ -21,26 +22,44 @@ def main():
|
|
| 21 |
st.title("Streamlit Camera Input Live Demo")
|
| 22 |
st.header("Try holding a QR code in front of your webcam")
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
st.
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
st.
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
main()
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import datetime
|
| 5 |
import os
|
| 6 |
+
import time
|
| 7 |
from camera_input_live import camera_input_live
|
| 8 |
|
| 9 |
def save_image(image):
|
|
|
|
| 22 |
st.title("Streamlit Camera Input Live Demo")
|
| 23 |
st.header("Try holding a QR code in front of your webcam")
|
| 24 |
|
| 25 |
+
# Sidebar for captured images
|
| 26 |
+
st.sidebar.markdown("## Captured Images")
|
| 27 |
+
captured_images = []
|
| 28 |
+
|
| 29 |
+
# Initialize session state
|
| 30 |
+
if 'last_captured' not in st.session_state:
|
| 31 |
+
st.session_state['last_captured'] = time.time()
|
| 32 |
+
|
| 33 |
+
while True:
|
| 34 |
+
image = camera_input_live()
|
| 35 |
+
|
| 36 |
+
if image is not None:
|
| 37 |
+
st.image(image)
|
| 38 |
+
|
| 39 |
+
# Save image every 5 seconds
|
| 40 |
+
if time.time() - st.session_state['last_captured'] > 5:
|
| 41 |
+
filename = save_image(image)
|
| 42 |
+
captured_images.append(filename)
|
| 43 |
+
st.session_state['last_captured'] = time.time()
|
| 44 |
+
|
| 45 |
+
# Update sidebar
|
| 46 |
+
for img_file in captured_images:
|
| 47 |
+
st.sidebar.markdown(f"- [{img_file}](./{img_file})")
|
| 48 |
+
|
| 49 |
+
# QR Code Detection
|
| 50 |
+
detector = cv2.QRCodeDetector()
|
| 51 |
+
bytes_data = image.getvalue()
|
| 52 |
+
cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
|
| 53 |
+
data, bbox, straight_qrcode = detector.detectAndDecode(cv2_img)
|
| 54 |
+
|
| 55 |
+
if data:
|
| 56 |
+
st.write("# Found QR code")
|
| 57 |
+
st.write(data)
|
| 58 |
+
with st.expander("Show details"):
|
| 59 |
+
st.write("BBox:", bbox)
|
| 60 |
+
st.write("Straight QR code:", straight_qrcode)
|
| 61 |
+
|
| 62 |
+
time.sleep(0.1) # Add a short delay to reduce CPU usage
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
main()
|