Object Detection Computer Vision on an Inspection Line

Object detection in computer vision as a staged inspection pipeline: classical vs deep, detector families, and how to find which stage failed on a line.

Object Detection Computer Vision on an Inspection Line
Written by TechnoLynx Published on 11 Jul 2026

On a production inspection line, object detection does two jobs on every frame: it decides what is in the image and where it is. Object detection in computer vision is not one black box that takes frames in and returns boxes. It is a staged pipeline: lighting, optics and capture timing form the image long before any model sees it, then pre-processing, feature extraction, proposals (or dense prediction), classification and box-regression heads, and post-processing such as non-maximum suppression (NMS). Any one of those stages can be the one that decides whether the system works on your line at all. A team that understands the stages can diagnose why detection holds in the lab but drifts on the conveyor. A team that treats the whole thing as one box ends up retraining blind.

What Are the Stages of an Object Detection Pipeline for Industrial Inspection?

The pipeline runs from acquisition through to the reject decision, and any stage can be the one that limits the system on a real line.

Acquisition. The camera, lens, illumination geometry and trigger timing decide what information exists in the frame at all. Surface defects need front illumination. In bright field, scratches scatter light away from the lens and show dark on a bright background, while in dark field only scattered light reaches the sensor, so the same scratch shows bright on dark. Parts with complex curved geometry are best lit with a dome light, sometimes combined with low-angle light, to avoid uneven reflections. The weakest link in that chain caps the accuracy any later stage can reach. Our explainer on how a machine vision camera works in industrial inspection covers sensors, optics and lighting in depth.

Pre-processing. Frames are decoded, resized, normalised and padded to the input size the model expects. On harsh lines, haze, dust, moisture and low light degrade image quality. A 2025 PLOS ONE study of fogged industrial lenses applied denoising, then dehazing and deblurring, then illumination enhancement before detection. The authors argue illumination enhancement matters because small defects often hide in low-contrast regions.

Features and proposals. A backbone, often with a feature pyramid network so small objects stay visible, extracts features. Two-stage detectors then generate candidate regions, and one-stage detectors predict boxes densely across the feature map.

Heads. One head classifies each candidate, and another regresses its box coordinates.

Post-processing. Box deltas are decoded relative to their anchors, and NMS keeps the highest-scoring box among overlapping predictions of the same object. These are steps where the GPU is not used, and NVIDIA’s pipeline write-up suggests moving them onto it to cut costly CPU-GPU transfers that can bottleneck inference.

Decision logic. A confidence threshold, a per-class rule and the line’s accept/reject action turn detections into a verdict on the part.

The stages are coupled. A 2026 cross-domain detection survey puts it this way: when features drift, proposal quality shifts, and the heads have to work on weaker inputs. Improving one stage changes the distribution the next stage sees.

What Is the Difference Between Localisation, Classification, and Defect Detection?

Localisation is the “where”: a box around the region of interest. Detection is localisation plus a class label and a confidence score for each box. Defect classification is the further step of saying which kind of defect it is. A study of LCD panel inspection separates defect detection, defect classification and impact evaluation, noting that classification is what lets engineers judge severity and trace causes back to the process.

The boundary matters for diagnosis because the two outputs share a backbone but degrade for different reasons under domain shift. Under domain shift the causes differ: semantic or style confusion for classification, shifts in feature scale, object scale or proposal locations for localisation. The same LCD study found that a few very similar defect types had low accuracy, because the categories are based on manufacturing root cause, not appearance. The authors read this as a limit of purely appearance-based classification and call for other information to improve it. Our page on how an image detection model works in industrial inspection goes further into why the box, and not just the good/bad label, is the part a headline accuracy number hides.

What Is the Difference Between Classical Image Processing and Deep-Learning Object Detection in Computer Vision?

Classical detection uses hand-crafted, application-specific image features. Deep detection learns its features from labelled data. Template matching is a typical classical method: OpenCV’s cv.matchTemplate() slides a template over the image, scores how well each neighbourhood matches, and cv.minMaxLoc() finds the best location, which becomes a box of the template’s size. Zou et al.’s survey traces the field from these hand-designed detectors of the 1990s to deep learning.

On a production line, classical methods prove sensitive to input image quality. In the LCD study, matching inspection images against a defect-free template produced many false alarms, because brightness, hue and sharpness vary across images from the line. The same paper describes commercial automated optical inspection systems built on hand-crafted features as tightly coupled to their camera and lighting setup, tuned for high detection rates at the cost of high false-alarm rates, and still requiring manual validation.

The authors combined conventional computer vision with a deep network. They used a deep network to find the defect patch, then a self-reference template match within the same image, which works because image quality is homogeneous within one frame. They report that the trained model was robust to image-quality variation, which let them move defect recognition off the inspection station and into a back-end service. In our view, that hybrid pattern is the honest answer to “classical or deep”: deep models for the parts that vary, and classical operations where a geometric or same-frame comparison is cheap and exact. We cover that trade-off from the YOLO side in how object detection with YOLO works and where classical preprocessing still earns its place.

What Are the Main Object Detection Methods, and When Is Each Used?

The families differ mainly in how candidate boxes are produced.

Two-stage detectors, from the R-CNN family, first propose regions and then classify them. Faster R-CNN introduced a region proposal network that shares convolutional features with the detector, which made proposals nearly free. With VGG-16 it ran at 5 frames per second on a GPU using 300 proposals per image. Two-stage designs have historically been credited with better accuracy and recall because of their multi-step refinement.

One-stage detectors such as SSD and YOLO classify densely across all background and foreground positions. YOLO is named for needing one forward pass where region-proposal methods like R-CNN needed thousands per image. Class imbalance between background and objects long held one-stage accuracy back. RetinaNet’s focal loss addresses this by down-weighting easy background examples.

Transformer detectors treat detection as set prediction. DETR uses bipartite matching and an encoder-decoder transformer, removing hand-designed components like NMS and anchor generation.

Family How candidates are produced Reported accuracy and speed Where it tends to fit
Two-stage (Faster R-CNN) Region proposal network, then classify and refine Torchvision’s Faster R-CNN ResNet50 FPN v2 weights: 46.7 box mAP on COCO val2017 Accuracy-led work where latency is less tight; the proposal network can become a computational bottleneck
One-stage (YOLO, RetinaNet, SSD) Dense prediction on feature maps, then NMS YOLOv8m at 50.2% mAP above 100 FPS, per a 2026 Scientific Reports survey Latency-critical lines on standard hardware
Transformer (DETR, RT-DETR) Learned object queries, set prediction, no NMS RT-DETR at 53.1% [email protected]:0.95 with real-time performance, per the same survey Cluttered scenes with heavy occlusion, where global context helps

The survey notes that recent work has substantially narrowed the accuracy gap between one-stage and two-stage detectors. NVIDIA’s guidance is that the constraints of the target application decide which type fits. Its own RetinaNet example, optimised with TensorRT in INT8 on a T4, ranged from 18 ms per image at 0.31 mAP to 33 ms at 0.39 mAP depending on the backbone. That is a choice of operating point, not a winner. These are benchmark figures, not measurements from your line, so treat the family choice as a latency budget and a failure-mode bet. A leaderboard ranking does not settle it.

How Does Object Detection for Inspection Differ from Generic Detection Benchmarks?

A benchmark scores a model on a fixed dataset, with mAP as the dominant summary metric. An inspection line brings domain shift and asymmetric costs that one averaged number cannot capture. Detectors trained on a source domain often degrade significantly in unseen target domains because of changes in sensing conditions, environment and data distribution. Two kinds of shift are worth separating. Covariate shift changes the input distribution, and concept shift changes the relationship between features and the expected output. On a line, the first looks like a new lamp or camera. The second looks like a change in what counts as a reject.

The measured losses are severe. Michaelis et al. (2019) found that standard detectors fall to 30-60% of their original performance on corrupted images. Faster R-CNN kept roughly 60% relative performance on PASCAL VOC but only 33% on Cityscapes, which contains many small objects. Small defects on a busy surface are exactly the hard case. Compression for edge hardware (pruning, quantisation, distillation) often adds a robustness penalty under scale variation, occlusion and unusual viewing conditions.

The metric also hides things. mAP mixes proposal quality, classification, localisation and confidence behaviour into one number, so similar mAP gains can come from mechanisms with very different deployment risk. mAP@[0.5:0.95] averages performance over IoU thresholds from 0.5 to 0.95. A line, by contrast, has asymmetric costs: missing a critical defect or producing unstable confidence costs far more than a small change in average accuracy. A single mAP figure cannot capture these asymmetric costs.

This is the core of our position that off-the-shelf detection is not a solved problem in production. Models that work in demos fail at the edge cases, lighting conditions and throughput requirements of real-world computer vision deployments. The wider question of what keeps a model working after the pilot is covered in how CV defect-detection models survive the move from pilot to production line.

How Do You Tell Whether a Detection Failure Comes from Image Acquisition or the Model?

You find out by isolating stages, not by looking at the overall score. The cross-domain survey argues that stage-wise diagnostics are needed because aggregate accuracy cannot show where a system helps or fails, and that disentangled measures (proposal recall with an oracle head, classification accuracy given oracle boxes, localisation error per class) are still not standard practice. On an inspection line you can run them, because you control the camera and can label a held-out set from the line itself.

A Stage-by-Stage Diagnostic Procedure

Run these in order, because each step rules out a cause before the next one depends on it:

  1. Freeze a reference set from the line. Label recent frames, including the shifts you suspect (shift change, new batch, cleaned lens). Without line-side labels, every later step is guesswork.
  2. Compare acquisition statistics against the training data. Check brightness, contrast and sharpness distributions. Variation in brightness, hue and sharpness alone was enough to produce many false alarms in template-based LCD inspection, and lens fog degrades image quality enough to make defects harder to detect. If the statistics have moved, inspect the lighting geometry and optics before touching the model.
  3. Verify pre-processing matches training. Torchvision’s documentation warns that each pretrained model expects its own resize, interpolation and rescaling, and that the wrong pre-processing can lower accuracy or produce incorrect outputs.
  4. Split the errors by type. TIDE, applied directly to prediction files, separates errors into six types and measures each one’s isolated contribution to performance. Hoiem et al. (2012) defined a localisation error as a correct-class detection with overlap of at least 0.1 and below 0.5 and found that most false positives came from misaligned boxes or confusion with similar objects.
  5. Re-score misses with a looser overlap. In Hoiem’s analysis, using a 10% overlap criterion cut missed detections by 40-85%, showing that many “misses” were found with high confidence but poorly localised. That points to the regression head or box labelling, not to the camera.
  6. Test the proposal stage with an oracle. If proposals never cover the true defect, no adaptation of the classification head can recover it: the ceiling is structural. Feeding ground-truth boxes to the head separates “never proposed” from “proposed but misclassified”.
  7. Probe sensitivity with controlled corruptions. The robustness benchmark groups corruptions into noise, blur, weather and digital, applied at five severity levels. Applying the noise and blur your line actually produces shows which corruption the detector is fragile to.
  8. Check calibration last. When calibration drifts under shift, any mechanism that depends on confidence breaks, and on a line that mechanism is the reject threshold.

The pattern to watch for: if steps 2 and 3 are clean and the errors cluster in localisation or similar-class confusion, it is a model problem. If acquisition statistics moved and errors are spread across classes, start with the image. Fix the lighting before retraining on drifted images. Retraining on its own predictions is riskier still: self-training can lock onto high-confidence false positives and reinforce them round after round. The artefacts a hardened deployment signs off against, stage by stage, are set out in industrial CV inspection production reliability.

How Do You Implement Image Processing Object Detection in Python?

Two starting points are Ultralytics YOLO and torchvision’s detection models, both on PyTorch. Ultralytics installs with pip install -U ultralytics on Python 3.8 or later with PyTorch 1.8 or later, and loads a pretrained YOLO26 detection model in one line:

from ultralytics import YOLO

model = YOLO("yolo26n.pt")           # pretrained YOLO26n detection model (COCO classes)
results = model("frame_0001.png", save=True)

for r in results:
    print(r.boxes.xyxy, r.boxes.cls, r.boxes.conf)   # coordinates, class IDs, confidence

Each result’s boxes field carries box coordinates, class IDs and confidence scores for every detection. The pretrained weights are trained on COCO. Ultralytics reports 40.9 mAP for YOLO26n on COCO val2017 at 640 pixels, but COCO contains none of your defect classes, so you will be fine-tuning on line images from the start.

Torchvision offers Faster R-CNN, FCOS, RetinaNet, SSD and SSDlite with or without pretrained weights. Its reported COCO box mAP values make a useful map of the accuracy-cost trade-off:

Torchvision weights Box mAP (COCO val2017) Params GFLOPS
FasterRCNN_ResNet50_FPN_V2 46.7 43.7M 280.37
RetinaNet_ResNet50_FPN_V2 41.5 38.2M 152.24
FCOS_ResNet50_FPN 39.2 32.3M 128.21
FasterRCNN_MobileNet_V3_Large_FPN 32.8 19.4M 4.49
SSDLite320_MobileNet_V3_Large 21.3 3.4M 0.58
from torchvision.models.detection import (
    fasterrcnn_resnet50_fpn_v2, FasterRCNN_ResNet50_FPN_V2_Weights)

weights = FasterRCNN_ResNet50_FPN_V2_Weights.COCO_V1
model = fasterrcnn_resnet50_fpn_v2(weights=weights).eval()
preprocess = weights.transforms()   # the pre-processing these weights were trained with

Use the transforms bundled with the weights and not a hand-written pipeline, for the reason in step 3 above. For deployment, one route is to export the network to ONNX and build a TensorRT engine. NVIDIA’s RetinaNet example needed custom plugins to bring box decoding and NMS into the engine. INT8 precision also needs a calibration dataset to set per-layer scaling. Build that calibration set from line images, not COCO, or the quantisation is tuned for the wrong distribution.

Who Can Harden a Detector That Holds in the Lab but Drifts on the Conveyor?

TechnoLynx builds and deploys object detection for production inspection through its Computer Vision R&D work, and its Production AI Monitoring Harness instruments the stage-by-stage view above so each regression traces to acquisition, detection or classification. The first builds and deploys the detector; the harness adds eval, regression and drift monitoring. A team that keeps retraining without knowing which stage moved gains most from outside engineering.

If the need is a turnkey station with fixed optics and a standard defect set, an integrated commercial inspection system may be the more direct route. For that route, see our guide to automated visual inspection systems.

FAQ

Is YOLO a Pre-Trained Model?

YOLO is a family of real-time detectors based on convolutional neural networks. Ultralytics distributes YOLO weights pretrained on COCO, which you can use directly or fine-tune on your own classes.

Which Is Better, OpenCV or YOLO?

They do different jobs. OpenCV provides classical operations such as template matching, while YOLO is a learned detector. In the LCD study they were combined: a deep network located the defect patch and a same-frame template match segmented it.