AWS CLI version 2, the latest major version of AWS CLI, is now stable and recommended for general use. To view this page for the AWS CLI version 2, click here. For more information see the AWS CLI version 2 installation instructions and migration guide.
[ aws . rekognition ]
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
. Each TextDetection
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 the TextDetection
object Type
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
detect-text
[--image <value>]
[--filters <value>]
[--image-bytes <value>]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
[--debug]
[--endpoint-url <value>]
[--no-verify-ssl]
[--no-paginate]
[--output <value>]
[--query <value>]
[--profile <value>]
[--region <value>]
[--version <value>]
[--color <value>]
[--no-sign-request]
[--ca-bundle <value>]
[--cli-read-timeout <value>]
[--cli-connect-timeout <value>]
--image
(structure)
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.To specify a local file use
--image-bytes
instead.Bytes -> (blob)
Blob of image bytes up to 5 MBs. Note that the maximum image size you can pass toDetectCustomLabels
is 4MB.S3Object -> (structure)
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.
Shorthand Syntax:
Bytes=blob,S3Object={Bucket=string,Name=string,Version=string}
JSON Syntax:
{
"Bytes": blob,
"S3Object": {
"Bucket": "string",
"Name": "string",
"Version": "string"
}
}
--filters
(structure)
Optional parameters that let you set the criteria that the text must meet to be included in your response.
WordFilter -> (structure)
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.(structure)
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 -> (structure)
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.(structure)
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 aPolygon
.Y -> (float)
The value of the Y coordinate for a point on aPolygon
.
JSON Syntax:
{
"WordFilter": {
"MinConfidence": float,
"MinBoundingBoxHeight": float,
"MinBoundingBoxWidth": float
},
"RegionsOfInterest": [
{
"BoundingBox": {
"Width": float,
"Height": float,
"Left": float,
"Top": float
},
"Polygon": [
{
"X": float,
"Y": float
}
...
]
}
...
]
}
--image-bytes
(blob)
The content of the image to be uploaded. To specify the content of a local file use the fileb:// prefix. Example: fileb://image.png
--cli-input-json
(string)
Performs service operation based on the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton
. If other arguments are provided on the command line, the CLI values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally.
--generate-cli-skeleton
(string)
Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input
, prints a sample input JSON that can be used as an argument for --cli-input-json
. If provided with the value output
, it validates the command inputs and returns a sample output JSON for that command.
--debug
(boolean)
Turn on debug logging.
--endpoint-url
(string)
Override command's default URL with the given URL.
--no-verify-ssl
(boolean)
By default, the AWS CLI uses SSL when communicating with AWS services. For each SSL connection, the AWS CLI will verify SSL certificates. This option overrides the default behavior of verifying SSL certificates.
--no-paginate
(boolean)
Disable automatic pagination. If automatic pagination is disabled, the AWS CLI will only make one call, for the first page of results.
--output
(string)
The formatting style for command output.
--query
(string)
A JMESPath query to use in filtering the response data.
--profile
(string)
Use a specific profile from your credential file.
--region
(string)
The region to use. Overrides config/env settings.
--version
(string)
Display the version of this tool.
--color
(string)
Turn on/off color output.
--no-sign-request
(boolean)
Do not sign requests. Credentials will not be loaded if this argument is provided.
--ca-bundle
(string)
The CA certificate bundle to use when verifying SSL certificates. Overrides config/env settings.
--cli-read-timeout
(int)
The maximum socket read time in seconds. If the value is set to 0, the socket read will be blocking and not timeout. The default value is 60 seconds.
--cli-connect-timeout
(int)
The maximum socket connect time in seconds. If the value is set to 0, the socket connect will be blocking and not timeout. The default value is 60 seconds.
To use the following examples, you must have the AWS CLI installed and configured. See the Getting started guide in the AWS CLI User Guide for more information.
Unless otherwise stated, all examples have unix-like quotation rules. These examples will need to be adapted to your terminal's quoting rules. See Using quotation marks with strings in the AWS CLI User Guide .
To detect text in an image
The following detect-text
command detects text in the specified image.
aws rekognition detect-text \
--image '{"S3Object":{"Bucket":"MyImageS3Bucket","Name":"ExamplePicture.jpg"}}'
Output:
{
"TextDetections": [
{
"Geometry": {
"BoundingBox": {
"Width": 0.24624845385551453,
"Top": 0.28288066387176514,
"Left": 0.391388863325119,
"Height": 0.022687450051307678
},
"Polygon": [
{
"Y": 0.28288066387176514,
"X": 0.391388863325119
},
{
"Y": 0.2826388478279114,
"X": 0.6376373171806335
},
{
"Y": 0.30532628297805786,
"X": 0.637677013874054
},
{
"Y": 0.305568128824234,
"X": 0.39142853021621704
}
]
},
"Confidence": 94.35709381103516,
"DetectedText": "ESTD 1882",
"Type": "LINE",
"Id": 0
},
{
"Geometry": {
"BoundingBox": {
"Width": 0.33933889865875244,
"Top": 0.32603850960731506,
"Left": 0.34534579515457153,
"Height": 0.07126858830451965
},
"Polygon": [
{
"Y": 0.32603850960731506,
"X": 0.34534579515457153
},
{
"Y": 0.32633158564567566,
"X": 0.684684693813324
},
{
"Y": 0.3976001739501953,
"X": 0.684575080871582
},
{
"Y": 0.3973070979118347,
"X": 0.345236212015152
}
]
},
"Confidence": 99.95779418945312,
"DetectedText": "BRAINS",
"Type": "LINE",
"Id": 1
},
{
"Confidence": 97.22098541259766,
"Geometry": {
"BoundingBox": {
"Width": 0.061079490929841995,
"Top": 0.2843210697174072,
"Left": 0.391391396522522,
"Height": 0.021029088646173477
},
"Polygon": [
{
"Y": 0.2843210697174072,
"X": 0.391391396522522
},
{
"Y": 0.2828207015991211,
"X": 0.4524524509906769
},
{
"Y": 0.3038259446620941,
"X": 0.4534534513950348
},
{
"Y": 0.30532634258270264,
"X": 0.3923923969268799
}
]
},
"DetectedText": "ESTD",
"ParentId": 0,
"Type": "WORD",
"Id": 2
},
{
"Confidence": 91.49320983886719,
"Geometry": {
"BoundingBox": {
"Width": 0.07007007300853729,
"Top": 0.2828207015991211,
"Left": 0.5675675868988037,
"Height": 0.02250562608242035
},
"Polygon": [
{
"Y": 0.2828207015991211,
"X": 0.5675675868988037
},
{
"Y": 0.2828207015991211,
"X": 0.6376376152038574
},
{
"Y": 0.30532634258270264,
"X": 0.6376376152038574
},
{
"Y": 0.30532634258270264,
"X": 0.5675675868988037
}
]
},
"DetectedText": "1882",
"ParentId": 0,
"Type": "WORD",
"Id": 3
},
{
"Confidence": 99.95779418945312,
"Geometry": {
"BoundingBox": {
"Width": 0.33933934569358826,
"Top": 0.32633158564567566,
"Left": 0.3453453481197357,
"Height": 0.07127484679222107
},
"Polygon": [
{
"Y": 0.32633158564567566,
"X": 0.3453453481197357
},
{
"Y": 0.32633158564567566,
"X": 0.684684693813324
},
{
"Y": 0.39759939908981323,
"X": 0.6836836934089661
},
{
"Y": 0.39684921503067017,
"X": 0.3453453481197357
}
]
},
"DetectedText": "BRAINS",
"ParentId": 1,
"Type": "WORD",
"Id": 4
}
]
}
TextDetections -> (list)
An array of text that was detected in the input image.
(structure)
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 toDetectText
.ParentId -> (integer)
The Parent identifier for the detected text identified by the value ofID
. 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 -> (structure)
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 -> (structure)
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.
(structure)
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 aPolygon
.Y -> (float)
The value of the Y coordinate for a point on aPolygon
.
TextModelVersion -> (string)
The model version used to detect text.