File size: 1,062 Bytes
ed5b198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import cv2
import numpy as np
from pyzbar.pyzbar import decode
from PIL import Image

def decode_barcode(image):
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    barcodes = decode(gray)
    results = []
    for barcode in barcodes:
        barcode_data = barcode.data.decode("utf-8")
        barcode_type = barcode.type
        results.append(f"Type: {barcode_type}, Data: {barcode_data}")
    return results

st.title("Barcode Scanner App")
st.write("Upload an image with a barcode to scan.")

uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])

if uploaded_file is not None:
    image = Image.open(uploaded_file)
    img_np = np.array(image)
    img_bgr = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
    
    st.image(image, caption="Uploaded Image", use_column_width=True)
    
    results = decode_barcode(img_bgr)
    
    if results:
        st.success("Barcodes Found:")
        for res in results:
            st.write(res)
    else:
        st.warning("No barcode detected. Try another image.")