Cv2 does not detect and decode QR-code

Detailed description

I try to create a QR code and decode that using cv2. The tutorials says the exact same below but I could not reproduce the code.

The problem persists for both small and large data. I looked any tutorials but any does not work. I have attached a small code for your information.

Thank you

Steps to reproduce

import cv2 import qrcode import matplotlib.pyplot as plt

Create a QR code

test = “Hello World”

qr = qrcode.QRCode( version=None, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=5, border=1, )

qr.add_data(test) qr.make(fit=True) img = qr.make_image(fill_color=“white”, back_color=“black”) img.save(“test.png”)

plot the generated QR code

im = plt.imread(“test.png”) implot = plt.imshow(im)

Read and Decode the QR code

img = cv2.imread(“test.png”) qcd = cv2.QRCodeDetector() retval, decoded_info, points, straight_qrcode = qcd.detectAndDecodeMulti(img) print(retval)

Output: False

They said , I need to add margin offset to generated QR code. But none of th tutorial says to add margin and I donot know how to add margin.

Thank you

Actually, your problem is in creating the code, not reading one.

You need to find examples that set the margin. Here’s one:

that code is inverted. invert it again.