简体   繁体   English

Amazon Rekognition用于文本检测

[英]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? 是否可以使用Amazon Rekognition从图像中检测文本?

Update from November 2017: 2017年11月更新:

Amazon Rekognition announces real-time face recognition, Text in Image recognition, and improved face detection 亚马逊Rekognition宣布实时人脸识别,图像识别中的文本以及改进的人脸检测

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/ 阅读此处的公告: https//aws.amazon.com/about-aws/whats-new/2017/11/amazon-rekognition-announces-real-time-face-recognition-text-in-image-recognition-and -改进用面部检测/

Proof: 证明:

在此输入图像描述

No, Amazon Rekognition not provide Optical Character Recognition (OCR). 不,Amazon Rekognition不提供光学字符识别(OCR)。

At the time of writing (March 2017), it only provides: 在撰写本文时(2017年3月),它仅提供:

  • Object and Scene Detection 物体和场景检测
  • Facial Analysis 面部分析
  • Face Comparison 面部比较
  • Facial Recognition 面部识别

There is no AWS-provided service that offers OCR. 没有AWS提供的服务提供OCR。 You would need to use a 3rd-party product. 您需要使用第三方产品。

Amazon doesn't provide an OCR API. 亚马逊不提供OCR API。 You can use Google Cloud Vision API for Document Text Recognition. 您可以使用Google Cloud Vision API进行文档文本识别。 It costs $3.5/1000 images though. 它的价格为3.5美元/ 1000张。 To test Google's open this link and paste the code below in the the test request body on the right. 要测试Google打开此链接并将下面的代码粘贴到右侧的测试请求正文中。

https://cloud.google.com/vision/docs/reference/rest/v1/images/annotate 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"
         }
       ]
     }
   ]
 }

You may get better results with Amazon Textract although it's currently only available in limited preview. 使用Amazon Textract可能会获得更好的效果,尽管它目前仅在有限预览中可用。

It's possible to detect text in an image using the AWS JS SDK for Rekognition but your results may vary. 可以使用AWS JS SDK for Rekognition检测图像中的文本,但结果可能会有所不同。

/* 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 . 在此答案中查看更多使用Rekognition和NodeJS的示例。

 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();           
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM