Name:
interface
Value:
Extend your Amplify Gen 2 app with AWS Blocks — self-contained backend capabilities you compose into your existing backend.

Page updated Apr 29, 2024

NewDeploy web apps with Git or your AI coding agent using the latest AWS Amplify. Add managed databases and authentication as you grow. Explore the documentation.
Maintenance ModeYou are viewing Amplify Gen 1 documentation. Amplify Gen 1 has entered maintenance mode and will reach end of life on May 1, 2027. For existing Gen 1 projects, a migration guide and tooling are available to help you upgrade.

Identify text

These docs cover Amplify Gen 1. For new web apps, we recommend the latest AWS Amplify, with a simplified CLI and native integrations for databases, storage, and AI models. Get started with the latest AWS Amplify.

The following APIs will allow you to identify text (words, tables, pages from a book) from an image.

Set up your backend

Run amplify add predictions, then use the following answers:

? Please select from one of the categories below (Use arrow keys)
`Identify`
? What would you like to identify? (Use arrow keys)
`Identify Text`
? Provide a friendly name for your resource
`identifyText`
? Would you also like to identify documents? (y/N)
`Y`
? Who should have access? (Use arrow keys)
`Auth and Guest users`

Run amplify push to create the resources in the cloud.

Working with the API

Detect text in an image

Amplify will make calls to both Amazon Textract and Amazon Rekognition depending on the type of text you are looking to identify (i.e. image or document).

Passing in TextFormatType.PLAIN as the identify action will yield IdentifyResult, which must be cast into IdentifyTextResult. See below for an example of plain text detection from an image.

public void detectText(Bitmap image) {
Amplify.Predictions.identify(
TextFormatType.PLAIN,
image,
result -> {
IdentifyTextResult identifyResult = (IdentifyTextResult) result;
Log.i("MyAmplifyApp", identifyResult.getFullText());
},
error -> Log.e("MyAmplifyApp", "Identify text failed", error)
);
}
fun detectText(image: Bitmap) {
Amplify.Predictions.identify(TextFormatType.PLAIN, image,
{ result ->
val identifyResult = result as IdentifyTextResult
Log.i("MyAmplifyApp", identifyResult.fullText)
},
{ Log.e("MyAmplifyApp", "Identify text failed", it) }
)
}
suspend fun detectText(image: Bitmap) {
try {
val result = Amplify.Predictions.identify(PLAIN, image)
val identifyResult = result as IdentifyTextResult
Log.i("MyAmplifyApp", identifyResult.fullText)
} catch (error: PredictionsResult) {
Log.e("MyAmplifyApp", "Identify text failed", error)
}
}
public void detectText(Bitmap image) {
RxAmplify.Predictions.identify(TextFormatType.PLAIN, image)
.subscribe(
result -> {
IdentifyTextResult identifyResult = (IdentifyTextResult) result;
Log.i("MyAmplifyApp", identifyResult.getFullText());
},
error -> Log.e("MyAmplifyApp", "Identify text failed", error)
);
}

Detect text in a document

Passing in any other format of TextFormatType (i.e. FORM, TABLE or ALL) will yield IdentifyResult, which must be cast into IdentifyDocumentTextResult. See below for an example with TextFormatType.FORM for detecting forms from a document.

public void detectText(Bitmap image) {
Amplify.Predictions.identify(
TextFormatType.FORM,
image,
result -> {
IdentifyDocumentTextResult identifyResult = (IdentifyDocumentTextResult) result;
Log.i("MyAmplifyApp", identifyResult.getFullText());
},
error -> Log.e("MyAmplifyApp", "Identify failed", error)
);
}
fun detectText(image: Bitmap) {
Amplify.Predictions.identify(TextFormatType.FORM, image,
{ result ->
val identifyResult = result as IdentifyDocumentTextResult
Log.i("MyAmplifyApp", identifyResult.fullText)
},
{ Log.e("MyAmplifyApp", "Identify failed", it) }
)
}
suspend fun detectText(image: Bitmap) {
try {
val result = Amplify.Predictions.identify(FORM, image)
val identifyResult = result as IdentifyDocumentTextResult
Log.i("MyAmplifyApp", identifyResult.fullText)
} catch (error: PredictionsException) {
Log.e("MyAmplifyApp", "Identify failed", error)
}
}
public void detectText(Bitmap image) {
RxAmplify.Predictions.identify(TextFormatType.FORM, image)
.subscribe(
result -> {
IdentifyDocumentTextResult identifyResult = (IdentifyDocumentTextResult) result;
Log.i("MyAmplifyApp", identifyResult.getFullText());
},
error -> Log.e("MyAmplifyApp", "Identify failed", error)
);
}