Food Quality Vault learning network
Food Quality VaultLearning Hub
Quick Answer

In brief: Explains why convolutional neural networks outperform rigid contrast-threshold machine vision on natural product variation, spotting burnt crusts, foreign debris and torn seals. Also covers checking seals for sauce, oil or powder residue and verifying lot codes, dates and allergen declarations on labels. Rejects are timed from conveyor encoder pulses, logged, and tested at least twice per shift.

Home / Pillar 11 / Module 11.6

Module 11.6: Computer Vision and Machine Learning for Line Inspection

Deep learning vision systems for defect sorting, seal contamination detection, label verification, and high-speed reject triggering.

By Nair Ajeet, Lead Author, Food Quality Vault Editorial Team · · Editorial governance

Food Quality Vault Updated October 2026 Reference context: Vision AI & SQF

You will learn: Computer Vision for Line Inspection

Cameras that learn what good and bad look like can check every pack on a fast line for faulty seals, missing labels, wrong fill and foreign objects. The technology depends on lighting and optics as much as on software, and it needs training data, honest testing and change control. This module explains how image classification works, how to size a camera for a defect, how to measure performance, what drift and retraining mean, how to validate a vision system and where privacy and ethics come in.

1. What a vision system does

A machine vision system captures an image of each item as it passes, analyses it and decides whether it is acceptable. Tasks include reading the text and codes on labels and packs, checking that seals are closed and clean, confirming the fill level, finding missing or broken items in a tray, spotting foreign objects with a different colour or shape from the product and checking the position and orientation of items.

Classical systems apply rules, such as comparing pixel brightness or measuring a shape. Newer systems use deep learning, in which a neural network is trained on many labelled images to recognise patterns, including ones that are hard to describe in rules, such as the look of a burnt biscuit. Many installations combine the two. Vision complements the optical sorting described in Module 3.9, which works on bulk product in free fall, and the X-ray and metal detection described earlier, which work on density and conductivity, not appearance.

2. Lighting and optics come first

A common mistake is to treat software as the solution and to neglect the image. Poor, uneven or changing light is the most frequent cause of poor performance. Choose lighting to make the defect stand out: low-angle light to show surface texture, backlighting to show silhouettes and holes, diffuse light to avoid glare on shiny packs and coloured or infrared light to boost contrast. Shield the station from stray light, and use light sources with stable output.

Camera resolution must match the defect. As a rule of thumb, the smallest defect to be found should span at least three pixels. To find a 1 mm defect, the pixel size on the product must be about 0.33 mm or smaller. If the field of view is 300 mm wide, the camera needs at least 300 ÷ 0.33, about 900 pixels across, and in practice more, to allow margin. Speed matters too: for a line running 600 items a minute, each item has 100 milliseconds, and the system must capture, analyse and trigger a reject within that time, with the reject point placed correctly downstream.

Figure 11.6 — High-Speed Camera Capture, CNN Feature Extraction, Seal & Label Classification, and Encoder-Synchronized Reject Workflow

1. High-Speed Capture Strobe LED & Camera 2. CNN Analysis Deep Learning Feature Map 3. Defect Classification Seal & Label Verification 4. Pneumatic Eject Encoder-Timed Removal

3. Training a deep learning model

  • Collect images from the real line, under real conditions, including every product variant and the normal variation in position, colour and lighting.
  • Label them carefully. Experts decide what counts as a defect, and the labels must be consistent, since inconsistency in the training data limits what the model can learn.
  • Balance the classes. Defects are rare, so seek out examples, for instance by seeding known defects, and use augmentation, such as rotating or adjusting images, to increase variety.
  • Split the data. Train on one set, tune on a second and test on a third that the model has never seen.
  • Include difficult cases, such as borderline defects and good items that look odd.
  • Keep a record of the images, labels, model version and settings.

A few hundred examples of each defect class may be enough for a simple task, but complex tasks need thousands. Where defects are too rare, anomaly detection models, trained only on good items, can flag anything unusual.

4. Measuring performance

The same measures apply as for any classifier. Recall is the share of real defects that are rejected, and precision is the share of rejects that are real defects. A false reject wastes good product, and a false accept lets a defect pass. The trade-off is set by the decision threshold: lowering it catches more defects but rejects more good items.

The threshold should be chosen from the consequences. For a safety-critical defect, such as a foreign object, a very high recall is needed, and a higher false reject rate may be accepted. For a cosmetic defect, a balanced setting is better. Report results by defect type and size, and by line speed, since performance usually falls as speed rises.

5. Validation, drift and change control

Validate the system as a control, using test items with known defects mixed into the normal flow. A statistical approach, like that in Module 9.9, shows the detection rate with confidence: for example, 59 consecutive correct detections of a defect type support a claim of at least 95 percent detection at 95 percent confidence. Run a challenge at the start of each shift with known good and bad items, and record the result.

Models drift. New packaging, a different supplier’s film, a change in lighting, dirt on the lens or a seasonal change in the product can alter the images, and performance falls without any alarm. Monitor the reject rate and the confidence scores, check for sudden changes, clean optics on a schedule and revalidate after any change in product, packaging, camera, lighting or software. Control the model like any critical setting: version it, limit who can change it and record every change.

Example scenario (illustrative)

A plant that packs salads uses a vision system to find plastic fragments among leaves. For months it works well. After a change to a new green film for the bags, the reject rate jumps to 4 percent, and operators begin to turn down the sensitivity to keep the line running. A review finds that the new film’s green is close to that of the old test fragments, and the model needs retraining with images that include the new colour. The plant retrains, revalidates with seeded pieces and adds a rule that no sensitivity change can be made without quality approval.

6. Privacy, ethics and human factors

Cameras in a plant can also see people. Using them to monitor hygiene, for example to check that hairnets are worn, raises questions about privacy, consent and trust, and the law differs by country. If such monitoring is considered, involve staff and their representatives, state the purpose, limit the data collected, avoid identifying individuals where possible and follow data protection law.

Human factors matter in product inspection. Operators need to understand what the system is looking for and what a reject means. They should know how to respond to alarms, report suspected faults and test the system with confidence. A vision system that nobody trusts will be bypassed.

Key takeaways: Computer Vision and Machine Learning for Line Inspection

Vision inspection depends on good lighting, adequate resolution and timing, honest training data, performance measured by recall and precision, validation with seeded defects, drift monitoring and strict change control. Handle camera data on people with care.

Frequently Asked Questions

How many pixels should span the smallest defect?

As a rule of thumb at least three, so a 1 mm defect needs a pixel size of about 0.33 mm or smaller on the product.

Why can a vision system’s performance fall without warning?

Changes in packaging, lighting, product or dirt on the lens alter the images, so the model drifts. Monitoring reject rates and revalidating after changes catches it.

What does recall mean for a vision system?

The share of real defects that the system rejects.

Why control who can change the sensitivity?

Operators may lower it to reduce false rejects, which can let real defects through, so changes need quality approval.

Lesson details: Computer Vision and Machine Learning for Line

Facts about this module
MeasureDetail
PillarPillar 11: Digital HACCP & AI Compliance
PositionModule 11.6 of 10 in this pillar
Reading timeabout 7 minutes at 200 words per minute
Practice quiz120 questions in four tiers; you can test yourself after reading
Last updated

Key terms: Computer Vision and Machine Learning for Line Inspection

Convolutional neural network
A deep learning model trained on thousands of images that tells acceptable natural variation from true safety defects such as torn seals or foreign debris.
Seal contamination detection
Optical checking that sealing areas are free of sauce, oil or powder residue that could compromise a hermetic seal.
Label verification
Inspection of variable data printing, including lot codes, expiration dates and allergen declarations, against master database records to prevent mislabeling recalls.
Encoder-synchronized reject
A mechanism that tracks a defect's position through conveyor encoder pulses so an air jet or sweep arm diverts it at the calculated millisecond.

Sources and further reading

Nair Ajeet, Lead Author at Food Quality VaultNair Ajeet, author profile

About the author

Nair Ajeet · Lead Author, Food Quality Vault Editorial Team

Lead QC & ISO Certification Planner with more than 10 years in food safety and quality control. MSc Food Science, ASQ Certified Food Safety and Quality Auditor (CFSQA), HACCP Level 4. Experience in fresh-produce inspection, receiving QC, warehouse quality management and production QC. Read the full profile · LinkedIn

Technical Evidence & Practical Application

  1. eCFR — 21 CFR Part 11, Electronic Records; Electronic Signatures
  2. eCFR — 21 CFR Part 117, Current Good Manufacturing Practice, Hazard Analysis, and Risk-Based Preventive Controls for Human Food
  3. FDA — FSMA Food Traceability Rule