Python Forum

Full Version: QR code creation with image
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to create QR code for the image , the result should be, after scanning the QR it should display image. The error message in QR generation is : Invalid version (was 41, expected 1 to 40)
the code is below, can anyone help to find the error in my code
import cv2
import numpy as np
import qrcode
import zlib
import base64

#Read The Image
img=cv2.imread("photo.jpg")

#encode the image to Numpy Array
_,imgencoded=cv2.imencode(".jpg",img,[cv2.IMWRITE_JPEG_QUALITY, 20] )


#Convert to bytecode
imgbc=imgencoded.tobytes()

# Compress the data
compressed_data = zlib.compress(imgbc)

# Encode compressed data as Base64
base64_data = base64.b64encode(compressed_data).decode('ascii')

#Generate QR code
qr=qrcode.QRCode(
    version=None,
    error_correction=qrcode.constants.ERROR_CORRECT_Q,
    box_size=20,
    border=4,
    )
qr.add_data(base64_data)
qr.make(fit=True)
# Specify the filename and path where you want to save the QR code image
qr_image_path = 'E:/photo2.png' 
# Create an image from the QR Code instance
qr_image = qr.make_image(fill='black', back_color='white')

# Save the QR code image
qr_image.save(qr_image_path)
print(f"QR Code image saved to {qr_image_path}")
perhaps this will help.