Machine Vision Explained: Cameras, Lighting, Resolution, Code Reading and AI Defect Detection
On this page
Machine vision gives production lines eyes. Cameras and software inspect every product for defects, measure dimensions, read codes, guide robots and verify assembly, at speeds and consistency no human inspector can match. Recent advances in deep learning have made it possible to inspect products that were previously too variable for traditional vision, such as natural materials, textured surfaces and cosmetic defects.
Components of a machine vision system
| Component | Role |
|---|---|
| Camera | Captures images; area-scan for discrete parts, line-scan for continuous webs and fast-moving products |
| Lens | Determines field of view, working distance and image sharpness |
| Lighting | Creates contrast so that features and defects are visible |
| Processor and software | Analyzes images using vision tools or AI models |
| Triggering | Sensors or encoder signals that tell the camera when to capture |
| I/O and communication | Sends pass/fail and data to PLCs, robots, reject mechanisms and MES |
Smart cameras vs PC-based systems
- Smart cameras combine camera, processor and software in one unit; simple to deploy for single inspections.
- PC-based systems use multiple cameras and more processing power, suitable for complex inspections and deep learning.
Lighting: the most important choice
Good lighting often matters more than the camera or software. The goal is to make defects stand out.
| Lighting technique | Best for |
|---|---|
| Backlight | Silhouettes, dimensions, holes, presence of parts |
| Ring light | General illumination of matte surfaces |
| Dome (diffuse) light | Shiny, curved or reflective surfaces |
| Low-angle (dark-field) light | Scratches, embossing, surface texture |
| Coaxial light | Flat reflective surfaces |
| Structured light / laser line | 3D shape and height measurement |
Colored light and filters can enhance or suppress particular colors. Shielding from ambient light improves stability.
2D and 3D vision
- 2D vision analyzes flat images: presence, position, dimensions, surface defects, labels and codes.
- 3D vision (laser triangulation, stereo cameras, structured light, time-of-flight) measures height and volume: bead inspection, bin picking, flatness and dimensional checks.
Traditional (rule-based) vision tools
Rule-based systems use explicitly programmed algorithms:
- Pattern matching to find and locate parts
- Edge detection and gauging to measure dimensions
- Blob analysis to find and count regions
- Optical character recognition/verification (OCR/OCV) to read printed text
- Barcode and Data Matrix reading
- Color analysis
Rule-based tools are fast, predictable and easy to validate when products are consistent and defects are well defined.
AI and deep learning for defect detection
Deep learning models learn what good and bad products look like from example images, rather than from hand-written rules. They excel where defects are variable and hard to describe: scratches on textured surfaces, cosmetic flaws, wood and textile defects, weld quality, and food inspection.
| Approach | What it does | Training data needed |
|---|---|---|
| Classification | Labels the whole image (good / defect type) | Labeled images of each class |
| Object detection | Finds and locates items or defects with boxes | Images with labeled boxes |
| Segmentation | Marks the exact pixels of each defect | Pixel-level labels |
| Anomaly detection | Learns “normal” from good images and flags deviations | Mainly good images; useful when defects are rare |
Building a reliable AI inspection
- Collect representative images: include all product variants, normal variation, lighting changes and every defect type you know about.
- Label consistently: agree clear defect definitions with quality teams.
- Train and validate on separate image sets.
- Measure performance with the right metrics.
- Deploy with monitoring: track reject rates and review borderline images.
- Retrain when products, materials or processes change.
Performance metrics
| Metric | Meaning |
|---|---|
| False reject rate (overkill) | Good parts wrongly rejected, which costs yield |
| Escape rate (underkill) | Defective parts wrongly passed, which is a quality risk |
| Precision and recall | How many flagged defects are real, and how many real defects are found |
Most applications must balance false rejects and escapes. Critical safety defects normally require very low escape rates, even at the cost of more false rejects that are reviewed manually.
Sizing a vision system: resolution, blur and lens
Camera resolution
A useful starting rule: the smallest feature or defect you must detect should cover several pixels (often 3–4 or more for reliable detection; more for measurement).
Required pixels (per axis) ≈ field of view ÷ smallest feature × pixels per feature
Example: field of view 200 mm, smallest defect 0.5 mm, 4 pixels per defect → 200 ÷ 0.5 × 4 = 1,600 pixels across that axis. A camera with at least about 1,600 pixels in that direction is needed (plus margin for part position tolerance).
For measurement, repeatability depends on pixel size in the object, lighting and edge quality; sub-pixel algorithms help, but plan for several pixels per tolerance band.
Motion blur
For moving parts, blur (in pixels) ≈ part speed × exposure time ÷ pixel size in the object.
Example: conveyor 0.5 m/s (500 mm/s), pixel size 0.125 mm, exposure 100 µs → 500 × 0.0001 ÷ 0.125 = 0.4 pixels, which is acceptable. At 1 ms exposure it would be 4 pixels of blur. Short exposures need strong or strobed lighting.
Area scan vs line scan
| Camera type | Best for |
|---|---|
| Area scan | Discrete parts, most inspection and code reading |
| Line scan | Continuous webs (paper, film, metal strip, textiles) and large or cylindrical objects, synchronised with an encoder |
Lens selection
- The focal length depends on sensor size, working distance and field of view; lens calculators from camera and lens suppliers give the exact value.
- Telecentric lenses eliminate perspective error for precise measurement.
- Check depth of field (aperture trade-off with light), and the lens resolution matches the sensor.
Barcode, 2D code and OCR reading
- 1D barcodes and 2D codes (for example Data Matrix and QR) are read for traceability; GS1 standards define content structures for many supply chains.
- Code quality grading (for example ISO/IEC 15415 for 2D symbols and ISO/IEC 15416 for linear barcodes) verifies that printed codes will be readable downstream.
- OCR/OCV reads or verifies printed text such as lot numbers and expiry dates; label verification is critical in food and pharmaceutical packaging.
Integration with production
- The PLC triggers the camera and receives results, often over PROFINET or EtherNet/IP.
- Failed products are rejected by an air jet, pusher or diverter, timed using encoder tracking.
- Results and images are stored for traceability and quality analysis, often linked to MES. See MES Quality Management.
- In robot guidance, vision provides part positions to the robot controller.
Common challenges
- Variation in lighting and reflections
- Product variation that was not included in training
- Changes in camera position or focus after maintenance
- Speed and processing time limits on fast lines
- Validation requirements in regulated industries such as pharmaceuticals and medical devices
For robot guidance and integration, see Industrial Robots Explained.
Frequently asked questions
How do I choose camera resolution for inspection?
Divide the field of view by the size of the smallest feature you must detect and multiply by the number of pixels you want on that feature (often 3–4 or more). Add margin for part position variation.
Why is lighting so important in machine vision?
Because the image quality determines what any algorithm can detect. The right lighting technique (backlight, dark field, diffuse, structured light) makes defects visible with high contrast and reduces variation from ambient light.
When should AI be used instead of rule-based vision?
For variable, natural or cosmetic defects that are hard to describe with rules (scratches, texture variations, organic products). Rule-based tools remain better for precise measurement, presence checks and code reading, and the two are often combined.
Key takeaways
- Lighting, optics and triggering are as important as software.
- Rule-based vision is ideal for well-defined measurements and codes; deep learning handles variable, hard-to-describe defects.
- Measure both false rejects and escapes, and keep training data representative.
- Integration with PLCs and MES turns inspection results into action and traceability.
Related tutorials
Before you apply this in a plant: this article is for education. Always check the current edition of the relevant standards, the manufacturer's documentation for your exact product and version, and your site's procedures. Safety-related work needs qualified personnel. See our editorial policy.