The Problem
Scottish Water maintains tens of thousands of Piping and Instrumentation Diagrams (P&IDs) — the technical drawings that document every pipe, valve, instrument, and control loop across their water treatment and distribution infrastructure. The majority of these drawings existed as scanned PDFs or aging CAD exports with no queryable structure. Engineers tracing a process loop or locating a specific instrument tag had to manually page through hundreds of drawings — a task that could take hours and was prone to human error.
The underlying data existed; it was simply locked inside raster images.
Approach
I designed a four-stage computer vision pipeline to systematically extract structured engineering data from P&ID drawings.
Stage 1 — Symbol Detection. I fine-tuned a YOLOv8 object detection model to recognize the full vocabulary of P&ID symbols defined by the ISA 5.1 standard: valves, pumps, instruments, actuators, process equipment, and more. The training dataset was built from a small set of manually annotated client drawings and augmented with synthetic data generated programmatically from standard symbol libraries. This allowed us to reach useful precision/recall with a modest annotation budget.
Stage 2 — Text Extraction. A layout-aware OCR pipeline (EasyOCR with custom post-processing) extracted instrument tag numbers, line designations, and annotation text. P&IDs are visually dense, and text frequently overlaps with symbol geometry, so significant effort went into separating text regions from graphical elements before recognition.
Stage 3 — Relationship Extraction. With symbols and text located, I built a graph-based algorithm using NetworkX to link each detected symbol to its neighboring instruments and pipeline segments. The algorithm traced connecting lines spatially and resolved junctions to reconstruct the process topology: which instruments belong to which control loop, which valves sit on which pipe run.
Stage 4 — Structured Output. Each processed drawing produced a JSON representation encoding all detected components and their relationships. This output was designed for direct import into the client's asset management system and could be queried — for example, "return all pressure transmitters on the chlorination loop" — across the entire drawing library.
The central technical challenge was quality variance. Clean CAD-exported drawings and 1980s hand-drawn scans required very different preprocessing, and the model had to generalize across both. I addressed this with a preprocessing classifier that routed drawings to different enhancement pipelines before detection.
Outcome
The pipeline processed several hundred drawings and achieved meaningful detection precision on the primary symbol classes. For the first time, the client could query their drawing library programmatically — a capability that had previously required a manual search. The structured output formed the foundation for an asset register linking physical infrastructure to its engineering documentation.
The project also produced an annotation methodology and labeling guide that the client's engineering team could use to extend the training dataset as new symbol variants emerged.