I believe I can successfully encode binary data as a QR code, but I'm struggling to decode that data.
The top answer to this question suggests that QR code readers generally have issue decoding binary data:
The problem comes from the decoding. Because most decoders will try to interpret it as text. But since it's binary data, you should not try to handle it as text. Even if you think you can convert it from text to binary, as you saw this may cause issues with values which are not valid text.
How true is this for Python packages? I've tried using pyzbar
and opencv
's but to I've had no success (they work fine for utf-8
strings). I'm also struggling to find useful documentation for pyzbar, while opencv's is not fruitful.
For completeness, here's an example QR code that I've created.
data = b'\x00\x00\x00\x00\x00\x00\x00\x00\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00\x84\x00\x03\x02\x02\n\n\n\n\n\n\n\n\n\n\n\n\x08\x08\n\n\n\n\x08\x08\n\x08\x08\x08\x08\x08\x08\x08\x08\x08\n\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\n\x08\x08\x08\x08\n\n\n\x08\x08\r\r\n\x08\r\x08\x08\n\x08\x01\x03\x04\x04\x06\x05\x06\n\x06\x06\n\x0f\x0e\x0b\r\x0f\x0f\x0f\x0f\x10\x10\x0f\x0f\x0f\x0f\x0f\x0f\x0f\r\r\r\x0f\r\x0f\x0f\x0f\r\r\r\r\x0f\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\xff\xc0\x00\x11\x08\x01@\x02\x00\x03\x01\x11\x00\x02\x11\x01\x03\x11\x01\xff\xc4\x00\x1d\x00\x00\x02\x03\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x04\x05\x02\x03\x06\x01\x07\x00\x08\t\xff\xc4\x00C\x10\x00\x02\x01\x02\x04\x04\x03\x05\x06\x06\x01\x03\x03\x03\x05\x00\x01\x02\x11\x00\x03\x04\x12!1\x05\x06"AQaq\x07\x132\x81\xf0\x14\x91\xa1\xb1\xc1\xd1\x08\x15#B'
To generate the QR code from this byte string, I use the segmo
library, as so:
qr = segno.make(data)
qr.save(path/to/output/file)
Here is the resulting QR code:
