Smart Extract
Automatically extract the parts that match validation from noisy OCR output using a sliding window.
When you point the camera at a label, a box, or a screen, ML Kit usually reads far more than the value you actually want: headings, unit names, description lines, even unrelated text in the background. Even if all you need is a serial number or a quantity in the middle of the frame, the raw OCR output arrives full of that noise. Smart Extract takes this crowded text and automatically pulls out only the parts that match your validation rules, so you do not have to clean up the result by hand or scan again.
This page explains how Smart Extract breaks noisy text into pieces, how it finds matches with a sliding-window approach, how it prevents overlapping results, and which conditions must be met to turn the feature on.
The problem it solves
When the OCR engine reads a region, it returns the result as a single block of text. Your target value is buried inside that block, sitting right next to words you do not want. Without Smart Extract you have two options: shrink the viewfinder rectangle so tightly that only a single value remains (which is fiddly to align), or clean up the extra text manually.
Smart Extract offers a third, far more practical path: scan the whole region as is and let extraction find the parts that match your validation rules on its own and add them to your list.
How it works
Smart Extract applies these steps, in order, to the raw OCR text:
- Tokenization — the text is split into tokens by whitespace. Every word, number, or run of adjacent characters becomes a separate token.
- Sliding window — extraction tries windows of neighboring tokens, working from larger to smaller. It first evaluates the longest possible combinations (windows spanning more tokens), then narrows down step by step. This way a longer value that only makes sense as a whole — for example a code that contains spaces — is captured before it is broken into individual pieces.
- Validation — each candidate window is run through your active validation rules. Only windows that match every active rule are accepted.
- Overlap prevention — once a window is accepted, the tokens it covers are marked and cannot be reused by smaller windows. This keeps the same piece of text from being added twice and stops the results from overlapping one another.
The end result is that a noisy block yields only the values that pass validation, none of them overlapping, all of them added to your active list.
Note: Smart Extract uses your validation rules to find matches. In other words, what extraction “looks for” depends entirely on the regex rules you define. The more specific the rule, the more precise the extraction from noisy text.
When it turns on
Smart Extract is not a standalone mode; it is an extension of validation. For that reason two conditions must be satisfied together:
- Validation must be enabled — at least one validation rule must be defined and turned on. When extraction talks about a “matching part,” these rules are the yardstick.
- Smart Extract must be on — the
smartExtractoption in settings must be enabled.
If either condition is missing, the scan result is processed as a single value the usual way, and the noisy block is evaluated as is. When both are on, the OCR output passes through the extraction pipeline first.
Tip: When you scan a single, clean value (for example just one number under a barcode), you may not need Smart Extract. Its real benefit shows up on dense label and screen scans where other text inevitably lands in the frame.
Example
Suppose you are collecting six-digit part numbers and your validation rule accepts exactly six digits:
Validation rule (regex): ^\d{6}$
The camera reads a shelf label and the raw OCR output arrives like this:
PART NO 482190 SHELF B12 QTY 7 LOT 559034
Smart Extract splits this text into tokens by whitespace, runs every candidate through the rule with the sliding window, and accepts only the six-digit values. The result:
482190
559034
The tokens PART, NO, SHELF, B12, QTY, 7, and LOT are dropped because they do not match the rule; the two valid numbers are added to the list separately, without overlap. If Smart Extract were off, the whole line would be treated as one candidate and rejected entirely for not matching the rule.
Its relationship to validation
Smart Extract and validation rules are an inseparable pair. Validation decides whether a value is accepted; Smart Extract pulls the parts that meet that acceptance criterion out of a noisy block. The same ReDoS protections (rejecting overly long patterns or inputs) apply here too, because extraction runs every candidate window through the very same validation pipeline.
If you have not defined a rule yet, or you would rather not write regex, see AI rule generator to build a rule from plain language; the rule you generate automatically feeds Smart Extract as well.
Next steps
- Validation rules — define regex-based accept/reject rules
- AI rule generator — turn plain language into regex
- Scanning — the viewfinder, capture modes, and the OCR + QR flow
- Live preview — see validated values above the viewfinder in real time
Made by ReviseTouch.