Code readingTroubleshooting

Why a QR code is not reading in vision software but scans on a reader

Why a QR code is not reading in your vision software: quiet zone sizes, the 2:1 gray contrast target, 3 pixels per module and a blur budget, with fixes.

LumaSpec VisionLettura 11 min Condividi su LinkedIn

In questa pagina Sezioni 10
  1. 01Why does a handheld scanner read a code my software cannot?
  2. 02How much quiet zone does a DataMatrix or QR code need?
  3. 03How much contrast do the modules need against the background?
  4. 04How many pixels per module does the camera need?
  5. 05How fast can the part move before blur kills the decode?
  6. 06What do the numbers look like on one real line?
  7. 07Can preprocessing rescue a marginal image?
  8. 08Should I fix the lighting instead of the software?
  9. 09When do I stop tuning and use a fixed code reader?
  10. 10Questions

A QR code that scans on the handheld reader but will not decode in your vision software is one of the most common faults on a code-reading line, and it is nearly always an image problem rather than a symbol problem. The scanner brings its own illumination, its own optics and a decoder tuned for marginal symbols; your software gets a raw camera frame and has to find and read the code inside it. This guide gives the four numbers that decide software decode — quiet zone, contrast, pixels per module and blur — the arithmetic to check each one on your own captured image, the preprocessing order that recovers marginal frames, and the point at which you stop tuning and fit a fixed reader instead.

Why does a handheld scanner read a code my software cannot?

Because the scanner never sees your image: it aims its own light and optics at the symbol and runs a decoder tuned for marginal codes, so the quiet-zone, contrast, focus and blur faults that kill a camera decode simply never reach it.

A successful scan proves the symbol was printed within spec. It says nothing about your acquisition. Four faults cover nearly every scanner-reads-it-software-does-not case, in this order of frequency:

  1. Quiet zone contaminated — print, artwork or a label edge sits inside the clear margin.
  2. Contrast too flat — modules and background land too close together in gray value.
  3. Too few pixels per module — the smallest module spans fewer than 3 pixels.
  4. Motion or focus blur — edges smear across more than half a module.

Run the five-minute sequence before touching any decode parameter:

  1. Save the exact failing frame, uncompressed — BMP or PNG, never JPEG. Saving grayscale frames as BMP shows one route from camera to file.
  2. Open it at 400% zoom and look at the margin around the symbol and at the module edges.
  3. Draw a gray line profile across the modules and note the two levels.
  4. Count pixels across the smallest module.
  5. Decode the saved file with a second decoder.
What you see at 400% zoom Cause Fix
Print or an edge inside the clear margin Quiet zone violation Clear 1X (DataMatrix) or 4X (QR) on all four sides
Modules and background within about 2x gray Flat contrast Relight or rework the print toward the 2:1 target
Stair-stepped or ragged module edges Under-sampling or defocus Narrow the field of view and refocus on a target
Edges smeared in one direction Motion blur Cut exposure to the half-module budget

How much quiet zone does a DataMatrix or QR code need?

DataMatrix needs a clear quiet zone of at least one module width (1X) on all four sides — that is the ISO/IEC 16022 requirement — and two modules is the safer design target; QR Code Models 1 and 2 need four modules, and Micro QR needs two.

The quiet zone is not loose white space near the code. It is a defined margin, free of any print or marks, that lets the decoder close the symbol boundary. Camera software searches a whole frame for candidate symbols, so any dark pixel inside the margin competes with the finder pattern. An aimed scanner decodes along the finder track and tolerates a margin eaten on one side, which is exactly why it reads what your software rejects.

A ring or corner marks printed around the symbol do not replace the quiet zone, but they help indirectly: they push text and artwork outside the margin. A label that reads with a frame and fails without one almost always has print sitting in the quiet zone. Keep any frame at least one module width from the finder pattern and leave the ring between frame and symbol unprinted.

For planning the printed area down to the pixel, see QR code quiet zone and integer module scaling. The same margin rule breaks 1D reads too: EAN-13 with an insufficient quiet zone fails for the identical reason.

How much contrast do the modules need against the background?

Target a gray-value ratio of about 2:1 between background and dark modules — a background at gray 200 means modules at 100 or below — and measure it with a line profile across the symbol in the captured image, never on the print artwork.

Print contrast and image contrast are different quantities. Lighting can flatten a well-printed code, when glare washes out the modules, or rescue a poor one, when low-angle light darkens printed marks. The classic trap is colour: a red aiming laser reads black-on-red as high contrast at its own wavelength, while a monochrome camera under white light sees mid-gray on dark. If the label colours are fixed, apply the contrast rules for coloured QR codes a scanner can read before reprinting anything.

Two decode-side causes sit next to contrast. Polarity: most libraries assume dark modules on a light background and need the inverted-polarity option for etched or backlit codes. Exposure: clipping either end of the histogram destroys contrast no later filter can rebuild, so pull exposure back until both peaks sit inside the 20-250 range.

How many pixels per module does the camera need?

At least 3 pixels across the smallest module, 4 to 5 for margin: below 3 the decoder guesses where each module ends, and read rate falls away on the first slightly defocused frame.

px_per_module = module_size x sensor_width_px / field_of_view

The sensor width is the pixel count across the image, and the field of view is what that span covers on the part. A tighter field of view buys sampling faster than a bigger sensor does, which is why the fix for ragged module edges is usually a longer lens or a closer camera, not more megapixels.

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

How fast can the part move before blur kills the decode?

Keep blur below half a module: cap the exposure so part motion during integration stays under 0.5 module widths, and use a global-shutter sensor so the symbol geometry stays square while it moves.

exposure_max = 0.5 x module_size / belt_speed

Defocus spends the same half-module budget, so focus with a ruled target on the belt rather than by eye on the monitor. The full treatment of speed, exposure and read rate is in barcode capture on a moving vehicle, and the strobe path for cameras without a flash control is adding an external strobe when the camera has no LED API.

What do the numbers look like on one real line?

For 0.30 mm DataMatrix modules on a belt running 0.5 m/s, a 2560-pixel camera over a 100 mm field of view delivers 7.7 px per module, a 300 us exposure cap and a 0.60 mm design margin — the whole check takes ten minutes.

  • Sampling: 2560 px / 100 mm = 25.6 px/mm, so 25.6 x 0.30 mm = 7.7 px per module, or 39 um per pixel on the part. That clears the 3-px floor with room for defocus.
  • Quiet zone: minimum 1 x 0.30 = 0.30 mm clear on all four sides, about 8 px; design to 2 x 0.30 = 0.60 mm. A QR Code at the same module size needs 4 x 0.30 = 1.20 mm.
  • Blur: budget 0.5 x 0.30 = 0.15 mm. Exposure cap = 0.15 mm / 500 mm/s = 0.0003 s = 300 us.
  • Lens: with a 2/3-inch sensor 8.8 mm wide, magnification m = 8.8 / 100 = 0.088. At 250 mm working distance, f = 250 x 0.088 / (1 + 0.088) = 20 mm. Check your own pair in the lens focal length calculator.
  • Aperture: diffraction spends the same budget. At f/8 the Airy disc is 2.44 x 0.55 um x 8 = 10.7 um in the image, or 10.7 / 0.088 = 0.12 mm on the part, most of the 0.15 mm allowance. Shoot at f/5.6 (about 0.085 mm) instead.
  • Contrast: histogram peaks near 200 for the background and at or below 100 for the modules, with an empty valley between them.

Every number passes on this line, so a decode failure here points at settings — minimum module size, polarity, search effort — not at optics.

Can preprocessing rescue a marginal image?

Yes, in this order: crop to a region of interest, convert 10- or 12-bit frames to the 8 bits most decoders expect, correct tilt, and downscale heavily oversampled images — this sequence recovers most frames that fail a full-frame decode.

No filter creates a quiet zone that print has eaten, or contrast the sensor never captured. Those are artwork and lighting fixes.

Should I fix the lighting instead of the software?

Fix the light when the image itself is the problem — specular glare off a shiny label, a background drifting toward the module gray value, or a shadow across the symbol — because no decoder setting repairs an image that was never captured.

The first hardware move is a diffused ring light around the lens:

Ring lightsRing light, 120 mm dia., 0°, White (LS-RNG-0426)LS-RNG-0426
Size
100-200 mm
Type
Diffused
Angle
Low angle (0-15°)
Voltage
24 V
$369.00View partBuild a system with it

The LS-RNG-0426 is a diffused white ring light of 120 mm diameter on 24 V, and its 0-degree beam washes over glossy labels instead of glinting off them. Mount it close enough that the part sees the full ring. For mirror-finish surfaces the next step is polarization: the lens-and-light method is in cross-polarization to reduce surface glare, and curved or reflective substrates have their own treatment in reading QR codes on reflective and curved surfaces.

When do I stop tuning and use a fixed code reader?

Stop when the symbol is the limit — damaged, below your sampling floor after the best optics you can fit, or printed at a contrast no lighting rescues — or when decode tuning has already cost more than a shift.

A fixed reader is a camera, lens, light and decoder engineered together, so you buy back the integration time you are spending on thresholds. The build-or-buy line for the decode step itself is drawn in software barcode decode in your own camera app, and if you are weighing dedicated imagers against camera decode, this 2D imager selection guide for QR code reading covers the same trade-offs from the scanner side.

When the image rules are met and the symbol is still the limit, let a purpose-built reader close the gap:

Fixed code readers2560 x 2048 fixed code reader, 30 fps, 60 codes/s, 8 mm lens (LS-CRD-0028)LS-CRD-0028
Interface
Fast Ethernet
Resolution
5 MP
Sensor format
1/1.7"
Shutter
Global
$920.00View part

The LS-CRD-0028 reads up to 60 codes/s at 30 fps from a 2560 x 2048 global-shutter sensor behind an 8 mm lens — sampling headroom that makes a marginal module size someone else's problem. Browse the fixed code readers for other mounts and reading distances.

Two routes take the decode off your PC entirely:

Fixed code readersCompact fixed industrial barcode reader, 1.2 MP, USB 2.0, 60-120 mm reading distance (LS-CRD-0047)LS-CRD-0047
Resolution
Up to 3 MP
Shutter
Global
$559.00View part
Smart cameras & vision sensors1.6 MP smart camera, 60 fps, 16 mm lens, white light (polarized, transparent light) (LS-SMC-0063)LS-SMC-0063
Interface
GigE
Resolution
Up to 3 MP
$1,110.00View part

The LS-CRD-0047 is a compact 1.2 MP reader with a 60-120 mm reading distance for close, stationary codes, and the LS-SMC-0063 is a 1.6 MP smart camera at 60 fps with a 16 mm lens and polarized white light, so it attacks glare and decode in one housing. Whichever route you take, the system configurator steps through camera, lens, light and controller together, and the applications desk will look at your saved failing image before you order anything.

Domande

Why does the code read when it has a printed border around it?

The border is doing the quiet zone's job: it pushes neighbouring print, label edges and artwork outside the clear margin, so the decoder finds a clean symbol boundary. A borderless label usually fails because text or graphics sit inside the quiet zone itself. Keep any frame at least one module width away from the finder pattern and leave the ring between them unprinted, and the border helps instead of hurting.

How do I measure the quiet zone in a captured image?

Measure the module first: take the pixel length of a solid finder side of the DataMatrix and divide it by the number of modules along it, which gives pixels per module. Then count the clear pixels between the symbol edge and the nearest mark or image border on all four sides. For DataMatrix that count must be at least the module width; for QR Code it must be at least four module widths.

Will a newer decoder version fix a code that will not read?

Sometimes, and it is the quickest test: newer decode libraries handle skew, low contrast and uneven illumination better, so run the saved failing image through the latest version before changing any hardware. No version recovers a quiet zone eaten by print, modules sampled below three pixels, or blur past half a module. Upgrade the decoder to clear marginal images, not to replace the image rules.

What threshold should I use if I binarize the image before decoding?

Most decoders binarize internally, so try the raw gray frame first. When you do preprocess, use a fixed global threshold at the midpoint of the two histogram peaks — with background at gray 200 and modules at gray 90, threshold near 145. Avoid aggressive adaptive thresholds: they can carve dark specks into the quiet zone and create the very failure you are trying to fix.

Does a rolling-shutter camera matter for codes on a moving belt?

Yes. A rolling shutter exposes rows at different times, so a moving code is captured as a parallelogram: vertical modules lean, horizontal ones change width, and read rate drops long before the image looks wrong to the eye. For anything moving on a line, choose a global-shutter sensor or freeze the motion with a strobed exposure in the 300 µs class.