LoginSignup
3
2

More than 1 year has passed since last update.

Amazon Textractってみた

Last updated at Posted at 2022-02-16

Amazon Textractとは?

いわゆるOCRです。ではないです。
手書き文字などを抽出してくれますが以下にある通り単なるOCRにとどまらないとのこと!

Amazon Textract は、スキャンしたドキュメントからテキスト、手書き文字、およびデータを自動的に抽出する機械学習 (ML) サービスです。これは、単純な光学文字認識 (OCR) のレベルにとどまらず、フォームやラベルからデータを識別、理解、および抽出します

東京リージョンではまだ使えない

バージニア北部 us-east-1 を選択しました。

image.png

以下、Amazon Textracを試すをポチと

image.png

Amazon Textractのコンソール

既にサンプルドキュメントとその解析結果が表示されてます。
このサンプルで色々ポチポチすれば大体のイメージがつかめるかと。

image.png

textract.gif

自前のPDFをアップロード

日本語は対応していないということなので、SCSの証明書を投入!S3にアップロード後解析されます。
アップロード含め15秒くらいで解析完了しました。

手書き文字ではないので精度としてはばっちりです。
右下のValidation Numberrの文字は黒塗りで欠けている感じなのですが、ちゃんと解析されてる・・

image.png

フォーム

Issue DateExpiration Dateがフォームとして検出されました。

image.png

テーブル

特にテーブル形式のフォーマットがないため未検出です。

スクリーンショット 2022-02-16 7.44.02.png

Human review

解析結果をAmazon Augmented AI(Amazon A2I)に接続し、実際の人間によるチェックを含めたワークフローを組み込めるようです。次回やってみます。

image.png

S3

PDFファイルがアップロードされてました。

スクリーンショット 2022-02-16 7.54.27.png

結果のダウンロード

結果を以下のようにダウンロードもできます。

analyzeDocResponse.json
{
  "Bucket": "バケット名",
  "UploadedFileName": "ファイル名",
  "DocumentMetadata": {
    "Pages": 1
  },
  "JobStatus": "SUCCEEDED",
  "Blocks": [
    {
      "BlockType": "PAGE",
      "Geometry": {
        "BoundingBox": {
          "Width": 1,
          "Height": 1,
          "Left": 0,
          "Top": 0
        },
        "Polygon": [
          {
            "X": 9.462437987838284e-17,
            "Y": 0
          },
          {
            "X": 1,
            "Y": 1.5849613011084484e-16
          },
          {
            "X": 1,
            "Y": 1
          },
          {
            "X": 0,
            "Y": 1
          }
        ]
      },
      "Id": "3d8dffe0-4f33-4755-b303-9ed91b5899ab",
      "Relationships": [
        {
          "Type": "CHILD",
          "Ids": [
            "e949a008-c83e-4ba8-b7f7-7c3de6e33d92",
            "26ec328d-28e0-4afc-a348-d93845c06310",
            "ccf87815-0521-4b9b-8365-c786e6b3229d",
            "8c1188a0-ce3c-457c-9a22-ba3201f30be5",
            "4ccc0655-a718-46ae-8384-c9b85591f6d5",
            "10305887-c60e-42b1-a8d0-a3a87d401b79",
            "950de493-4120-4d44-9562-7ca6e7026951",
            "be47dabe-3ea2-4131-928f-668820ceb8d1",
            "fb8b4643-5c70-405e-894d-f6da24b68063",
            "cf985452-ab74-4995-8987-fe30f9886346",
            "ed5ca345-f5f9-4770-8a6b-ec7756d47f2a",
            "52220f94-5872-4f65-8df6-8fa546dfeca7",
            "9c0dd952-ef20-4a22-b605-4788fd351545",
            "96983254-9598-4b9c-8355-e35badd913e7",
            "7a004d37-96fc-4f32-acbb-74b4b007b8fc",
            "bb766919-f7cf-4326-97b3-8827ebe7d3e1"
          ]
        }
      ],
      "Page": 1,
      "childText": "aws certified has successfully completed the AWS Certification requirements and has achieved their: AWS Certified Security - Specialty Issue Date 2021-12-18 AWS Training and Certification Expiration Date 2024-12-18 Validation Number Validate at: https:/laws.amazon.com/verification ",
      "SearchKey": "aws certified has successfully completed the AWS Certification requirements and has achieved their: AWS Certified Security - Specialty Issue Date 2021-12-18 AWS Training and Certification Expiration Date 2024-12-18 Validation Number Validate at: https:/laws.amazon.com/verification "
    },
    {
      "BlockType": "LINE",
      "Confidence": 74.0015640258789,
      "Text": "aws",
      "Geometry": {
        "BoundingBox": {
          "Width": 0.13254089653491974,
          "Height": 0.05848681926727295,
          "Left": 0.2540280222892761,
          "Top": 0.20253263413906097
        },
        "Polygon": [
          {
            "X": 0.2540280222892761,
            "Y": 0.20253263413906097
          },
          {
            "X": 0.38656893372535706,
            "Y": 0.20253263413906097
          },
          {
            "X": 0.38656893372535706,
            "Y": 0.26101943850517273
          },
          {
            "X": 0.2540280222892761,
            "Y": 0.26101943850517273
          }
        ]
      },
      "Id": "e949a008-c83e-4ba8-b7f7-7c3de6e33d92",
      "Relationships": [
        {
          "Type": "CHILD",
          "Ids": [
            "e31937c1-afc3-4a8c-99d3-10a271f7f484"
          ]
        }
      ],
      "Page": 1,
      "childText": "aws ",
      "SearchKey": "aws"
    },
    {
      "BlockType": "LINE",
      "Confidence": 99.94499969482422,
      "Text": "certified",
      "Geometry": {
        "BoundingBox": {
          "Width": 0.2852284610271454,
          "Height": 0.08378611505031586,
          "Left": 0.45901256799697876,
          "Top": 0.17839643359184265
        },
        "Polygon": [
          {
            "X": 0.45901256799697876,
            "Y": 0.17839643359184265
          },
          {
            "X": 0.7442410588264465,
            "Y": 0.17839643359184265
          },
          {
            "X": 0.7442410588264465,
            "Y": 0.2621825337409973
          },
          {
            "X": 0.45901256799697876,
            "Y": 0.2621825337409973
          }
        ]
      },
      "Id": "26ec328d-28e0-4afc-a348-d93845c06310",
      "Relationships": [
        {
          "Type": "CHILD",
          "Ids": [
            "0a03a1c6-b394-4f4c-b959-421238f54786"
          ]
        }
      ],
      "Page": 1,
      "childText": "certified ",
      "SearchKey": "certified"
    }
    (略)
 ],
  "AnalyzeDocumentModelVersion": "1.0"
}
keyValues.csv
key,value
"Issue Date ","2021-12-18 "
"Expiration Date ","2024-12-18 "
rawText.txt
aws
certified
has successfully completed the AWS Certification
requirements and has achieved their:
AWS Certified Security - Specialty
Issue Date
2021-12-18
AWS Training and Certification
Expiration Date
2024-12-18
Validation Number
Validate at: https:/laws.amazon.com/verification

まとめ

日本語対応が待ち遠し
何かミスチル関連でTextractってみたいと思います。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2