Code readingGuide

OCR for expiration date verification: read inkjet codes on packaging

Set up OCR for expiration date verification on inkjet-coded packaging: pixel sizing, low-angle lighting, strobe timing and checking the printed string.

LumaSpec Vision12 min read Share on LinkedIn

On this page 10 sections
  1. 01The three numbers that decide a read
  2. 02Read the string, then check it
  3. 03Worked example: field of view for a 2 mm code on a flow wrapper
  4. 04Lighting: angle first, wavelength second
  5. 05Strobe, trigger and shutter
  6. 06Reader or smart camera
  7. 07Checks before it goes on the line
  8. 08When the standard answer is wrong
  9. 09Set-up checklist
  10. 10Questions

A date code that fails on the line is rarely a software problem. The digits are too small in the image, the ink sits too close to the film in gray level, or the strobe fires while the web is moving too fast. This guide gives the three numbers that decide whether inkjet date-code OCR holds up at line speed: 20 pixels of character height, 20 gray levels of ink-to-substrate contrast, and motion blur under half a pixel. A worked example sizes the field of view for a 2 mm continuous-inkjet code on a flow wrapper. If you verify dates on food, beverage or pharma packaging, these numbers let you choose between a fixed code reader and a smart camera, set the lighting angle and strobe, and check the printed string against the date the line is running.

The three numbers that decide a read

Pixel height. Size the image so every digit stands at least 20 pixels tall. A 5 x 7 dot-matrix date code then carries about 3 pixels across each printed dot, which is what an engine needs to tell 0 from 8 and 3 from 5 without guessing. At half the target the confusion between similar digits climbs steeply, and reads turn shift-to-shift unreliable. The arithmetic behind the target sits in the minimum font size guide for OCR.

Contrast. Hold at least 20 gray levels between ink and substrate in the saved 8-bit image, on the 0-255 scale. White film at gray level 185 under ink at 150 is a 35-level code that survives web weave and gain drift. The same ink at 172 against 185 is a 13-level code: it reads on the bench and fails within a shift. Read both numbers off the histogram of a real line image, not a bench pack under a desk lamp.

Motion blur. Keep the smear under half a pixel:

blur (px) = web speed (mm/s) × exposure (s) × scale (px/mm)

At 30 m/min — 500 mm/s — a 100 µs exposure and the 10 px/mm scale from the worked example below, the smear is 500 × 0.0001 × 10 = 0.5 px. That is the limit, so at that belt speed hold exposure between 50 and 100 µs and let a strobe make the exposure rather than ambient integration. The pulse-sizing arithmetic for faster lines is in the strobe pulse guide.

Read the string, then check it

OCR turns glyphs into text; verification turns text into a reject decision. Read the string, parse the format your coder prints — DD.MM.YY, a Julian day with a shift letter, whatever the plant standard is — and accept only codes inside a window: the running date plus or minus one day, which absorbs lines spliced just after midnight. Then treat two faults differently. An unreadable code means no print or lost contrast; a readable but out-of-window code means someone set the coder wrong. Both go to the reject station, each with its own reason code, and the wiring that carries them is laid out in the traceability and reject handling guide and the TCP string output guide.

When the print never changes shape, template OCV is the lighter tool: it grades characters against a golden image and catches broken dots without parsing anything. The date-code print grading guide covers that side of the station; this one handles reading and checking.

Worked example: field of view for a 2 mm code on a flow wrapper

The inputs:

  • Character height 2.0 mm, read from the coder's print-height setting. Small cartons and film commonly run 1-3 mm, so 2 mm is a fair middle case.
  • Resolution target 20 px per character height, from the first section. That is 20 px / 2.0 mm = 10 px/mm.
  • Sensor 2560 x 2048 pixels, the fixed reader below.

The rule in words: a field of view H millimeters tall spreads the sensor's 2048 pixel rows over H millimeters, so the scale is 2048 divided by H, in pixels per millimeter. The code reads while that scale, multiplied by 2 mm, stays at or above 20 pixels.

scale (px/mm) = 2048 px / FOV height (mm) FOV_max = 2048 px / 10 px/mm = 204.8 mm ≈ 205 mm FOV_max width = 2560 px / 10 px/mm = 256 mm
How sensor width, working distance and field of view set the focal length Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.CameraField of view (FOV)Working distance (WD)≈ fsensor width slensm = s / FOVf = WD × m / (1 + m)
How sensor width, working distance and field of view set the focal length. Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.

At minimum scale one reader frames 256 x 205 mm — a full flow-wrapper lane with margin for web weave. Pull the ROI in to 60 x 40 mm around the code region and the scale jumps to 2048 / 40 = 51.2 px/mm, so each digit stands 102 pixels tall, five times the target. That headroom carries you through missing dots and faded ink.

Decision: set the field of view to placement tolerance, not the 205 mm maximum. A single lane up to about 205 mm tall stays readable on this sensor; a three-lane web 600 mm across needs 6,000 pixels at 10 px/mm, more than one 2560-pixel-wide frame delivers, so that line takes one reader per lane.

The reader class this example assumes:

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

Run your own pack through the same arithmetic:

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

Lighting: angle first, wavelength second

Matte board and carton are the easy case: diffuse bright field from near the camera axis reads dark ink on light board, and any even bar light covers it. Mount the bar across the web, roughly 100-150 mm above the surface, with the lit face longer than the code.

Glossy film and metallized laminate act as mirrors. Light from an on-axis source bounces straight back into the lens and washes the code out. Drop to dark field: a bar grazing the web at 60-85° from the camera axis, so the flat film reflects the light onward, the background falls toward black, and the raised CIJ dots scatter light back to the sensor.

Bright-field and dark-field lighting geometry High-angle light reflects off the flat surface straight into the lens, so the surface looks bright. Low-angle light reflects away from the lens, so the surface looks dark and only edges or scratches scatter light upward.flat part with a scratchCamerabright field(high angle)dark field (low angle)flat areas reflect away;only the scratch sends light up
Bright-field and dark-field lighting geometry. High-angle light reflects off the flat surface straight into the lens, so the surface looks bright. Low-angle light reflects away from the lens, so the surface looks dark and only edges or scratches scatter light upward.

Judge every angle by the histogram. If the ink-to-film gap sits under 20 gray levels, step down the wavelength before touching exposure. Many CIJ inks absorb harder at the blue end, and lines printing with UV-read or tracer inks show their marks only under 365-395 nm ultraviolet, where a matching bar light makes the dots fluoresce. Where visible light fights the printed artwork itself, near-infrared can quiet the background; the near-infrared packaging guide shows when it pays.

Mounting geometry along a moving web is worked through in the inkjet lighting on moving packaging guide, and the choice between dome, dark field and backlight in the inkjet OCV lighting guide.

The LS-BAR-1047 lights a 290 x 30 mm strip from a 24 V supply, a face sized for an across-web grazing mount.

Bar lights290 x 30 mm LED bar light (LS-BAR-1047)LS-BAR-1047
Size
200-400 mm
Type
Standard
Voltage
24 V
$449.00View partBuild a system with it

If glare survives every angle change on foil, cross a polarizer on the light with one on the lens; the cross-polarization guide gives the recipe. The reader below builds that polarizer in:

Fixed code readersHikrobot MV-IDB005EXI-05NRP Fully isolated version, 1.3 MP resolution, 4.63 mm focal length, 70 mm focus distance, Polarized industrial code readerMV-IDB005EXI-05NRP
Interface
Fast Ethernet
Resolution
Up to 3 MP
Shutter
Global
Lens mount
M5.8
$719.00 · quotedView and quote

Strobe, trigger and shutter

Trigger from the coder fire signal or a photo-eye just downstream of the print head, close enough that the ink has landed but the web has not yet wandered. Fire a 50-200 µs strobe pulse inside the camera exposure. The classic wiring fault is a light that fires between frames — correct logic, black image — and the black-frame timing guide walks that one out.

Use a global-shutter sensor. A rolling shutter reads the frame line by line and turns a strobed, moving web into striped slices. The Shutter filter in the camera finder splits every reader and camera on it, so filter to global first.

A strobed frame is also your ambient rejection. An unlit 10 ms frame integrates the whole room, flicker and all; a 100 µs strobed frame integrates a hundredth of that, and the room drops out of the histogram. The measurement method, and how much rejection to expect, is in the ambient rejection guide.

Reader or smart camera

Choose a fixed code reader when the job is read-and-verify: light, sensor, decoder and communications in one housing. The MV-ID3013PM-12M-WBN is a compact reader with a 1.3 MP global-shutter sensor, a 12 mm focal length and Fast Ethernet output. Readers also take more than one string per image when you print a batch code beside the date — the multiple strings guide shows the setup. Compare focus distances and mounts across the fixed code readers.

Fixed code readersHikrobot MV-ID3013PM-12M-WBN 12mm focal length 1.3 MP Compact Industrial Code ReaderMV-ID3013PM-12M-WBN
Interface
Fast Ethernet
Resolution
Up to 3 MP
Shutter
Global
Lens mount
M12
$1,979.00View part

Step up to a smart camera when the station owes you more than the code: print grading, orientation checks, or a wavelength test you want to run from a setting change. The MV-SC6050C-08M-XBN is a 5 MP color smart camera with a global shutter, an 8 mm focal length and a built-in multi-color light source. A wavelength test then costs a software change rather than a rewiring job. The smart cameras split on resolution, shutter and mount.

Smart cameras & vision sensorsHikrobot MV-SC6050C-08M-XBN SC6000 Series Smart Camera, 5 MP, Color, 8 mm focal length, M12-mount, Multi-color light sourceMV-SC6050C-08M-XBN
Interface
GigE
Resolution
5 MP
Sensor format
1/1.45"
Shutter
Global
$3,449.00 · quotedView and quote

Checks before it goes on the line

Sample across a shift, not a minute. CIJ ink condition drifts through the day as solvent evaporates from the system, so pull 30-50 packs from early and late in the shift and re-measure the histogram gap on each one. The station is only as good as its worst image.

Run at top line speed with the strobe on, then inspect saved frames at 1:1 zoom: character edges crisp, no smear along the print direction.

Inject the faults on purpose. Run a pack with the nozzle blocked, a pack printed with tomorrow's date, and an unprinted pack. All three must reject, each with its own reason code. A station that only rejects unreadable codes passes wrong-date product all day.

Keep the ROI tight around the code region; every spared pixel is decode time, quantified in the ROI sizing guide. Score each decode instead of accepting it, as the read confidence guide shows. And when ink starts to fade mid-shift, the preprocessing that buys a fading code more margin is catalogued in the damaged low-contrast code guide.

When the standard answer is wrong

Wandering placement. If codes drift out of a 60 x 40 mm ROI during a shift, the fault sits in the coder bracket or web guidance, not the camera. Enlarging the field of view dilutes pixels for every pack; fix the mount instead.

Grade-only obligations. If your requirement is that the code is legible and complete, not that the date is correct, template OCV alone answers it and the grading guide above is the whole station.

Curved or shiny packs. On a bottle shoulder, perspective bends the glyphs and specular glare returns from angles a flat-web fixture never sees. The surface treatment in the reflective and curved surfaces guide applies to printed text as much as to QR codes.

Webs above 1 m/s. The blur rule then demands 50 µs-class pulses and a brighter light, because 1000 mm/s × 50 µs × 10 px/mm is already 0.5 px. If you cannot freeze the web at that speed, accumulate packs and inspect them stationary — a short slowdown conveyor is the simpler fix.

Set-up checklist

Optics:

  • 20 px character height at the worst pack position, checked at 1:1 zoom — smaller digits trade shapes.
  • Field of view at placement tolerance, not the sensor maximum — pixels you do not need are read time you pay for.
  • Global shutter — rolling sensors stripe a strobed, moving web.

Lighting:

  • Diffuse bright field for matte board; a 60-85° grazing bar for film and foil — angle sets contrast before any setting does.
  • 20 gray levels ink-to-substrate minimum, measured on saved line images — bench packs flatter the code.
  • 50-200 µs strobe fired from coder or photo-eye trigger — ambient and flicker leave the frame.

Logic:

  • Parse the printed format and accept only the running date plus or minus one day — an out-of-window code is a different fault from a missing one.
  • Separate reject reasons for unreadable and wrong-date codes — the operator needs to know which knob to turn.
  • String output to the PLC over TCP — verification only counts if the line acts on it.

Proof:

  • 30-50 packs sampled across a full shift — ink drifts, and a five-pack sample hides it.
  • Fault injection: no print, wrong date, unprinted pack — each must reject.
  • Rate check at top line speed — a station that reads at half speed becomes the bottleneck.

Size the field of view with the numbers above, then bench the station against a shift's worth of real packs before you cut the mounting plate. The lighting configurator starts at the light choice, the light finder filters bar lights by size and wavelength, and the contact page takes a pack photo and your line speed if you want the numbers worked through with you.

Questions

How many pixels does a date-code character need for OCR?

Design to 20 pixels of character height. Treat 12 pixels as the working floor: below it, similar digits start trading places, and by 8 pixels decoding stops outright. If a pack position cannot clear 20 pixels, shrink the field of view or move to a higher-resolution sensor rather than raising gain — gain lifts ink and film together and the gray-level gap you depend on disappears.

Do I need OCR, OCV or both on a date-code station?

Both, in most plants, in one pass. OCR reads the printed string and compares it with the date the line is running, which catches a coder set to the wrong day. OCV template grading checks the print is legible and complete without reading it, which catches blocked nozzles and broken dots. Reject on either fault: an out-of-window code and an unreadable code are different problems with different fixes.

What lighting reads an inkjet date code on shiny film?

A bar light grazing the surface at 60-85 degrees from the camera axis — dark field. The flat film reflects the light away from the sensor and the background goes near black, while the raised ink dots scatter light back and stand out bright. On matte board, stay in diffuse bright field and read the code as dark print on light. Confirm whichever angle you choose with a histogram: the ink-to-film gap must clear 20 gray levels.

Can one reader check the date code and the barcode together?

Yes, when both codes sit inside one field of view at adequate scale — the 10 px/mm that resolves a 2 mm digit also resolves the common transport barcodes on outer packaging. Read the text with the OCR tool and decode the barcode in the same image, then send both answers over one connection. If the two codes never share a window, a second triggered reader is the simpler fix.

Why does the code read on the bench but fail on the running line?

Three usual suspects. Ambient light and its 50/60 Hz flicker shift the threshold between bench and line — a strobe removes the room from the image. Web weave moves the code out of a tight ROI — widen it or fix the guidance. And a light firing between camera frames produces correct logic with a black image — trigger the strobe from the camera exposure signal. Each fault leaves a different signature in saved frames, so pull images before changing settings.

How fast can a fixed reader verify date codes?

Faster than most food lines need. The reader in the worked example is rated at 30 frames per second and 60 codes per second, while a belt at 60 packs per minute asks for one verified frame per second. The limit is not decode speed but exposure: at 500 mm/s the strobe must freeze motion within about 100 µs. Space triggers so every pack receives its own frame and the reader never queues.