Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not decode qrcode in binary #1044

Open
2 of 4 tasks
cosing opened this issue Nov 8, 2024 · 0 comments
Open
2 of 4 tasks

Can not decode qrcode in binary #1044

cosing opened this issue Nov 8, 2024 · 0 comments

Comments

@cosing
Copy link

cosing commented Nov 8, 2024

Expected behaviour

qrCodeDetector.detectAndDecode()[0] should be bytes.

same issue:https://stackoverflow.com/questions/77150620/opencv-is-there-a-way-to-decode-qrcode-in-binary-rather-than-string

Actual behaviour

use qr_output.py

import qrcode

qr = qrcode.QRCode(
    version=9,
    error_correction=qrcode.constants.ERROR_CORRECT_L,  # 最低纠错级别,存储最大数据量
)

binary_data = b'\x30' * 230  # 256 字节的序列重复 11 次,总共 2,816 字节
binary_data = bytes(range(127, -1, -1))+bytes(range(128, 256, 1))
print(binary_data)
qr.add_data(qrcode.util.QRData(binary_data, mode=1 << 2))

qr.make(fit=True)

img = qr.make_image(fill_color="black", back_color="white")
img.save("output_qr.png")

then use qr_input

from PIL import Image, ImageDraw, ImageFont
from pyzbar.pyzbar import decode, Decoded, Rect

def get_qr(image: Image.Image) -> Decoded:
    result = decode(image)
    if len(result) != 1:
        print("multy qr code")
    result = result[0]
    return result

qrcode_filename = r"output_qr.png"

ori_image = Image.open(qrcode_filename)
qr_info = get_qr(ori_image)
print(qr_info)

import cv2

print(cv2.__version__)
qrcode_image = cv2.imread(qrcode_filename)
qrCodeDetector = cv2.QRCodeDetector()
a = qrCodeDetector.detectAndDecode(qrcode_image)

print(type(a[0]))

out:

4.7.0
('\x7f~}|{zyxwvutsrqponmlkjihgfedcba`_^]\\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)(\'&%$#"! \x1f\x1e\x1d\x1c\x1b\x1a\x19\x18\x17\x16\x15\x14\x13\x12\x11\x10\x0f\x0e\r\x0c\x0b\n\t\x08\x07\x06\x05\x04\x03\x02\x01', array([[[ 40.,  40.],
        [609.,  40.],
        [609., 609.],
        [ 40., 609.]]], dtype=float32), array([[  0,   0,   0, ...,   0,   0,   0],
       [  0, 255, 255, ..., 255, 255,   0],
       [  0, 255,   0, ...,   0, 255,   0],
       ...,
       [  0, 255,   0, ...,   0, 255, 255],
       [  0, 255, 255, ...,   0, 255, 255],
       [  0,   0,   0, ...,   0, 255,   0]], dtype=uint8))


}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"! 
       
<class 'str'>

stop in \x00

Steps to reproduce

  • example code
  • operating system
    • Windows 10 Enterprise LTSC 21H2
  • architecture (e.g. x86)
    • x86
  • opencv-python version
    • 4.7.0
Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
  • I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • I'm using the latest version of opencv-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant