Applications of Machine Vision in Pharmaceutical Technology Pharmaceutical inspection is the application where rule-based machine vision still wins more often than custom computer vision — and understanding why is the difference between a system that ships and one that stalls in validation. Fill levels, cap presence, blister-pack integrity, label position, and tablet count are all geometric or photometric tests with tight tolerances, controlled lighting, and an inspector who has to defend every reject to a regulator. That combination favours deterministic Keyence- or Cognex-style vision over a learned model whose decision boundary cannot be enumerated in a validation protocol. That is the starting frame for this article: machine vision in pharma is not a generic “AI inspection” story. It is a specific procurement and engineering decision, with criteria that map cleanly onto the broader machine vision vs computer vision decision framework. Here we walk through where the rule-based path fits a pharmaceutical line, and where the exceptions push you toward a custom CV deployment. What counts as machine vision on a pharma line? A pharmaceutical machine vision station is typically a fixed camera (often a smart camera with on-device processing), structured lighting (backlight, dome, or coaxial depending on surface), a calibrated optical setup, and a rule-based decision pipeline: threshold, blob analysis, edge detection, pattern matching, OCR or OCV for printed text. The output is binary or near-binary — accept, reject, or flag for review — with every parameter set explicitly by a vision engineer and locked into the recipe. Three properties matter here. The decision logic is deterministic — the same image yields the same result every time. The pipeline is auditable — every threshold, ROI, and tolerance is visible and version-controlled. And the inspection is fast — sub-millisecond decisions on a smart camera are routine, which is what lets you keep pace with a vial line running at several hundred units per minute. Custom computer vision, by contrast, learns its decision boundary from labelled data. It can generalise across variation that no rule set could enumerate — subtle morphology in tablets, unexpected contamination shapes, OCR on degraded labels — but it gives up some of that determinism and auditability in exchange. For pharma that trade is the central question. Where rule-based machine vision is the right choice For most high-volume pharmaceutical inspection tasks, the rule-based path is structurally the better fit. The criteria converge: The defect class is geometric or photometric. Fill level relative to a meniscus, cap height in pixels, blister-cavity diameter, label X/Y offset, presence-of-print at a known location. These reduce to measurement against a tolerance, which is exactly what rule-based pipelines do well. Lighting and product presentation are controlled. Pharma lines run in environments where the lighting rig, conveyor speed, and product orientation are engineered to be stable. That removes most of the variation that machine learning models exist to absorb. The throughput target is high. Vial lines at 400+ units per minute, blister lines at similar rates, leave roughly 100–150 ms per inspection station. Smart-camera rule pipelines hit that comfortably; a custom CV model on edge hardware can, but the engineering cost is higher. Validation has to be defensible to a regulator. GMP and 21 CFR Part 11 expect a traceable inspection logic. A documented rule set with named thresholds maps to that expectation cleanly. A learned model maps to it only with substantial additional work — held-out validation sets, drift monitoring, change-control on retraining. The maintenance team is an automation team, not an ML team. Most pharma sites have controls engineers who can tune a vision recipe but not retrain a model. That capability constraint is real and persistent. When most of these hold, the rule-based vision system is the operationally relevant measure. It is not a benchmarked rate of “X% accuracy” — it is the observed pattern across our pharmaceutical engagements that the audit, throughput, and maintenance constraints push the design decisively this way. Where custom computer vision earns its place The exceptions are real, and recognising them up front saves the project. A custom CV deployment becomes the better path when: The defect class is morphological or context-dependent. Particulate contamination in a liquid product (shape, size, motion in suspension), tablet defects where the boundary between “cosmetic” and “rejectable” is judgment rather than measurement, or visual inspection of complex devices where good and bad differ by texture rather than dimension. Variation outpaces the recipe. New SKUs, new packaging, frequent format changes. Each rule-based recipe is engineered work; a learned model can sometimes absorb a wider operating envelope from data the team already collects. The OCR or text-verification task is hard. Degraded print, curved surfaces, multi-language artwork. Deep-learning OCR (PaddleOCR, Tesseract with a learned head, or vendor-trained models) outperforms classic OCV here meaningfully. The hybrid case. A common pattern is rule-based primary inspection — fast, deterministic, regulator-friendly — with a learned model running in parallel as a secondary check on edge cases the rules flag for review. That keeps the audit trail clean while picking up the morphology cases the rules miss. A pharma inspection decision rubric The decision framework, applied to pharma: Factor Pushes toward machine vision Pushes toward custom CV Defect class Geometric, photometric, presence/absence Morphological, contextual, subtle texture Production variation Stable lighting, fixed SKUs Frequent format changes, lighting drift Throughput Smart-camera latency budget (sub-ms decision) Edge GPU/accelerator available Validation regime GMP, 21 CFR Part 11, recipe-locked Change-control plus drift monitoring acceptable Maintenance team Controls/automation engineers ML-capable site or vendor with SLA Cost shape Higher capex, lower opex per line Higher engineering setup, ongoing model ops This rubric is not a scoring sheet. It is a way of forcing the conversation about which constraints actually bind on a specific line. If four or five rows lean one direction, the answer is clear. If they split, the hybrid pattern is usually right. What this looks like on a high-speed vial line A typical liquid fill-finish line inspecting vials at 300–500 per minute will have several vision stations: fill level, cap presence and crimp integrity, stopper seating, label position and print verification, and a final cosmetic pass for cracks or scratches. Of these, four are pure rule-based machine vision targets. The cosmetic pass is the one where teams sometimes regret choosing pure machine vision — surface defect morphology varies enough that a tuned recipe accumulates false-positive load over time, and the rejection queue grows until an operator starts overriding it. In our experience this is where a learned model added as a downstream secondary check pays for itself. The primary rule-based system catches everything it is engineered to catch, with the deterministic logic the validation protocol expects. The secondary CV model reviews the borderline rejects and reduces false-positive rework without ever being on the critical reject path. That separation keeps the regulatory story simple — the qualified inspection is still the rule-based one — while recovering throughput the primary system would otherwise leak. Procurement implications A few practical consequences fall out of all this. First, the cost shape of the two paths differs in ways that matter at procurement time. A Keyence or Cognex installation has higher per-station hardware cost but predictable integration timelines and a vendor that owns the validation documentation. A custom CV deployment has lower hardware cost per station but front-loaded engineering — dataset construction, model training, edge deployment, validation evidence — that is genuinely substantial and not always anticipated. Neither approach is “cheaper” in the abstract; the answer depends on how many lines, how stable the SKUs are, and whether the site has the operations capability to maintain a model. Second, the question of whether computer vision is “AI/ML” matters less than people think for procurement, except in one place: validation. A rule-based system validates as automation; a learned model validates as a computerised system with additional expectations around training data, drift, and change control. That is a real workstream, not a paperwork formality. For lines where the inspection task is well-bounded and the regulator-facing story has to be airtight, machine vision remains the structurally right answer. For lines where variation, morphology, or text verification outpace what rules can describe, custom CV earns its place — sometimes alongside the rule-based system rather than in place of it. Frequently asked questions Machine vision vs computer vision: which inspection approach fits my manufacturing line? For pharmaceutical lines with stable lighting, geometric defects, and high throughput, rule-based machine vision usually fits — it is deterministic, auditable, and matches GMP validation expectations. Custom computer vision earns its place when defects are morphological, SKUs change often, or OCR is hard. Hybrids are common. What is machine vision, and how does it differ from a custom computer vision system? Machine vision is a deterministic, rule-based inspection pipeline — thresholds, edges, pattern matching, OCV — usually on a smart camera with controlled lighting. A custom computer vision system learns its decision boundary from data and can generalise across variation no rule set could enumerate, at the cost of some auditability. When does a Keyence/Cognex-style machine-vision system beat a custom CV deployment? When the defect class is geometric or photometric, lighting is engineered to be stable, throughput leaves only a sub-millisecond decision budget, and the validation regime requires recipe-level traceability. These conditions are typical for pharmaceutical fill-finish and packaging lines. How much does a vision inspection system cost across machine-vision versus custom-CV options? Rule-based stations carry higher per-station hardware cost but predictable integration and vendor-owned validation. Custom CV has lower hardware cost per station but front-loaded engineering — dataset, training, edge deployment, validation evidence. Total cost depends on line count, SKU stability, and site ML capability. Is computer vision AI/ML, and does the answer change the procurement path? Custom computer vision is AI/ML; classic machine vision generally is not. The distinction matters most at validation: rule-based systems validate as automation, learned models as computerised systems with expectations around training data, drift, and change control. That is a real workstream. Which production constraints (latency, lighting, throughput) push the decision one way or the other? High throughput with sub-millisecond decision budgets and engineered lighting push toward machine vision. Variable lighting, frequent format changes, or morphological defects push toward custom CV. Latency budgets above ~50 ms per decision open up edge-GPU CV options that smart-camera form factors cannot host.