12
votes

I have images of receipts and I want to store the text in the images separately. Is it possible to detect text from images using Amazon Rekognition?

5

5 Answers

14
votes

Update from November 2017:

Amazon Rekognition announces real-time face recognition, Text in Image recognition, and improved face detection

Read the announcement here: https://aws.amazon.com/about-aws/whats-new/2017/11/amazon-rekognition-announces-real-time-face-recognition-text-in-image-recognition-and-improved-face-detection/

Proof:

enter image description here

6
votes

No, Amazon Rekognition not provide Optical Character Recognition (OCR).

At the time of writing (March 2017), it only provides:

  • Object and Scene Detection
  • Facial Analysis
  • Face Comparison
  • Facial Recognition

There is no AWS-provided service that offers OCR. You would need to use a 3rd-party product.

3
votes

Amazon doesn't provide an OCR API. You can use Google Cloud Vision API for Document Text Recognition. It costs $3.5/1000 images though. To test Google's open this link and paste the code below in the the test request body on the right.

https://cloud.google.com/vision/docs/reference/rest/v1/images/annotate

{
   "requests": [
     {
       "image": {
         "source": {
           "imageUri": "JPG_PNG_GIF_or_PDF_url"
         }
       },
       "features": [
         {
           "type": "DOCUMENT_TEXT_DETECTION"
         }
       ]
     }
   ]
 }
2
votes

You may get better results with Amazon Textract although it's currently only available in limited preview.

It's possible to detect text in an image using the AWS JS SDK for Rekognition but your results may vary.

/* jshint esversion: 6, node:true, devel: true, undef: true, unused: true */

// Import libs.
const AWS = require('aws-sdk');
const axios = require('axios');

// Grab AWS access keys from Environmental Variables.
const { S3_ACCESS_KEY, S3_SECRET_ACCESS_KEY, S3_REGION } = process.env;

// Configure AWS with credentials.
AWS.config.update({
  accessKeyId: S3_ACCESS_KEY,
  secretAccessKey: S3_SECRET_ACCESS_KEY,
  region: S3_REGION
});

const rekognition = new AWS.Rekognition({
  apiVersion: '2016-06-27'
});

const TEXT_IMAGE_URL = 'https://loremflickr.com/g/320/240/text';

(async url => {

  // Fetch the URL.
  const textDetections = await axios
    .get(url, {
      responseType: 'arraybuffer'
    })

    // Convert to base64 Buffer.
    .then(response => new Buffer(response.data, 'base64'))

    // Pass bytes to SDK
    .then(bytes =>
      rekognition
        .detectText({
          Image: {
            Bytes: bytes
          }
        })
        .promise()
    )
    .catch(error => {
      console.log('[ERROR]', error);
      return false;
    });

  if (!textDetections) return console.log('Failed to find text.');

  // Output the raw response.
  console.log('\n', 'Text Detected:', '\n', textDetections);

  // Output to Detected Text only.
  console.log('\n', 'Found Text:', '\n', textDetections.TextDetections.map(t => t.DetectedText));

})(TEXT_IMAGE_URL);

See more examples of using Rekognition with NodeJS in this answer.

0
votes
 public async Task<List<string>> IdentifyText(string filename)
        {
            // Using USWest2, not the default region
            AmazonRekognitionClient rekoClient = new AmazonRekognitionClient("Access Key ID", "Secret Access Key", RegionEndpoint.USEast1);            
            Amazon.Rekognition.Model.Image img = new Amazon.Rekognition.Model.Image();
            byte[] data = null;
            using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                data = new byte[fs.Length];
                fs.Read(data, 0, (int)fs.Length);
            }
            img.Bytes = new MemoryStream(data);   

            DetectTextRequest dfr = new DetectTextRequest();
            dfr.Image = img;
            var outcome = rekoClient.DetectText(dfr);

            return outcome.TextDetections.Select(x=>x.DetectedText).ToList();           
        }