ZBar utf-8 decoding (Python)

Help
felix
2012-03-27
2013-02-02
  • felix

    felix - 2012-03-27

    I am using ZBar with Python bindings. I ran into an issue where I can not properly decode UTF-8 encoded QR Codes.

    For example, instead of  'Überscanner' = '\xc3\x9cberscanner' I get '\xef\xbe\x83\xef\xbd\xbcberscanner'

    Can I somehow tell ZBar (or modify the code) so that it uses utf-8 or gives me the raw data? I could easily do proper decoding in Python.

    Or is there a way to reverse encode it?

    btw see this question/discussion on utf-8 in qr codes:
    http://stackoverflow.com/questions/9699657/is-utf-8-the-encoding-of-choice-for-qr-codes-with-non-ascii-chars-by-now/

    And in case you are interested: http://qr-code-scanner.com (maybe some of the scanners here use ZBar?)

     
  • felix

    felix - 2012-03-28

    not pretty but does the job….  

    try:
        utf8Data = symbol.data.decode("ascii")
    except UnicodeDecodeError:
        utf8Data = symbol.data.decode("utf-8").encode("sjis")
    print utf8Data.decode("utf-8")

    note: I know only ascii or utf-8 goes in and the whole thing is only used for validation

    I really think zbar should default to utf-8 even if it is against the spec. At least there should be an option. Even the google qr code api uses utf-8 as default encoding without a BOM - currently not readable with zbar.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks