awacke1 commited on
Commit
57034fc
1 Parent(s): 40280ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -20
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
- image = camera_input_live()
25
-
26
- if image is not None:
27
- st.image(image)
28
- filename = save_image(image)
29
- st.sidebar.markdown(f"## Captured Images")
30
- st.sidebar.markdown(f"- [{filename}](./{filename})")
31
-
32
- # QR Code Detection
33
- detector = cv2.QRCodeDetector()
34
- bytes_data = image.getvalue()
35
- cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
36
- data, bbox, straight_qrcode = detector.detectAndDecode(cv2_img)
37
-
38
- if data:
39
- st.write("# Found QR code")
40
- st.write(data)
41
- with st.expander("Show details"):
42
- st.write("BBox:", bbox)
43
- st.write("Straight QR code:", straight_qrcode)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()