Using Data Matrix or QR Code to encode/decode JSON in consideration of scan performance

2,478 views
Skip to first unread message

Tobias J.

unread,
Feb 20, 2015, 4:06:42 AM2/20/15
to zx...@googlegroups.com
Hi folks,

I want to encode a long string (more precisely JSON, 600 - 800 chars) into a 2D bar code and did some tests with Data Matrix and QR Code. I want to decode the bar code with a Smartphone. My feeling is that QR Code is faster recognized and decoded by ZXing. Can someone confirm that?

To become more general. Does one of the codes better suits my needs especially with regard to the content, the size of the code and the scan rate of ZXing?

To be honest I am developing a Cordova based application and I use the Cordova plugin com.phonegap.plugins.barcodescanner (https://github.com/wildabeast/BarcodeScanner/) which internally uses ZXing (and ports like ZXing.Net). My mentioned feeling that QR Code recognition seems to be faster than the recognition of Data Matrix is based on a Windows Phone (so the ZXing.Net port) but my Cordova based application also targets iOS and Android which uses XZing.

I would really appreciate it if some people tell me their experiences with much text encoded in Data Matrix and/or QR Code and the decoding with ZXing.

Greetings from Germany,

Tobias

Sean Owen

unread,
Feb 20, 2015, 8:13:03 AM2/20/15
to zx...@googlegroups.com
Probably better with QR codes, but you should test it. This is a lot of data to put into a QR code. You can probably scan it but with some trouble. I would generally avoid this and try to design a system that encodes URLs of data on the web. Otherwise try to make your JSON as compact as possible

Tobias J.

unread,
Feb 20, 2015, 8:21:57 AM2/20/15
to zx...@googlegroups.com
Hi Sean. Thanks for your quick reply! Our Barcode will be printed on theater tickets and we want to validate the data offline on smartphones. The JSON is as compact as possible (property names consist of one or two chars for example) and to validate it offline the data is RSA signed.

You said that 600 - 800 characters are a lot of data to put into a QR code. Different sources tells me that the maximum capacity of alphanumeric characters in a QR code is 4.296 and we are far away from that technical limit. Is it a question of recognition or decode time or simply a question of the size the code will get with much data?

Sean Owen

unread,
Feb 20, 2015, 9:07:56 AM2/20/15
to zx...@googlegroups.com
Max capacity is indeed ~4K characters if you use only the alphanumeric subset of characters. For general text it's more like 3K characters. However, that means using the densest possible QR code, which is not scannable in normal usage. Anything more than version 10 starts to get a little tricky to scan (~130 chars) and beyond version 20 I would not consider it normally usable (~380 chars). But, try it out. You might consider making a simple custom text encoding that only uses the alphanumeric subsets and uses some simple delimiting scheme instead of JSON. That might keep you well under version 20.

solon

unread,
Mar 3, 2015, 11:06:13 AM3/3/15
to zx...@googlegroups.com
Tobias Jamin於 2015年2月20日星期五 UTC+8下午5時06分42秒寫道:
Hi Tobias,

I have also done some works on embedding a lot of characters (>2,000) into a QR code and adding digital signature to the QR code.
From my experience, although the QR code standard allows storing 4,xxx characters into a QR code, in reality it is difficult to scan QR codes with version over 20 (~1000 alphanumeric or ~800 bytes of UTF-8 text).
The first problem is that the data modules are too small.
As the decoding algorithm assumes the QR code is printed on a 2D plane, a fold on the paper holding the QR code will displace the data modules and may make the scanner unable to read the modules correctly.
For normal QR codes we use today, as the modules are big, this kind of error can be ignored. For QR codes with version 20 or above, successful scanning usually comes from luck.
Hard-shaking makes the problem worse, you need to be very stable to take a clear image of the modules, especially when you save over 3,000 characters into a QR code.
One way to improve the performance is to detect the alignment patterns as references. It helps for QR codes with version 20-30. For version 30 or above, I am still looking for a robust method.

For the digital signature, we need to base64 encode the signature before embedding it into the QR code. For 1,024 bits RSA signature, it takes ~180 bytes. ECDSA may be a better option (supported from Android 4 and takes ~30 bytes only).

You may also consider saving some of the data in the scanner App to reduce the content of the QR code.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages