Spaces:
Runtime error
Runtime error
File size: 974 Bytes
01fd29f 5a24b2d 01fd29f 5a24b2d 01fd29f 5a24b2d c658e07 01fd29f 5a24b2d b189d2c 5a24b2d b189d2c 5a24b2d b189d2c |
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 gradio as gr
import cv2
from pyzbar.pyzbar import decode
import numpy as np
def qr_barcode_scanner(image):
# Convert PIL image to numpy array
image_data = np.array(image)
# Convert RGB to grayscale if needed
if len(image_data.shape) == 3 and image_data.shape[2] == 3:
image_data = cv2.cvtColor(image_data, cv2.COLOR_RGB2GRAY)
# Decode QR codes and barcodes
decoded_objects = decode(image_data)
if len(decoded_objects) == 0:
return "No QR code or barcode found."
results = []
for obj in decoded_objects:
data = obj.data.decode("utf-8")
results.append(f"Type: {obj.type}, Data: {data}")
return "\n".join(results)
iface = gr.Interface(
fn=qr_barcode_scanner,
inputs=gr.inputs.Image(type="pil", label="Select an image containing QR code or barcode."),
outputs=gr.outputs.Textbox(),
live=True,
capture_session=True,
interpretation="default"
)
iface.launch(share=True)
|