Dua Rajper commited on
Commit
ed5b198
·
verified ·
1 Parent(s): 2cbd6b6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ from pyzbar.pyzbar import decode
5
+ from PIL import Image
6
+
7
+ def decode_barcode(image):
8
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
9
+ barcodes = decode(gray)
10
+ results = []
11
+ for barcode in barcodes:
12
+ barcode_data = barcode.data.decode("utf-8")
13
+ barcode_type = barcode.type
14
+ results.append(f"Type: {barcode_type}, Data: {barcode_data}")
15
+ return results
16
+
17
+ st.title("Barcode Scanner App")
18
+ st.write("Upload an image with a barcode to scan.")
19
+
20
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
21
+
22
+ if uploaded_file is not None:
23
+ image = Image.open(uploaded_file)
24
+ img_np = np.array(image)
25
+ img_bgr = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
26
+
27
+ st.image(image, caption="Uploaded Image", use_column_width=True)
28
+
29
+ results = decode_barcode(img_bgr)
30
+
31
+ if results:
32
+ st.success("Barcodes Found:")
33
+ for res in results:
34
+ st.write(res)
35
+ else:
36
+ st.warning("No barcode detected. Try another image.")