Skip to content

Support decoding of binary QR codes#82

Open
KlaasJelmer wants to merge 3 commits into
NaturalHistoryMuseum:masterfrom
KlaasJelmer:master
Open

Support decoding of binary QR codes#82
KlaasJelmer wants to merge 3 commits into
NaturalHistoryMuseum:masterfrom
KlaasJelmer:master

Conversation

@KlaasJelmer

Copy link
Copy Markdown

When the ZBar decoder encounters binary data, it guesses the data encoding while converting it to text. This behavior destroys other types of data.

Version 0.23.1 of the ZBar library supports decoding binary QR codes using configuration option ZBAR_CFG_BINARY. This PR allows settings this flag from the decode() function

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.2%) to 97.877% when pulling 2b12b68 on KlaasJelmer:master into 833b375 on NaturalHistoryMuseum:master.

outofmemo pushed a commit to outofmemo/pyzbar that referenced this pull request Apr 18, 2021
libzbar support raw binary data since 0.23.1. See more: mchehab/zbar@59e0ed1

Refer to KlaasJelmer's modification to add configuration option ZBAR_CFG_BINARY to pyzbar. See more: NaturalHistoryMuseum#82
And modify the conversion method of symbol data to support binary data.
@nmccann nmccann mentioned this pull request Nov 17, 2021
@maglub

maglub commented Apr 17, 2024

Copy link
Copy Markdown

Is there a good way to get attention to this pull request?

This would be quite a nice and useful workaround for issues in Europe, where the base library zbar mis-interprets the encoding:

My workaround for now is the following, which could be avoided if one could just get the binary representation of the QR codes:

  try:
    logging.info("  - Trying the ugly workaround to re-encode utf-8 to big5, then back to utf-8")
    logging.info(res[0].data.decode('utf-8').encode('big5'))
    return res[0].data.decode('utf-8').encode('big5').decode('utf-8')
  except:
    logging.info("  - Re-encoding failed, so the qrcode is probably ok already in utf-8")
    logging.info(res[0].data.decode('utf-8'))
    return res[0].data.decode('utf-8')

@pauuser

pauuser commented May 9, 2024

Copy link
Copy Markdown

Getting the same issue. Hope this pull request gets more attention as soon as possible!

@DogFortune

Copy link
Copy Markdown

I have the same problem and am having trouble. I strongly hope that this PR will get some attention.

@douzebis

douzebis commented May 8, 2025

Copy link
Copy Markdown

Please could we get this PR merged into the master?
Or maybe an explanation what this is not possible at the moment?
Thank you!

@arpruss

arpruss commented Jan 14, 2026

Copy link
Copy Markdown

Even with this PR, binary support is incomplete: null bytes are treated as string terminators.

@tadeubas

tadeubas commented Feb 7, 2026

Copy link
Copy Markdown

Created a fork with this PR and a new tag v0.1.10. To use:
pyzbar @ git+https://github.com/tadeubas/pyzbar@v0.1.10

For Poetry use:
pyzbar = { git = "https://github.com/tadeubas/pyzbar", tag = "v0.1.10"}

@tadeubas

tadeubas commented Feb 7, 2026

Copy link
Copy Markdown

Even with this PR, binary support is incomplete: null bytes are treated as string terminators.

Something is wrong with your setup, tested here and it does output nul bytes like b"ABC\x00DEF". You just need to use: pyzbar.decode(frame, binary=True)

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

Successfully merging this pull request may close these issues.

10 participants