Abstract
Traditional scene-text spotting systems often struggle with structured, non-dictionary strings such as serial numbers or technical codes, frequently resulting in fragmented detections or out-of-vocabulary errors. We present STEP (Structured TExt sPotter), a novel framework that incorporates user-defined regular expressions (regex) to dynamically guide the detection and recognition process. By integrating regex constraints into a transformer-based attention mechanism, STEP effectively filters irrelevant noise and unifies fragmented text into coherent semantic units. Our evaluations on a new Structured Scene-Text Dataset demonstrate significant performance gains, particularly for complex industrial identifiers.
Introduction
Standard OCR models are typically optimized for natural language, relying on internal dictionaries to resolve ambiguities. However, industrial environments are replete with "nonsense" strings—serial numbers, container IDs, and technical specifications—that do not follow linguistic patterns. These systems face three primary challenges:
- Out-of-Vocabulary (OOV) Failure: Codes like
L4BNorEXFU 878552 2are often misread because they lack semantic context and do not appear in standard dictionaries. - Fragmentation: Multi-part codes containing spaces are often detected as separate, unrelated fragments rather than a single semantic entity.
- Irrelevant Noise: In cluttered scenes, users often require a specific piece of information, yet standard models return every visible character, necessitating complex post-processing to filter results.
STEP addresses these issues by allowing users to "query" the image with a specific structure using a regex (e.g., [A-Z]{4}\s\d{7}).
Methodology: Regex-Guided Spotting
STEP is built upon the TESTR (Transformer-based Text Spotter) architecture, enhanced with a regex-driven attention mechanism. The input regex is transformed into a sequence of multi-hot encoded vectors, where each vector defines the valid character set for a specific position. This structural information is then injected into the model via Regex Cross-Attention layers in the encoder and decoders.
- Encoder: Biases proposal generation toward image regions matching the requested structure, helping the model "look" for relevant text.
- Character Decoder: Constrains character predictions to the allowed types (e.g., forcing a digit when the regex specifies
\d), which reduces common OCR errors like confusing 'O' with '0'. - Location Decoder: Ensures the spatial coordinates of the detected text align with the expected format.
This approach enables Zero-Shot Spotting, where the model can identify entirely new text formats at test time by understanding the relationship between visual features and regex-defined structures.
Experimental Results
The authors introduced a new Structured Scene-Text Dataset featuring 836 images of container codes (BIC), railway codes (UIC), and technical markings. As shown in Figure 6, STEP significantly reduces fragmentation. While the baseline model (b) breaks the container ID into multiple boxes and detects irrelevant labels, STEP (c, d) produces a single, clean detection for the queried structure.
On the new benchmark, STEP achieved an F-score of 0.71, outperforming the baseline TESTR (0.59). The improvement was most pronounced for complex 12-digit UIC railway codes, where STEP's F-score was nearly triple that of the baseline without manual post-processing.
Discussion and Future Work
By treating detection and recognition as a unified, structure-aware task, STEP solves the fragmentation problem inherent in word-level OCR. However, current limitations include a single-query constraint per forward pass and a fixed-length representation that precludes variable-length operators like the Kleene star (*). Future research will focus on supporting multiple simultaneous queries and expanding regex syntax to enhance flexibility for industrial automation.
Summary updated