import streamlit as st import cv2 import numpy as np import datetime import os from camera_input_live import camera_input_live def save_image(image): # Generate a timestamped filename timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") filename = f"captured_image_{timestamp}.png" # Convert the image to OpenCV format and save bytes_data = image.getvalue() cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR) cv2.imwrite(filename, cv2_img) return filename def main(): st.title("Streamlit Camera Input Live Demo") st.header("Try holding a QR code in front of your webcam") image = camera_input_live() if image is not None: st.image(image) filename = save_image(image) st.sidebar.markdown(f"## Captured Images") st.sidebar.markdown(f"- [{filename}](./{filename})") # QR Code Detection detector = cv2.QRCodeDetector() bytes_data = image.getvalue() cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR) data, bbox, straight_qrcode = detector.detectAndDecode(cv2_img) if data: st.write("# Found QR code") st.write(data) with st.expander("Show details"): st.write("BBox:", bbox) st.write("Straight QR code:", straight_qrcode) if __name__ == "__main__": main()