Read QR Codes with High Density

QR code can store much more data than 1D code. But do you know how much data it can represent?

Here is a quote from wikipedia1:

The amount of data that can be stored in the QR code symbol depends on the datatype (mode, or input character set), version (1, …, 40, indicating the overall dimensions of the symbol, i.e. 4 × version number + 17 dots on each side), and error correction level.

In simple terms, a QR code can store up to 7,089 numbers, 4,296 alphanumeric characters, 2,953 bytes, or 1,817 Japanese Kanjis.

With this capacity, a QR code can even represent a small image. For instance, an enhanced QR code which includes the card holder’s info like name and photo is used on PAN Card, which is promoted by the Indian government.

Example Image of High-density QR Codes

The more data a QR code has to represent, the bigger it becomes. Here we generate two QR codes using the first chapter name and the first three paragraphs of A Tale of Two Cities by Charles Dickens. The error correction level is set to the lowest. The two codes are generated using this online QR code generator: QR Code Generator.

a_tale_of_two_cities_chapter_name

a_tale_of_two_cities_first_three_paragraphs

There is no problem using advanced barcode readers like Dynamsoft Barcode Reader (DBR) (ZXing does not work) to read these images directly.

Try Online Demo

But normally QR codes are printed in a limited area and have to be scanned with a mobile phone. The modules of the printed QR code might be dense and small. The environment conditions may also affect the reading process. In general, there are several aspects to which we can pay attention for better reading.

  • Sufficient light
  • A good camera with high resolution
  • Scan only the code area. The image content will be simpler and clearer when it only contains the QR code. You could put your phone close to the code or place the QR code within a viewfinder (This requires using a higher camera resolution).

The localization and decoding of QR codes rely on sophisticated image processing. It is also recommended to use a high-performance barcode reader like Dynamsoft Barcode Reader.

How to Optimize Dynamsoft Barcode Reader for High-density QR Codes

Let’s try using Dynamsoft Barcode Reader to read QR codes with high density.

The image below has a low resolution and the background is yellowish.

pan_card_cropped_small

Image Preprocessing

The first step is to convert the color to grayscale, smooth, and sharpen the image with the ImagePreprocessingModes parameter.

"ImagePreprocessingModes": [
  {
	"LibraryFileName": "",
	"LibraryParameters": "",
	"Mode": "IPM_GRAY_SMOOTH",
	"SmoothBlockSizeX": 3,
	"SmoothBlockSizeY": 3
  },
  {
	"LibraryFileName": "",
	"LibraryParameters": "",
	"Mode": "IPM_SHARPEN_SMOOTH",
	"SharpenBlockSizeX": 3,
	"SharpenBlockSizeY": 3,
	"SmoothBlockSizeX": 3,
	"SmoothBlockSizeY": 3
  }
]

We can use DBR’s intermediateResult to see the processed result:

Preprocessed Image

Binarization

The second step is binarization. Dynamsoft Barcode Reader provides two ways for image binarization.

  • One way is to use a threshold for the whole image.
  • The other way divides the image into blocks, calculates the threshold values of these blocks, and does the binarization. This is called adaptive binarization.

Binarization using one threshold for the entire image:

"BinarizationModes": [
  {
	"BinarizationThreshold": -1,
	"LibraryFileName": "",
	"LibraryParameters": "",
	"Mode": "BM_THRESHOLD"
  }
]

Auto threshold

Adaptive binarization:

"BinarizationModes": [
  {
	"BlockSizeX": 6,
	"BlockSizeY": 6,
	"LibraryFileName": "",
	"LibraryParameters": "",
	"Mode": "BM_LOCAL_BLOCK"
  }
]

Adaptive binarization

Since the modules of the example QR code are small and dense, it is better to use an adaptive binarization method using a small block size.

Here is the template to decode the example QR code:

{
  "ImageParameter": {
    "BarcodeFormatIds": [
      "BF_QR_CODE"
    ],
    "BinarizationModes": [
      {
        "BlockSizeX": 6,
        "BlockSizeY": 6,
        "LibraryFileName": "",
        "LibraryParameters": "",
        "Mode": "BM_LOCAL_BLOCK"
      }
    ],
    "Description": "",
    "ExpectedBarcodesCount": 1,
    "ImagePreprocessingModes": [
      {
        "LibraryFileName": "",
        "LibraryParameters": "",
        "Mode": "IPM_GRAY_SMOOTH"
      },
      {
        "LibraryFileName": "",
        "LibraryParameters": "",
        "Mode": "IPM_SHARPEN_SMOOTH"
      }
    ],
    "Name": "Settings",
    "Timeout": 99999
  },
  "Version": "3.0"
}

Normally, with the default balanced settings, DBR can directly read these kinds of QR codes. A customized template like above can have a better result by adapting the parameters to specific situations.

To learn more about DBR’s parameters, visit its documentation.

About Dynamsoft Barcode Reader

Dynamsoft Barcode Reader is fully customizable for the greatest performance just for your business. Advanced users can choose between a long list of parameters, each containing a set of modes. A mode is a special function that the barcode reader can do. Each mode can include a number of arguments, which are used to further refine or customize the application. How to customize Qr code scan settings?

Download Free Trial

References

  1. https://en.wikipedia.org/wiki/QR_code 

Search Blog Posts