← Articles

What camera resolution do you need for DataMatrix? Start from the module size

Camera resolution for reading DataMatrix is counted not in megapixels but in pixels per module — how many sensor pixels fall on one cell of the code. The working minimum is 2 pixels; a reliable margin is 3. From this and the width of the field of view you get how many pixels the sensor needs.

How many pixels per module

  • 1.5 pixels — reads only with perfect print, lighting and geometry, or if the code is captured several times.
  • 2 pixels — the working minimum for a production line with a good decoder.
  • 3 pixels or more — a margin for defocus, glare and weak print.

These thresholds are common machine-vision practice (VA Imaging). The real threshold depends on the decoder. On our conveyor sample (a 704×450 camera, a symbol of about 100 pixels, about 2.4 pixels per module) the free libdmtx read 64 frames out of 300 (21%), while a decoder designed for this kind of imaging read 295 (98%). So test the decoder on your own frames, not by its datasheet.

A small module is fine; a small module with defocus is not

On a sharp synthetic frame the code reads even at 1.4 pixels per module. What limits you is optical blur: the boundary is a defocus σ of about 0.4–0.5 module, whatever the module size. Share of synthetic frames read, %:

Defocus σ, px \ pixels per module1.62.02.53.04.0
0.5100100100100100
1.003391100100
1.50007591

The takeaway for choosing a camera: at 2 pixels per module, focus and depth of field matter more than extra megapixels. If box heights vary on the line, stop down the aperture or go for 3 pixels per module.

Module size and code size

The module (X-dimension) is the side of one cell. Check the X-dimension your marking specification requires: for example, the Russian Chestny ZNAK operator recommends at least 0.255 mm and allows smaller modules if print quality is within the norm (markirovka.ru). The number of modules depends on the length of the data: a long GS1 code with cryptographic fields (76–85 characters, as in Chestny ZNAK) takes 36×36 modules with plain ASCII encoding; a short one fits in 20×20 or 22×22.

So with a 0.33 mm module a long code is a square of about 12 mm, a short one about 7 mm, not counting the quiet zone.

The formula

Sensor width in pixels = field-of-view width × pixels per module / module size:

N(px) = FOV × k / X

Here FOV is the width of the field of view in mm, k is pixels per module and X is the module size in mm. Take the field of view with a margin for how much the code position varies: label offset, boxes placed unevenly on the conveyor.

Examples

SituationField of view, mmModule, mmPixels per modulePixels needed across
Code at a fixed spot on a carton600.333545
The same, at the limit600.332364
Label with position spread1500.3331,364
Code anywhere on a case3000.3321,818
The same, with a margin3000.3332,727
The same, small module3000.25533,529

In practice: for a code at a known spot a 1–1.3 MP camera is enough. To find the code anywhere across a case you need a 5 MP camera or better (2448 pixels across) — or a decoder that works reliably at 2 pixels per module. The difference between 2 and 3 pixels is the difference in camera price and in data volume per frame.

Motion: exposure and shutter

On a moving conveyor, motion blur eats pixels as surely as low resolution. Blur during exposure = speed × exposure time; keep it under half a module — that leaves a margin for defocus and weak print. On a sharp frame our decoder read every code in synthetic tests with 1.25 modules of blur, 83% at 1.5 and 25% at 2 modules.

Exposure, µsBlur at 0.5 m/s, mmShare of a 0.33 mm module
500.0250.08
1000.050.15
2000.10.3
5000.250.76 — no margin

A short exposure needs bright pulsed lighting. A moving line needs a global shutter: a rolling shutter distorts the geometry of the code and suits only stationary objects.

Camera selection checklist

  1. Get the module size from the print template, not from the code size in millimetres.
  2. Measure how much the code position varies on the line and add a margin — that is your field of view.
  3. Calculate the pixels with the formula for k = 3 and k = 2.
  4. Calculate the exposure from the line speed and check there is enough light.
  5. Test the decoder on real frames from the line, not on a test print.

Try it

The libscanner reader library is built for GS1 DataMatrix at two pixels per module. On 12,315 frames from a running conveyor it read 98.4%, with a median of 11 ms per frame and a 90th percentile of 13 ms; surfaces are flat or a label on a cylinder curving up to 90°. Upload a frame from your line to the online scanner, install the Python package with pip install libscanner-dmr or get the library on GitHub.

Chestny ZNAK is a trademark of CRPT LLC (ООО «Оператор-ЦРПТ»); GS1 is a trademark of GS1 AISBL. The product is not affiliated with or certified by their owners.