White cartons moving past an inkjet print head and a small camera with a bar light that checks the printed code on each carton
Engineering Guides

OCR Inspection Guide: OCR vs OCV for Date and Batch Codes

OCR inspection on packaging lines: how OCR and OCV differ, print methods and hard characters, checking the expected value, challenge sets and rejects.

Talk to an Engineer

OCR inspection uses a camera to read the printed characters on a pack, such as a batch number or expiry date. The station checks them before the pack leaves the line. A reliable station does two jobs: it reads the characters, and it checks that the value is the one this batch should carry. It is one task within a complete machine vision inspection system, alongside label, code and presence checks.

What Is OCR Inspection?

OCR inspection is an automated check: a camera and software read the printed text on each pack. The station then compares that text with what the pack should carry.

The Wikipedia article on optical character recognition defines OCR as “the electronic or mechanical conversion of images of typed, handwritten or printed text into machine-encoded text”. On a production line that means turning the printed code on each pack into data the line controller can check and record.

Typical targets are lot or batch numbers, expiry and manufacturing dates, product codes and serial numbers printed in plain text beside a barcode or Data Matrix code.

Where OCR Inspection Is Used

OCR inspection is used wherever a printed code carries information that must be right on every unit.

  • Pharmaceutical packs: Batch, expiry and serial numbers beside the 2D code.
  • Medical devices: Lot numbers and the human-readable part of the unique device identifier (UDI).
  • Electronics: Part numbers and date codes marked on components and boards.
  • Personal care and household products: Batch and expiry codes on bottles, tubes and cartons.
  • Labels and logistics: Shipping labels and case codes checked against the order.

Why Manual Code Checks Miss Errors

Manual code checks miss errors because people sample a few packs, tire over a shift and read what they expect to see. A line running 200 packs a minute produces 12,000 packs an hour, and a person checking one pack in fifty sees 240 of them. A camera reads all 12,000 and records the result for each.

OCR vs OCV: What Is the Difference?

OCR reads characters the station does not know in advance and returns them as text. OCV compares the printed characters with an expected value and returns pass or fail.

OCR reads an unknown code into data, OCV checks the printed code against the expected one
OCR reads an unknown code into data, OCV checks the printed code against the expected one
OCR (recognition)OCV (verification)
Question it answersWhat does the print say?Does the print match what we expect?
Needs the expected value?NoYes, from the recipe or batch record
OutputA text string and a confidence scorePass or fail, with a quality score per character
Best forRecording codes, sorting, traceabilityConfirming batch and date on every pack
Main riskA misread character goes unnoticedA wrong expected value passes wrong packs

Packaging lines can use both: OCV to confirm the code is correct and legible, and OCR to store what was actually printed with the pack record.

Vision Sensor or Vision System for OCR?

A vision sensor is a compact, all-in-one unit with fixed OCR tools. A vision system is a camera plus a controller or PC that runs more flexible software. A vision sensor suits one code in a fixed position with a simple format. A vision system suits several codes per pack, codes mixed with other checks, variable formats and links to batch records or a line controller. The comparison of smart cameras and PC-based vision covers the trade-off in more detail.

How OCR Inspection Works

OCR inspection works in five steps on every pack: trigger, light, read, compare and reject.

  1. A part sensor triggers the camera as the pack passes.
  2. Lighting makes the print stand out from the pack surface.
  3. The software finds the code area, separates the characters and reads each one.
  4. The result is compared with the expected value and the date rules.
  5. A failed pack is tracked to the reject point, removed, and the removal is confirmed.
Five checks on each printed code: capture, read, match the expected value, check the date is valid, reject and confirm
Five checks on each printed code

Rule-Based OCR vs Deep Learning OCR

Rule-based OCR matches each character against trained font samples, and deep learning OCR uses a neural network trained on many examples of real print.

Rule-based OCRDeep learning OCR
SetupTrain each font and character setUses a pre-trained model, fine-tuned on samples
HandlesConsistent fonts on stable surfacesDistorted, faint or curved print, varied fonts
Explaining a resultCharacter scores are easy to readHarder to explain a single decision
ValidationSimpler to validate in regulated plantsNeeds a fixed model version and a test set

Rule-based OCR suits stable print in a controlled position. Deep learning OCR helps where print varies, with the model version locked and tested like any other recipe.

Print methods for coded packs are continuous inkjet, thermal inkjet, laser marking, thermal transfer and embossing. Each one gives the camera a different kind of character to read.

Five printed codes side by side: inkjet dots on a white bottle cap, a thermal inkjet code on a white carton, a laser code on a dark carton, a thermal transfer code on clear film and an embossed code on a foil blister
Five print methods, five kinds of character for the camera
Print methodWhat the camera seesWhat makes it hard
Continuous inkjetDot-matrix charactersGaps between dots, ink spread on glossy film
Thermal inkjetFine, sharp charactersFading as the cartridge empties
Laser markingCharacters etched or colour-changedLow contrast on some materials
Thermal transferSolid characters on film or labelsRibbon wrinkles, missing strokes
EmbossingRaised or pressed charactersNeeds low-angle light to show relief

Some characters are easy to confuse: O and 0, I and 1, S and 5, B and 8. Where they appear in your real codes, include them in the trial. Where you control the code format, leave out the letters O and I.

Four pairs of dot-matrix characters that look alike: letter O and zero, letter I and one, S and five, B and eight
Character pairs that OCR can confuse in dot-matrix print

Lighting decides whether the print is readable. Low-angle light shows embossed print; diffuse light reduces glare on foil and film. Our machine vision lighting guide covers the options, and the machine vision camera guide covers exposure for moving packs.

Code Format and Fonts for Reliable OCR

Code format decides how easily a camera reads the print. Fixed-length codes, consistent separators and a fixed date format (for example, EXP 2027-11) are easier to verify than free text. OCR-A and OCR-B (ISO 1073) were designed for machine reading. A clear sans-serif font at a consistent height reads well from inkjet, laser and thermal transfer printers. Leave space around the code so the camera can find it, and keep the print inside a defined window on the pack.

Codes Required on Regulated Packs

Regulated packs carry codes with fixed content, and the human-readable text has to match the encoded data.

DataGS1 Application IdentifierExample use
Product code (GTIN)(01)Pharmaceutical and medical device packs
Batch or lot number(10)Recall and traceability
Expiry date(17)Pharmaceutical and medical device packs
Serial number(21)Serialised packs

In the EU, prescription medicine packs carry a 2D code with a human-readable product code and serial number under the Falsified Medicines Directive. The batch and expiry are printed under EU labelling rules. Medical devices in the US and EU carry a unique device identifier in human-readable and machine-readable form. OCR and OCV confirm that the printed text matches the 2D code on each pack.

Lighting for OCR

Lighting for OCR is chosen from the pack surface and the print method, because the camera can only read characters that stand out from the background. A ring light suits matte printed cartons. A dome light gives even, glare-free light on shiny foil, film and curved bottles. A low-angle bar light throws shadows across embossed and etched codes so the raised or cut characters become visible. Test the light with real packs at line speed, including the shiniest and most creased examples.

Three lights for reading codes: a ring light above a matte white carton, a dome light above a foil blister and a low-angle bar light across embossed characters on brushed metal
Ring, dome and low-angle light matched to the surface

Character Segmentation and Training

Character segmentation splits the code into single characters before each one is read. Segmentation fails when characters touch, when dot-matrix dots are spaced too widely or when the code is skewed. Set the code region, character height and spacing from real samples. Train each character in the font the printer actually produces, and include faint and heavy print in the training set.

OCR on Curved and Moving Packs

Curved and moving packs distort the code the camera sees. Characters near the edge of a round bottle shrink and lean. Position the code where the pack faces the camera most squarely, or use two cameras around the bottle. On a moving line, a short exposure and a strobed light freeze the code. A guide rail or side belts keep each pack at the same distance from the lens.

Why a Clear Read Needs a Value Check

A printer can print the wrong batch or date perfectly. Reading quality and value checking are separate results, and the station needs both.

  • Match the expected value. Take the batch and date from the active recipe or batch record, set at changeover.
  • Check the date is valid. Confirm the format, a real calendar date, and the right relationship between manufacturing and expiry dates.
  • Decide what happens without a source. If the expected value is missing, stop or reject. Never fall back to “anything legible passes”.
  • Keep the two results apart. Log the read confidence and the value check as separate fields.

For packs that also carry serial numbers and 2D codes, the human-readable text links to the same pack record; see our pharmaceutical serialization page. Barcode and Data Matrix grading is covered under code reading and traceability.

Pro Tip: Make the expected value part of the changeover screen, and have the operator confirm it before the first pack runs. That closes the gap a rushed changeover leaves open.

OCR Speed and Line Rate

An OCR station has a fixed time budget for each pack, set by the line rate. A line at 300 packs per minute delivers one pack every 200 milliseconds. Image capture, reading, the value check and the reject decision must all fit inside that time, with margin for the slowest read. Longer codes, more fonts and extra checks all add reading time, so measure the worst-case read time during the trial.

Validating OCR in Regulated Plants

OCR validation in a regulated plant proves the station reads and rejects correctly before it runs product. The usual sequence is an installation check, an operational test with the challenge set, and a performance run on real production. Lock the recipe, font training and software version after validation, and treat any change to them as a controlled change with a repeat of the relevant tests.

Build a Challenge Set Before Acceptance

A challenge set is a group of faulty and good packs that proves the OCR station rejects and passes the right packs. Test the station with packs that should fail as well as packs that should pass:

Challenge sampleWhat it proves
Good print at the edges of the print areaPosition tolerance
Faint, smeared and partly missing charactersQuality limits
Confusable characters in real codesFont training
Correct format, wrong batch or dateValue check
Invalid date such as 31 AprilDate rules
No print at allMissing-code detection
Curved, glossy or creased packsLighting and presentation

Run the set at full line speed, with the real pack and print, and repeat it after each recipe change.

Rejects and Evidence

OCR rejects and evidence prove that every failed pack left the line and that the record shows why. Each result must stay attached to the right pack until the reject point. Test a missing code, an unreadable code, a clear read of a wrong code and a lost expected-value input, and confirm that every one leaves the line. A sensor at the reject bin should confirm the removal.

Save images and results for the retention period your quality system sets. If only failed images are kept, record that rule so an investigation knows what exists. For label position and other pack defects, see our label inspection system guide.

Pro Tip: Store the image of every rejected pack with the read string and the expected value side by side. That record speeds up root-cause analysis.

How Does OCR Data Reach MES or ERP?

OCR data reaches MES or ERP through the line controller or a direct software link. For every pack, the vision system sends a short record:

FieldExample content
Read textThe batch, date or serial number as printed
ResultPass or fail, with the reason for a fail
TimeWhen the pack passed the camera
Image referenceWhere the saved image is stored

The record travels over the network the line already uses, such as industrial Ethernet or OPC UA, to the PLC or straight to the plant system. Stored against the batch, these records support genealogy, recall scope and audits.

Common OCR Inspection Mistakes

Common OCR inspection mistakes come from testing in conditions the line never sees. Trusting a clear read as proof of the right code is the other.

  • Training on clean bench samples and testing on moving, curved packs.
  • Accepting any legible string without checking it against the batch.
  • Treating a high confidence score as proof the code is correct.
  • Leaving the expected value to be typed in free text at changeover.
  • Confirming the reject signal without confirming the pack left the line.

How Motionwell Builds OCR Inspection

Motionwell specifies the camera, lighting and reading tools for the actual print and pack. We link the expected value to the recipe or batch record and build the tracking and confirmed reject. Machine vision uses Keyence and other platforms selected for the part and the inspection task. Handover can include IQ/OQ/PQ protocols, electronic batch records, LVD and EMC test reports and MOM lifting certification.

Motionwell adds OCR and OCV stations to new packaging lines and to running ones. Motionwell has delivered more than 150 automation projects in Singapore since 2014.

Planning a printed-code check? Send sample packs, the code format and the line speed. Discuss your OCR inspection with Motionwell.

Share:

Frequently Asked Questions

What is the difference between OCR and OCV?

OCR, optical character recognition, reads characters the system does not know in advance and returns them as text. OCV, optical character verification, compares the printed characters with the value the system expects and returns pass or fail. Packaging lines use OCV to confirm the batch and date, and OCR to record what was printed.

Can OCR read inkjet dot-matrix codes?

It can, with the right training and lighting. Dot-matrix characters have gaps between dots, so the software needs a font model for dotted print, and the lighting must keep each dot clear on the pack surface.

Why does a clear read still need checking?

Because the printer can print the wrong batch or date perfectly. The inspection has to compare the read value with the active batch record and check the date is valid, as well as confirming the characters are legible.

What happens when the expected value is unavailable?

Define it before go-live. The safe default is to stop or reject, because without the expected value the station can only confirm that something legible was printed.

Ready to Automate Your Operations?

Contact us to discuss your automation needs and explore how we can help.

Get in Touch
Call Get a Quote