Comments (3)
I used the zxing online decoder https://zxing.org/w/decode.jspx and it works fine, so I want to know if I'm doing something wrong
It certainly doesn't look like the contents of your barcode are valid UTF-8: a lot of it appears to be horribly mangled.
… or it is a bug.
It's mainly a bug in how the ZXing command-line runner (which this Python module relies on as a wrapper script!) handles its output: namely, it mangles bytes that aren't validly encoded… and the encoding it targets depends on the operating system being used.
On Windows, this mostly works, because the default encoding can reversibly encode and decode unknown bytes, but on Linux it's UTF-8, where certain byte sequences are invalid, and they get mangled by the ZXing Java command-line-runner to an extent that the Python wrapper can't recover them.
See #17 (comment), specifically points (2) and (3) for more thoughts:
- The ZXing command-line-runner mangles the output of raw bytes beyond recognition on some operating systems, if they can't be correctly interpreted as UTF-8. For example, the QR code you give as an example gets completely borked on Linux. (I'm guessing you're testing on Windows?) See aff3dde where I added your file as an example, along with some other possible changes:
…- In order to improve this situation, the ZXing command-line runner would have to be improved to not mangle unknown bytes.
One possible fix for this is #19.
from python-zxing.
It's possible to use non-default encodings in PDF-17 (and other 2D barcodes like QR or DataMatrix), but you're at the mercy of having encoding and decoding and wrapping software that understands how to do this exactly right… and most of it doesn't.
I'll make the immodest claim that I understand and care about this better than almost anyone in the world, and have contributed code to the Java ZXing library to improve the correctness of its handling of nonstandard character sets (see zxing/zxing#1328, zxing/zxing#1330), but I haven't had time to improve the CommandLineRunner's output.
from python-zxing.
I'm coming here because of the same problem - trying to decode example barcodes from Deutsche Bahn (https://www.bahn.de/angebot/regio/barcode, there's a zip folder "Muster-Tickets nach UIC 918.9 (ZIP, 2 MB)"). The Aztec code contains no valid utf-8 - most of it is in zip format. So to process it, the library needs to return the bytes in the raw content to be useful here.
Patching the __init__.py
file at line 189 to return the bytes as string like this makes it possible to see the content and it is consistent with barcode scanning apps. (I'm using similar hacks whenever I need to paste the aztec code into web pages)
try:
raw = raw[:-1].decode()
parsed = parsed[:-1].decode()
except UnicodeDecodeError:
raw = ' '.join(f"{i:>02x}" for i in raw[:-1])
parsed = ""
It would be useful if an optional parameter switches the raw result to bytes and turns off any parsing attempts.
from python-zxing.
Related Issues (20)
- Cannot install from tarball HOT 1
- Command-line interface HOT 4
- data matrix generator HOT 1
- Fix TravisCI test failure for python 3.7, 3.8
- read multiple barcodes? HOT 3
- raw and parsed decode compatibility with ZXing HOT 5
- Use jpype for wrapper? HOT 2
- how to get rawByte from qr code? HOT 2
- How to input image array instead of filename to read QR code? HOT 3
- How to get QR Code version, error correction level, and mask? HOT 4
- Can't find the code when there are other content in the image HOT 1
- Different results from online decoder HOT 2
- ZXing does not decode some QR images HOT 2
- UnboundLocalError: local variable 'bc' referenced before assignment HOT 4
- Issues in decoding PDF 417 format Barcodes HOT 2
- Can't install ZXing - FileNotFoundError "requirements.txt" HOT 13
- what's the difference between raw and parsed results? HOT 1
- Java binary specified does not exist HOT 2
- utf-8 encoding problem, ???????? instead of Thai letters HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-zxing.