Intermediate

AI Quality Inspection

Deploy computer vision systems that detect defects faster and more consistently than human inspectors — running 24/7 on high-speed production lines.

Why AI for Quality Inspection?

Manual visual inspection is subjective, fatiguing, and cannot scale. AI vision systems offer:

  • Consistency: Same detection criteria applied to every single product, 24/7
  • Speed: Inspect hundreds of parts per minute at full production line speed
  • Sensitivity: Detect sub-millimeter defects invisible to the human eye
  • Data: Every inspection is logged with images and measurements for traceability

Inspection Types

🔎

Surface Defect Detection

Scratches, dents, stains, cracks, and discoloration on product surfaces. Classification and segmentation of defect types.

📏

Dimensional Measurement

Verify product dimensions, tolerances, and geometric features against CAD specifications with sub-pixel accuracy.

📦

Assembly Verification

Confirm all components are present, correctly positioned, and properly assembled. Check labels, barcodes, and packaging.

🔴

Color & Texture

Verify color consistency, surface finish quality, and texture uniformity across production batches.

Defect Detection Pipeline

import cv2
import torch
from ultralytics import YOLO

class DefectInspector:
    def __init__(self, model_path='defect_model.pt'):
        self.model = YOLO(model_path)
        self.defect_classes = ['scratch', 'dent', 'crack',
                               'stain', 'missing_part']

    def inspect(self, image_path):
        """Run inspection on a product image."""
        results = self.model(image_path, conf=0.3)
        defects = []

        for det in results[0].boxes:
            defect = {
                'type': self.defect_classes[int(det.cls)],
                'confidence': float(det.conf),
                'location': det.xyxy[0].tolist(),
                'area': self._compute_area(det.xyxy[0])
            }
            defects.append(defect)

        verdict = 'PASS' if len(defects) == 0 else 'FAIL'
        return {'verdict': verdict, 'defects': defects}

    def _compute_area(self, bbox):
        return (bbox[2] - bbox[0]) * (bbox[3] - bbox[1])

# Run inline inspection
inspector = DefectInspector()
result = inspector.inspect('product_001.jpg')
print(f"Verdict: {result['verdict']}, Defects: {len(result['defects'])}")

Anomaly Detection for Unseen Defects

When you only have "good" examples, anomaly detection finds deviations from normal without labeled defect data:

  • Autoencoders: Train on good images. High reconstruction error indicates anomaly.
  • PatchCore: State-of-the-art industrial anomaly detection using memory bank of normal features.
  • Student-Teacher: A student network trained on good data fails to reconstruct anomalous regions.
  • MVTec AD: Benchmark dataset for industrial anomaly detection with 15 categories.

Hardware Setup

ComponentOptionsConsiderations
CameraArea scan, line scan, 3DResolution, frame rate, sensor type
LightingRing, bar, dome, backlightCritical for consistent results
ComputeIndustrial PC, NVIDIA JetsonInference speed vs. model complexity
TriggerEncoder, photoelectric sensorSynchronize capture with line speed
Reject mechanismAir blast, diverter, robotIntegrate with PLC for reject action
Key takeaway: Lighting and image acquisition are more important than the AI model. Invest in proper lighting and camera setup first. Use anomaly detection when defect examples are scarce, and supervised detection when you have labeled data. Always validate against human inspectors before deployment.