Amazon Rekognition for text detection
Asked Answered
C

5

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?

Cooperstein answered 16/3, 2017 at 18:45 Comment(0)
M
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

Measly answered 25/11, 2017 at 22:22 Comment(3)
Quite right! Amazon Rekognition Text in Image "can detect text in images and convert it into machine-readable text". However, it can't do full-page OCR.Lamellirostral
There is a 50 word limit on AWS Rekognition OCR. :(Crosscurrent
@Crosscurrent that was a surprise for me as well, so Tesseract+Lambda to the rescue - twitter.com/vladholubiev/status/1022607436274970624Measly
L
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.

Lamellirostral answered 16/3, 2017 at 23:23 Comment(1)
As of Feb 2018, OCR capabilities can now be demo'ed in Amazon Web Services e.g. at console.aws.amazon.com/rekognition/home?region=us-east-1#/…Saundrasaunter
T
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"
         }
       ]
     }
   ]
 }
Turino answered 28/7, 2017 at 19:10 Comment(0)
T
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.

Trochophore answered 4/1, 2019 at 17:18 Comment(0)
L
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();           
        }
Lyford answered 7/2, 2018 at 9:1 Comment(1)
Please add a comment to your answer, explaining your codeClincher

© 2022 - 2024 — McMap. All rights reserved.