12

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?

MartinTeeVarga
  • 10,478
  • 12
  • 61
  • 98
user2219441
  • 153
  • 1
  • 1
  • 7

5 Answers5

14

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

Vlad Holubiev
  • 4,876
  • 7
  • 44
  • 59
  • Quite right! [Amazon Rekognition Text in Image](https://docs.aws.amazon.com/rekognition/latest/dg/text-detection.html) "can detect text in images and convert it into machine-readable text". However, it can't do full-page OCR. – John Rotenstein Feb 27 '18 at 01:28
  • 1
    There is a 50 word limit on AWS Rekognition OCR. :( – Vingtoft Sep 07 '18 at 11:29
  • @Vingtoft that was a surprise for me as well, so Tesseract+Lambda to the rescue - https://twitter.com/vladholubiev/status/1022607436274970624 – Vlad Holubiev Sep 08 '18 at 17:17
6

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.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • 2
    As of Feb 2018, OCR capabilities can now be demo'ed in Amazon Web Services e.g. at https://console.aws.amazon.com/rekognition/home?region=us-east-1#/text-detection – xke Feb 25 '18 at 17:17
3

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"
         }
       ]
     }
   ]
 }
Kareem
  • 5,068
  • 44
  • 38
2

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.

jgraup
  • 1,271
  • 12
  • 14
1
 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();           
        }