-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
48 lines (40 loc) · 1.57 KB
/
Copy pathapp.py
File metadata and controls
48 lines (40 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
pip install streamlit opencv-python-headless pyzbar numpy pillow
import streamlit as st
import os
import cv2
import numpy as np
from pyzbar.pyzbar import decode
from PIL import Image
# Function to decode QR codes
def decode_qr(image):
qr_info = decode(image)
decoded_data = []
for qr in qr_info:
data = qr.data.decode('utf-8')
rect = qr.rect
polygon = qr.polygon
decoded_data.append((data, rect, polygon))
# Draw rectangle and polygon on the image
image = cv2.rectangle(image, (rect.left, rect.top), (rect.left + rect.width, rect.top + rect.height),
(0, 255, 0), 2)
image = cv2.polylines(image, [np.array(polygon)], True, (255, 0, 0), 2)
return image, decoded_data
# Streamlit app
st.title("QR Code Decoder")
uploaded_file = st.file_uploader("Choose an image", type=["png", "jpg", "jpeg"])
if uploaded_file is not None:
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
img = cv2.imdecode(file_bytes, 1)
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Decode QR code
decoded_img, decoded_data = decode_qr(img)
st.image(img_rgb, caption='Uploaded Image', use_column_width=True)
st.image(decoded_img, caption='Decoded Image with Annotations', use_column_width=True)
st.subheader("Decoded Data")
if decoded_data:
for data, rect, polygon in decoded_data:
st.text(f"Data: {data}")
st.text(f"Rectangle: {rect}")
st.text(f"Polygon: {polygon}")
else:
st.text("No QR code found in the image.")