Can not decode qrcode in binary
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 1k
- Avg merge
- 22h 17m
- Merged PRs (30d)
- 3
Description
Expected behaviour
qrCodeDetector.detectAndDecode()[0] should be bytes.
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the qr_output.py and qr_input reproduction and verify the reported opencv-python version. Check the repository README and issue checklist first: they indicate this repository contains only the Python package build toolchain, while the requested QR decoding behavior belongs in OpenCV itself; done would require confirming the correct upstream location for the feature.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- opencv, python
- Domain
- computer-vision
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100