Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Rekognition for text detection

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?

like image 365
user2219441 Avatar asked Mar 16 '17 18:03

user2219441


2 Answers

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

like image 106
Vlad Holubiev Avatar answered Sep 19 '22 15:09

Vlad Holubiev


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.

like image 33
jgraup Avatar answered Sep 17 '22 15:09

jgraup