Rekognition / Client / detect_text
detect_text#
- Rekognition.Client.detect_text(**kwargs)#
Detects text in the input image and converts it into machine-readable text.
Pass the input image as base64-encoded image bytes or as a reference to an image in an Amazon S3 bucket. If you use the AWS CLI to call Amazon Rekognition operations, you must pass it as a reference to an image in an Amazon S3 bucket. For the AWS CLI, passing image bytes is not supported. The image must be either a .png or .jpeg formatted file.
The
DetectText
operation returns text in an array of TextDetection elements,TextDetections
. EachTextDetection
element provides information about a single word or line of text that was detected in the image.A word is one or more script characters that are not separated by spaces.
DetectText
can detect up to 100 words in an image.A line is a string of equally spaced words. A line isn’t necessarily a complete sentence. For example, a driver’s license number is detected as a line. A line ends when there is no aligned text after it. Also, a line ends when there is a large gap between words, relative to the length of the words. This means, depending on the gap between words, Amazon Rekognition may detect multiple lines in text aligned in the same direction. Periods don’t represent the end of a line. If a sentence spans multiple lines, the
DetectText
operation returns multiple lines.To determine whether a
TextDetection
element is a line of text or a word, use theTextDetection
objectType
field.To be detected, text must be within +/- 90 degrees orientation of the horizontal axis.
For more information, see Detecting text in the Amazon Rekognition Developer Guide.
See also: AWS API Documentation
Request Syntax
response = client.detect_text( Image={ 'Bytes': b'bytes', 'S3Object': { 'Bucket': 'string', 'Name': 'string', 'Version': 'string' } }, Filters={ 'WordFilter': { 'MinConfidence': ..., 'MinBoundingBoxHeight': ..., 'MinBoundingBoxWidth': ... }, 'RegionsOfInterest': [ { 'BoundingBox': { 'Width': ..., 'Height': ..., 'Left': ..., 'Top': ... }, 'Polygon': [ { 'X': ..., 'Y': ... }, ] }, ] } )
- Parameters:
Image (dict) –
[REQUIRED]
The input image as base64-encoded bytes or an Amazon S3 object. If you use the AWS CLI to call Amazon Rekognition operations, you can’t pass image bytes.
If you are using an AWS SDK to call Amazon Rekognition, you might not need to base64-encode image bytes passed using the
Bytes
field. For more information, see Images in the Amazon Rekognition developer guide.Bytes (bytes) –
Blob of image bytes up to 5 MBs. Note that the maximum image size you can pass to
DetectCustomLabels
is 4MB.S3Object (dict) –
Identifies an S3 object as the image source.
Bucket (string) –
Name of the S3 bucket.
Name (string) –
S3 object key name.
Version (string) –
If the bucket is versioning enabled, you can specify the object version.
Filters (dict) –
Optional parameters that let you set the criteria that the text must meet to be included in your response.
WordFilter (dict) –
A set of parameters that allow you to filter out certain results from your returned results.
MinConfidence (float) –
Sets the confidence of word detection. Words with detection confidence below this will be excluded from the result. Values should be between 0 and 100. The default MinConfidence is 80.
MinBoundingBoxHeight (float) –
Sets the minimum height of the word bounding box. Words with bounding box heights lesser than this value will be excluded from the result. Value is relative to the video frame height.
MinBoundingBoxWidth (float) –
Sets the minimum width of the word bounding box. Words with bounding boxes widths lesser than this value will be excluded from the result. Value is relative to the video frame width.
RegionsOfInterest (list) –
A Filter focusing on a certain area of the image. Uses a
BoundingBox
object to set the region of the image.(dict) –
Specifies a location within the frame that Rekognition checks for objects of interest such as text, labels, or faces. It uses a
BoundingBox
orPolygon
to set a region of the screen.A word, face, or label is included in the region if it is more than half in that region. If there is more than one region, the word, face, or label is compared with all regions of the screen. Any object of interest that is more than half in a region is kept in the results.
BoundingBox (dict) –
The box representing a region of interest on screen.
Width (float) –
Width of the bounding box as a ratio of the overall image width.
Height (float) –
Height of the bounding box as a ratio of the overall image height.
Left (float) –
Left coordinate of the bounding box as a ratio of overall image width.
Top (float) –
Top coordinate of the bounding box as a ratio of overall image height.
Polygon (list) –
Specifies a shape made up of up to 10
Point
objects to define a region of interest.(dict) –
The X and Y coordinates of a point on an image or video frame. The X and Y values are ratios of the overall image size or video resolution. For example, if an input image is 700x200 and the values are X=0.5 and Y=0.25, then the point is at the (350,50) pixel coordinate on the image.
An array of
Point
objects makes up aPolygon
. APolygon
is returned by DetectText and by DetectCustomLabelsPolygon
represents a fine-grained polygon around a detected item. For more information, see Geometry in the Amazon Rekognition Developer Guide.X (float) –
The value of the X coordinate for a point on a
Polygon
.Y (float) –
The value of the Y coordinate for a point on a
Polygon
.
- Return type:
dict
- Returns:
Response Syntax
{ 'TextDetections': [ { 'DetectedText': 'string', 'Type': 'LINE'|'WORD', 'Id': 123, 'ParentId': 123, 'Confidence': ..., 'Geometry': { 'BoundingBox': { 'Width': ..., 'Height': ..., 'Left': ..., 'Top': ... }, 'Polygon': [ { 'X': ..., 'Y': ... }, ] } }, ], 'TextModelVersion': 'string' }
Response Structure
(dict) –
TextDetections (list) –
An array of text that was detected in the input image.
(dict) –
Information about a word or line of text detected by DetectText.
The
DetectedText
field contains the text that Amazon Rekognition detected in the image.Every word and line has an identifier (
Id
). Each word belongs to a line and has a parent identifier (ParentId
) that identifies the line of text in which the word appears. The wordId
is also an index for the word within a line of words.For more information, see Detecting text in the Amazon Rekognition Developer Guide.
DetectedText (string) –
The word or line of text recognized by Amazon Rekognition.
Type (string) –
The type of text that was detected.
Id (integer) –
The identifier for the detected text. The identifier is only unique for a single call to
DetectText
.ParentId (integer) –
The Parent identifier for the detected text identified by the value of
ID
. If the type of detected text isLINE
, the value ofParentId
isNull
.Confidence (float) –
The confidence that Amazon Rekognition has in the accuracy of the detected text and the accuracy of the geometry points around the detected text.
Geometry (dict) –
The location of the detected text on the image. Includes an axis aligned coarse bounding box surrounding the text and a finer grain polygon for more accurate spatial information.
BoundingBox (dict) –
An axis-aligned coarse representation of the detected item’s location on the image.
Width (float) –
Width of the bounding box as a ratio of the overall image width.
Height (float) –
Height of the bounding box as a ratio of the overall image height.
Left (float) –
Left coordinate of the bounding box as a ratio of overall image width.
Top (float) –
Top coordinate of the bounding box as a ratio of overall image height.
Polygon (list) –
Within the bounding box, a fine-grained polygon around the detected item.
(dict) –
The X and Y coordinates of a point on an image or video frame. The X and Y values are ratios of the overall image size or video resolution. For example, if an input image is 700x200 and the values are X=0.5 and Y=0.25, then the point is at the (350,50) pixel coordinate on the image.
An array of
Point
objects makes up aPolygon
. APolygon
is returned by DetectText and by DetectCustomLabelsPolygon
represents a fine-grained polygon around a detected item. For more information, see Geometry in the Amazon Rekognition Developer Guide.X (float) –
The value of the X coordinate for a point on a
Polygon
.Y (float) –
The value of the Y coordinate for a point on a
Polygon
.
TextModelVersion (string) –
The model version used to detect text.
Exceptions
Rekognition.Client.exceptions.InvalidS3ObjectException
Rekognition.Client.exceptions.InvalidParameterException
Rekognition.Client.exceptions.ImageTooLargeException
Rekognition.Client.exceptions.AccessDeniedException
Rekognition.Client.exceptions.InternalServerError
Rekognition.Client.exceptions.ThrottlingException
Rekognition.Client.exceptions.ProvisionedThroughputExceededException
Rekognition.Client.exceptions.InvalidImageFormatException