Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,46 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
-
from camera_input_live import camera_input_live
|
4 |
-
|
5 |
-
#image = camera_input_live()
|
6 |
-
|
7 |
-
#if image:
|
8 |
-
# st.image(image)
|
9 |
-
|
10 |
import cv2
|
11 |
import numpy as np
|
12 |
-
import
|
|
|
13 |
from camera_input_live import camera_input_live
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
17 |
|
18 |
-
image
|
19 |
-
|
20 |
-
if image is not None:
|
21 |
-
st.image(image)
|
22 |
bytes_data = image.getvalue()
|
23 |
cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
st.write(data)
|
32 |
-
with st.expander("Show details"):
|
33 |
-
st.write("BBox:", bbox)
|
34 |
-
st.write("Straight QR code:", straight_qrcode)
|
35 |
-
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
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):
|
9 |
+
# Generate a timestamped filename
|
10 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
11 |
+
filename = f"captured_image_{timestamp}.png"
|
12 |
|
13 |
+
# Convert the image to OpenCV format and save
|
|
|
|
|
|
|
14 |
bytes_data = image.getvalue()
|
15 |
cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
|
16 |
+
cv2.imwrite(filename, cv2_img)
|
17 |
+
|
18 |
+
return filename
|
19 |
+
|
20 |
+
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()
|
|
|
|
|
|
|
|
|
|