Problem with scanning a bigger size QR code

I beg for someone assistance, as I am totally lost and helpless with this problem.
I have the following QR code:

qrkodsaracuna

I have the following code in Python:

import cv2
import numpy as np

inputImage = 'qrkodsaracuna.png'
image = cv2.imread(inputImage)
detector = cv2.QRCodeDetector()
decodedText, points, _ = detector.detectAndDecode(image)
print('Regular scan: ', inputImage, decodedText, len(decodedText))
if len(decodedText) == 0:
    mirror_image = cv2.flip(image, 1)
    decodedText, points, _ = detector.detectAndDecode(mirror_image)
    print('Inverted scan: ', inputImage, decodedText, len(decodedText))

Output is:
python qrcode.py
Regular scan: qrkodsaracuna.png 0
Inverted scan: qrkodsaracuna.png 0

Decoding of the code has failed, both in regular and flipped versions.

This QR code is properly scanned by phone and it returns stored URL.
I would appreciate if anyone offered any idea how to read this QR code.

Thanks a lot!

image needs a “quiet zone” of about one “module”. codes are unrecognizable without it.

use copyMakeBorder to add some to your image. do this only to codes you produced like this. do not do this to actual pictures of QR codes.

the quiet zone is always required, in particular when printing the code and cropping the printout before sticking it to something.

Here is updated version of the code:

import cv2
import numpy as np

# Load the image
inputImage = 'qrkodsaracuna.png'
image = cv2.imread(inputImage)

# Define the border size (quiet zone). A typical quiet zone is 4 modules (or squares) wide,
# but you can adjust based on the size of your QR code.
quiet_zone_size = 10  # Change this size depending on the QR code size and scaling

# Add a white border (quiet zone) around the image
image_with_border = cv2.copyMakeBorder(
    image,
    top=quiet_zone_size,
    bottom=quiet_zone_size,
    left=quiet_zone_size,
    right=quiet_zone_size,
    borderType=cv2.BORDER_CONSTANT,
    value=[255, 255, 255]  # White color for the border
)

# QR code detection
detector = cv2.QRCodeDetector()
decodedText, points, _ = detector.detectAndDecode(image_with_border)
print('Regular scan: ', inputImage, decodedText, len(decodedText))

And it works!
However this only solves half of my problem.
The file which I provided was a perfect image of a QR code.
In reality, I will be scanning the codes from the paper and trying to read it.
Actually, real life code looks like this:

And I will be reading it from laptop or phone camera.
Here is my current code for this:

def detect_qr_code(self, frame):

        quiet_zone_size = 10
        
        frame = cv2.copyMakeBorder(
            frame,
            top=quiet_zone_size,
            bottom=quiet_zone_size,
            left=quiet_zone_size,
            right=quiet_zone_size,
            borderType=cv2.BORDER_CONSTANT,
            value=[255, 255, 255]  # White color for the border
        )
        # Initialize the QRCode detector
        detector = cv2.QRCodeDetector()

        # Detect and decode the QR code in the given frame
        data, bbox, _ = detector.detectAndDecode(frame)

        # Check if there is a QR code in the frame
        if bbox is not None:
            bbox = bbox.astype(int)  # Ensure bbox is an integer type
            # Display the image with lines
            for i in range(len(bbox)):
                # Draw all lines around the QR code
                pt1 = tuple(bbox[i][0])
                pt2 = tuple(bbox[(i+1) % len(bbox)][0])
                cv2.line(frame, pt1, pt2, color=(255, 0, 0), thickness=2)

            if data:
                print(f"[+] QR Code detected, data: {data}")
                #self.ids.qr_code_result.text = f"QR Code Data: {data}"
                time.sleep(3)
            else:
                print(f"QR Code detected but no data found.")
                #self.ids.qr_code_result.text = "QR Code detected but no data found."
        else:
            #self.ids.qr_code_result.text = "No QR code detected."
            pass

Code above is still not able to properly read this QR. :frowning:
I am not sure if I was supposed to apply the quiet zone in this code, as you said " do not do this to actual pictures of QR codes.".

I would kindly ask for help in reading this, as this is my real life usecase.

Thanks a lot!

End result:

After trying out several public libraries other then OpenCV, I concluded that none of them can handle specific QR codes which I am working with. Poor quality of print, bad paper, bad lighting… all lead to failure of scanning.

I had no other choice then to try out a commercial library which amazingly somehow bypassed all the obstacles and read all the QR codes which I tried, no matter how bad was the print, how wrinkled was the paper, how bad was the lighting etc.