File size: 961 Bytes
0b554f6
 
 
 
 
8b3c2b9
 
0b554f6
8b3c2b9
 
0b554f6
8b3c2b9
 
 
 
 
 
 
 
 
0b554f6
 
 
 
 
 
8b3c2b9
 
0b554f6
8b3c2b9
0b554f6
 
 
 
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
import cv2
import numpy as np
import gradio as gr
from PIL import Image

def read_qr_code(image):
    """Reads QR Code from an uploaded image using OpenCV."""
    try:
        # Convert image to OpenCV format
        image = np.array(image.convert("RGB"))
        gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

        # Initialize OpenCV QR Code detector
        detector = cv2.QRCodeDetector()
        data, _, _ = detector.detectAndDecode(gray)

        if data:
            return f"QR Code Data: {data}"
        else:
            return "No QR Code found."
    
    except Exception as e:
        return f"Error: {str(e)}"

# Gradio Interface
interface = gr.Interface(
    fn=read_qr_code,
    inputs=gr.Image(type="pil", label="Upload QR Code Image"),
    outputs=gr.Textbox(label="Scan Result"),
    description="Upload an image containing a QR Code to scan and retrieve its data.",
    css="footer {visibility: hidden}"
)

interface.launch(share=True)