Amazon web services 用于文本检测的Amazon Rekognion
我有收据的图像,我想在图像中分别存储文本。是否可以使用Amazon Rekognition从图像中检测文本?否,Amazon Rekognition不提供光学字符识别(OCR) 在撰写本报告时(2017年3月),它仅提供:Amazon web services 用于文本检测的Amazon Rekognion,amazon-web-services,amazon-rekognition,Amazon Web Services,Amazon Rekognition,我有收据的图像,我想在图像中分别存储文本。是否可以使用Amazon Rekognition从图像中检测文本?否,Amazon Rekognition不提供光学字符识别(OCR) 在撰写本报告时(2017年3月),它仅提供: 目标和场景检测 面部分析 面子比较 面部识别 没有AWS提供的提供OCR的服务。您需要使用第三方产品。亚马逊不提供OCR API。您可以使用Google Cloud Vision API进行文档文本识别。但它的价格是每1000张图片3.5美元。要测试Google的性能,请
- 目标和场景检测
- 面部分析
- 面子比较
- 面部识别
没有AWS提供的提供OCR的服务。您需要使用第三方产品。亚马逊不提供OCR API。您可以使用Google Cloud Vision API进行文档文本识别。但它的价格是每1000张图片3.5美元。要测试Google的性能,请打开此链接并将下面的代码粘贴到右侧的测试请求正文中
2017年11月起更新: 亚马逊Rekognition宣布实时人脸识别,图像中的文字 识别和改进的人脸检测 请在此处阅读公告: 证明:
公共异步任务标识文本(字符串文件名)
{
//使用USWest2,而不是默认区域
AmazonRekognitionClient-rekoClient=新的AmazonRekognitionClient(“访问密钥ID”,“秘密访问密钥”,RegionEndpoint.USEast1);
Amazon.Rekognition.Model.Image img=新的Amazon.Rekognition.Model.Image();
字节[]数据=null;
使用(FileStream fs=newfilestream(文件名,FileMode.Open,FileAccess.Read))
{
数据=新字节[fs.Length];
fs.Read(数据,0,(int)fs.Length);
}
img.Bytes=新内存流(数据);
DetectTextRequest dfr=新DetectTextRequest();
dfr.Image=img;
var结果=rekoClient.DetectText(dfr);
返回output.textdecatections.Select(x=>x.DetectedText.ToList();
}
尽管目前只能在有限的预览中使用,但使用它可能会获得更好的效果
使用for可以检测,但结果可能会有所不同
/* 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);
请在此查看更多使用Rekognition和NodeJS的示例。请在您的答案中添加注释,解释您截至2018年2月的代码,现在可以在Amazon Web服务中演示OCR功能,例如在非常正确的位置!“可以检测图像中的文本并将其转换为机器可读文本”。但是,它不能进行整版OCR。AWS Rekognition OCR有50个单词的限制:(@Vingtoft这对我来说也是一个惊喜,所以Tesseract+Lambda来营救我-
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();
}
/* 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);