AI /
Anomaly Detection using Computer Vision techniques
Updated as of April 2026
Giuseppe Gasbarro

Anomaly detection with Computer Vision is the use of Machine Learning models to identify defects, misplaced objects, or anomalous visual patterns in production images and videos. In an industrial context, it serves to make quality control faster, more scalable, and continuous, reducing manual inspections and intercepting even rare or previously unseen anomalies.
What is anomaly detection using Computer Vision techniques and when is it best to use it?
Visual anomaly detection (image-based anomaly detection) is a Computer Vision approach (automatic image analysis) where a Deep Learning system (neural networks trained on large amounts of data) learns what is "normal" and flags deviations. Compared to static rules (thresholds, templates) or manual inspection, it scales better across high volumes and real-world production line variations (lighting, reflections, minor camera shifts).
The adoption of AI in factories is accelerating: according to McKinsey's Global Survey on AI, the use of AI in at least one business function is now widespread and continues to grow (McKinsey, 2025). In manufacturing, Computer Vision is among the most "operational" use cases because it directly connects data and quality.
AI and Machine Learning enable real-world applications such as anomaly detection through computer vision to improve production quality.
— Databricks, “AI vs Machine Learning” guide
Typical examples: manufacturing (surface defects), logistics (misplaced items), security (intrusions/restricted areas), visual maintenance (visible wear or overheating).
Which visual anomaly detection techniques work best: supervised, unsupervised, and a comparison between the two approaches in the demo
The best choice depends on the available data: supervised anomaly detection (trained on labeled defects) is preferable when errors are recurring and easily classifiable; unsupervised/one-class anomaly detection (trained almost exclusively on "normal" data) is better when defects are rare, expensive to label, or unpredictable. In practice, many production lines achieve the best results by combining both.
| Technique | Data required | Strengths | Typical limits | Use cases | Typical output |
|---|---|---|---|---|---|
| Supervised (es. YOLO11) | Labeled defects | Explains "which defect" | Cannot see new defects | Recurring errors | Bounding box + label |
| One-class / Unsupervised (es. PatchCore, PaDiM) | Mostly "normal" | Discovers rare defects | More false positives | Unpredictable defects | Heatmap + score |
| Autoencoder (reconstruction) | Normal, variable | Simple setup | Loses fine details | Textures/shapes | Error map |
Approach 1 - Model on the most common errors
This approach is supervised: the model learns to recognize known defects and classify them. In practice, it is a classification (assigning a class) with localization through bounding boxes (rectangles that delimit the defective area), typical of models like YOLO11 (a family of real-time detectors). It is ideal when under-extrusion, skipped layers, or stringing are recurring and "prescriptive" alerts are needed: where the problem is and what type it is. In production, the value lies in interpretability: an operator immediately sees the area and the label. Robustness is achieved by working on real variability (slight rotations, lighting changes) using data augmentation and drift monitoring.
Approach 2 - Model on the ideal product
This approach is one-class: the model learns the "ideal product" and flags any significant deviation. The typical output is a heatmap (a heat map highlighting the intensity of the anomaly) and binary segmentation (a 0/1 mask that isolates areas above a threshold). In libraries like Anomalib (an open-source framework for visual anomaly detection in PyTorch), methods such as PatchCore and PaDiM are common, which leverage feature extraction (extraction of descriptors) from pre-trained networks. This is the right choice when defects are rare or cannot be cataloged.
The trade-off is managing false positives: it requires thresholds, calibration, and a truly representative "normal" dataset.
Practical metrics to evaluate a model
- Precision: how many alerts are correct (reduces unnecessary alarms).
- Recall: how many real anomalies are found (reduces defects that slip through).
- F1 score: the balance between precision and recall.
- False Positive Rate: the rate of false alarms per batch/hour.
- AUROC: the "normal vs. anomalous" separation across a variable threshold.
From theory to practice: our Anomaly Detection demo

To move from concept to reality, we have created a demo showing how Computer Vision can assist in a concrete production context. The demo demonstrates how to combine two complementary models to cover known defects and unexpected anomalies in 3D prints: a quality control "assistant" working in real-time on production line images, useful for industrial pre-validation before go-live.
To address the problem, we tested two complementary approaches.
Approach 1 - Model on the most common errors
In this case, the model is trained on the most frequent defects in 3D printing: under-extrusion, skipped layers, stringing, and deformations due to thermal variations. The system learns to recognize these recurring patterns and flags them as they emerge. It is a direct method, oriented towards the classification of already known failures, and particularly useful in situations where the production process exhibits recurring errors.



Approach 2 - Model on the ideal product
The second approach flips the perspective. Here, the model learns exclusively from the “perfect” version of the product, printed under optimal conditions. The algorithm builds a statistical and geometric representation of the correct object and uses this knowledge to identify any significant deviation: a misplaced bump, a misaligned layer, or compromised consistency. This is the classic paradigm of unsupervised anomaly detection, which allows for the discovery of even rare or previously unobserved defects.


The two strategies meet different needs but reinforce each other: the first is effective at rapidly recognizing recurring errors, while the second broadens coverage by detecting everything that deviates from the ideal behavior. Together, they offer a more complete view of process quality.
At Smart Shaped Software, we design "production-oriented" demos to verify data, outputs, and integration from the very beginning: the goal is to reduce risk when moving from prototype to the production line.
Behind the scenes: technologies, data, and tools for training an anomaly detection system
To build this demo, we combined three main components designed to work seamlessly together and remain scalable:
- Anomalib for the anomaly detection models,
- The ML Runner from the chaM3Leon framework,
- And a web app developed with Gradio.
The heart of the solution is Anomalib, an open-source library that brings together many of the most robust algorithms currently available for Anomaly Detection in Computer Vision. It offers models based on feature extraction, reconstruction, generative models, and self-supervised techniques, all optimized for training with limited datasets and in unsupervised scenarios. However, on its own, it isn't enough when the goal is to transform a lab prototype into a component ready for a production environment.
This is where chaM3Leon comes in—specifically its ML Runner module—which serves as the operational glue for the entire pipeline. Built on Metaflow, it enables the clear and repeatable orchestration of every phase of the model's lifecycle. It is at this level that the fundamental elements of any industrial ML project are managed:
- Experiment tracking;
- Model packaging and versioning;
- Model registry management;
- Automated deployment via MLflow.
The result is a comprehensive pipeline that adheres to MLOps best practices: providing not just training, but also control, reproducibility, and a standardized deployment path.
Finally, to make the demo accessible and intuitive, we created a web app using Gradio. The interface allows users to upload images, observe model behavior in real-time, and immediately visualize detected anomalies. This makes the technology understandable even for those unfamiliar with the technical details, facilitating experimentation and the sharing of results.
For a broader perspective on delivery and industrial data, see AI and Big Data services for industry and multi-source data transformation for operational decisions.
An architecture designed for production: deployment, MES/IIoT integration, and alerting
The integration of Anomalib, chaM3Leon, and Gradio allowed us to build a complete and modular solution, designed not just to demonstrate a concept but to move toward real-world application. In a production environment, a visual anomaly detection system must cover an end-to-end flow: acquisition (camera/PLC), inference (edge or cloud), storage (images + metadata), dashboards, alerts, and integration with plant systems.
The key is integration: a MES (Manufacturing Execution System, operational factory management) collects events and KPIs; a SCADA (Supervisory Control And Data Acquisition, plant supervision) manages control and alarms; an ERP (Enterprise Resource Planning) links quality and the supply chain; and an IIoT (Industrial Internet of Things) platform transports signals via MQTT or REST APIs.
Process control is the set of activities that ensure stability, quality, and continuity in production processes.
— Bravo Manufacturing Team, MES Experts for production
| Component | Function | Examples |
|---|---|---|
| Edge/Gateway | Low latency, buffering | NVIDIA Jetson, IPC |
| Inference service | Image scoring | PyTorch, Anomalib |
| MLOps Orchestration | Versions, rollback, audit | chaM3Leon, MLflow |
| Plant integration | Events + traceability | MES/SCADA/IIoT |
| Alerting | Notifications and workflow | Andon, ticketing |
For coherent industrial architectures, see also model-driven architecture for industrial systems and visual workflow for machine learning pipelines.
How much does it cost to implement industrial anomaly detection and which problems must be solved before go-live?
The cost of an industrial computer vision anomaly detection project primarily depends on four drivers: hardware (camera/lighting/edge), dataset quality and quantity, process complexity (product variants), and software integration (MES/SCADA/ERP). The most effective way to reduce risk and TCO (Total Cost of Ownership) is through an iterative pilot, with clear sprints and metrics.
| Scenario | Objective | Typical Components | Complexity | Estimated Timeline | Cost Drivers |
|---|---|---|---|---|---|
| Pilot | Validate feasibility | 1 camera, PoC, dashboard | Low | 4–8 weeks | Data + visual setup |
| Single Line | Stabilize in production | Edge, MLOps, alert | Medium | 2–4 months | Integration + audit |
| Multi-line / Multi-site | Scale and govern | Registry, monitoring, IIoT | High | 6–12 months | Standards + change mgmt |
Typical problems and countermeasures
- False positives: calibrate thresholds, use a "golden set" per shift/batch, and improve lighting setup.
- Light variations: use stable industrial illuminators, enclosures, and targeted data augmentation.
- Concept drift (change in "normal"): monitor metrics, implement scheduled retraining, and maintain a continuous dataset.
- Rare defects: combine one-class detection with supervised models for known defects, and use active learning.
- Insufficient throughput: optimize the pipeline, use batching, or leverage Edge (e.g., Jetson) or Cloud (AWS/Azure) resources.
Working software is the primary measure of progress.
- Asana Experts, Specialists in Agile methodologies
Per decisioni di implementazione e governance: implementazione dell'intelligenza artificiale nei processi aziendali e innovazione e metodologie agili in ambito AI industriale.
For implementation and governance decisions: innovation and agile methodologies in industrial AI.
Beyond the demo: new use cases for Anomaly Detection with Computer Vision
The approach tested in our demo offers a clear advantage: it is not tied specifically to the world of 3D printing. The same combination of artificial vision models, MLOps orchestration, and lightweight interfaces can be transferred to other sectors simply by changing the data or adding specialized modules.
- Manufacturing: surface anomalies, micro-scratches, color defects; output: heatmaps or bounding boxes for scrap/rework.
- Logistics: missing or misplaced items on pallets; output: real-time count + alert.
- Safety: intrusions, missing PPE (Personal Protective Equipment), access to restricted areas; output: event trigger + video clip.
- Retail analytics: empty shelves or products out of facing; output: compliance score.
- Healthcare imaging: anomalous patterns in diagnostic images for triage (regulated context, clinical validation required).
- Infrastructure inspection: cracks and corrosion on bridges or plants; output: segmentation and trends over time.
For video content, it is worth considering official demos: YouTube is cited in 23.3% of Google AI Overviews responses (Ahrefs/BrightEdge, Feb 2026; source: Databricks).
In summary: anomaly detection is not just quality control, but a cross-functional layer of visual observability that connects data, processes, and operational decisions.
FAQ on Anomaly Detection with Computer Vision
How long does it take to launch an anomaly detection pilot in a factory?
A well-defined pilot typically requires 4–8 weeks. The timeline depends primarily on image acquisition, lighting stabilization, defining metrics (precision/recall), and minimal integration for alerts or dashboards. A clear scope reduces delays and rework before the go-live.
How many images are needed to train a visual anomaly detection model?
To start, you often need hundreds or thousands of "OK" images that are representative of real shifts, batches, and conditions. For supervised models, labeled examples of defects are also required; for one-class models, it is more important to cover the variability of "normal" behavior. Dataset quality carries more weight than the absolute number of images.
What is the difference between defect detection and anomaly detection?
Defect detection searches for specific, pre-defined flaws (known classes) and usually produces bounding boxes or labels. Anomaly detection flags deviations from the norm, even without knowing exactly "what" the defect is, often providing scores and heatmaps. In industry, the former is more prescriptive, while the latter is more exploratory and covers the unknown.
Can anomaly detection be used without a dataset of defects?
Yes. One-class/unsupervised methods are trained primarily on "good" samples and then signal deviations. This is particularly useful when defects are rare or expensive to collect. However, it requires a truly representative "OK" dataset and careful threshold calibration to limit false positives.
How can false positives be reduced in production?
They can be reduced by stabilizing the optical setup (lighting and camera), defining thresholds per shift or batch, and monitoring the False Positive Rate (FPR) as an operational KPI. In many cases, an MLOps cycle with periodic retraining is necessary to manage concept drift. As AI implementation in companies continues to grow rapidly (McKinsey, 2025), governance has become a core part of the project.