Need to configure your backend?See Build a Backend →
テキストの識別
APIの操作
入力画像内のテキストを検出します。入力はブラウザから直接送信することも、プロジェクトバケットからAmazon S3キーとして送信することもできます。
import { Predictions } from '@aws-amplify/predictions';
const response = await Predictions.identify({ text: { source: { file } }});Amazon S3に保存された画像を識別
import { Predictions } from '@aws-amplify/predictions';
const response = await Predictions.identify({ text: { source: { key: pathToPhoto, } }})以下のオプションは、指定された
sourceに関係なく独立しています。デモンストレーションの目的でfileを参照しますが、S3キーにすることもできます。Predictions.identify({text : {...}})は、構造化されていないテキストPLAIN、テーブルからの構造化テキストTABLE、またはフォームからのテキストFORMを検出できます。
プレーンテキストを識別
プレーンテキストを検出する場合、検出されたテキスト全体、検出された行、各テキスト行の位置、および各単語を確認できます。
import { Predictions } from '@aws-amplify/predictions';
const response = await Predictions.identify({ text: { source: { file }, format: 'PLAIN' }});
const { text: { fullText, // String lines, // Array of String ordered from top to bottom linesDetailed /* Array of objects that contains text, // String boundingBox: { width, // ratio of overall image width height, // ratio of overall image height left, // left coordinate as a ratio of overall image width top // top coordinate as a ratio of overall image height }, polygon // Array of { x, y } coordinates as a ratio of overall image width and height */, words // Array of objects that contains { text, boundingBox, polygon} }} = response;構造化されたフォームを識別
画像から構造化されたフォーム(ドキュメント、テーブルなど)を検出する場合、keyValuesは画像内で見つかったエンティティの文字列を返します。また、チェックボックスの選択状態やboundingBoxを使用した画像内の相対位置などのメタデータも返します。
import { Predictions } from '@aws-amplify/predictions';
const response = await Predictions.identify({ text: { source: { file }, format: 'FORM' }});
const { text: { // same as PLAIN + keyValues // Array of { key: string, value: { text: string, selected: boolean}, polygon, boundingBox } }} = response;例えば、以下の画像は、キーとして「Test」または「Checked」を持つkeyValuesを返し、選択されているためtrueの値を返します。これらの要素の位置はboundingBox値に返されます。
構造化されたテーブルを識別
画像から構造化されたテーブルを検出する場合
import { Predictions } from '@aws-amplify/predictions';
const response = await Predictions.identify({ text: { source: { file }, format: 'TABLE' }});
const { text: { // same as PLAIN + tables: [ { size: { rows, columns }, table // Matrix Array[ Array ] of size rows // each element of the array contains { text, boundingBox, polygon, selected, rowSpan, columnSpan} } ] }} = response;画像上のテーブルとフォームを検出するには、フォーマット「ALL」を選択してください。
import { Predictions } from '@aws-amplify/predictions';
const { text } = await Predictions.identify({ text: { source: { file }, format: 'ALL' }});