Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QR code creation with image
#1
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}")
Larz60+ write Jan-15-2025, 11:15 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Tags added this time. Please user BBCode tags on future posts.
Reply
#2
perhaps this will help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  New2Python: Help with Importing/Mapping Image Src to Image Code in File CluelessITguy 0 1,245 Nov-17-2022, 04:46 PM
Last Post: CluelessITguy
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 2,717 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Correct the algorithm of image filter code saoko 6 3,473 May-08-2022, 05:06 PM
Last Post: saoko
  code decode, string, image ... teckow 2 2,819 Aug-20-2021, 07:02 PM
Last Post: teckow
  [split] Kera Getting errors when following code example Image classification from scratch hobbyist 3 5,637 Apr-13-2021, 01:26 PM
Last Post: amirian
  I need a code line to spam a keyboard key | Image detection bot Aizou 2 4,606 Dec-06-2020, 10:10 PM
Last Post: Aizou
  Help me get this image converter code working? NeTgHoSt 0 2,754 Jul-14-2020, 10:36 PM
Last Post: NeTgHoSt
  upload image with generated code from Postman does not work magic7598 0 2,255 Nov-30-2019, 10:32 AM
Last Post: magic7598
  Where is the error with this db creation code & the 'conn' variable? pcsailor 6 4,678 Nov-11-2018, 10:25 AM
Last Post: pcsailor
  Code review for S3 object creation beherap 0 2,730 Mar-29-2018, 01:31 PM
Last Post: beherap

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020