extract_text_regions method
Search an image for instances of text that match a pattern using OCR and return their location, dimensions and the text found.
An example use of this method is to find the location of a particular instance of text, such as on a button, so as to click on it as part of a test.
For more information see Eyes OCR support .
This feature is experimental. Please note that the functionality and/or API may change.
Syntax
value = eyes.extract_text_regions(config)
Parameters
- config
- Type:TextRegionSettings
- A list of one or more string literals or patterns to be searched for using OCR. For details of the possible patterns see below.
Return value
- Type: PATTERN_TEXT_REGIONS
-
The returned object is a map of key/value pairs,
where the keys are the patterns specified in the pattern list passed as a parameter,
and each value is a list of lines that matched the string pattern or literal.
Note that this behavior is different to the extractText method described,
which returns multiple lines as a single string with
indicating where a line break was detected.
Each matched line is represented as an object that consists of the following properties:
- The text that was found.
- The top left corner of the text's bounding rectangle in the captured image.
- The dimensions of the text's bounding rectangle.
- PATTERN_TEXT_REGIONS
- The type PATTERN_TEXT_REGIONS is defined as: Dict[Text,List[TextRegion]] It represents a mapping between a OCR pattern and a list of regions where matching text was found.
Remarks
Defining Patterns and Hints
An OCR pattern/hint may be composed of any of the following characters:
. | Matches any character. |
\d | Matches any digit 0-9. |
\l | (Lowercase L) Matches any letter a-z or A-Z. |
\w | Matches any word character a-z, A-Z, or _. |
\S | Matches any non-space character. |
+ | Repeats the previous literal character or character class one or more times, for example, "\d+" is any multi-numeral digit and "\w+" is any word that contains only letters or an underscore. This pattern cannot cross a line break. |
\ | Escapes a character that has a special meaning – specifically use this to specify the literals "\", ".", and "+" by using " \\", "\", and "\+". |
space | The OCR is tolerant of spaces between characters, so you don’t have to add them to the pattern. Where a space is detected in the image, it is translated into a single space. If you add an explicit space in the pattern, then it matches any number of spaces. |
Any other character represents itself. |
Depending on the programming language you use, the back-slashed character classes may need to be specially encoded in the string, for example, by using a double back-slash such as "\\w".
Example patterns
-
"\w+": Match a word
-
"\d+": Match a number
-
"\S+" : Match mixed alphabetic and digital data
-
"\d+/\d+/\d+": Match a date, such as 01/04/1972
-
"$\d+.\d+": Match an amount of money, such as $150.00