Amazon Textract Helper工具
项目描述
Textractor-Textract-Helper
amazon-textract-helper 提供了一系列现成的函数和示例实现,用于加速任何使用 Amazon Textract 的项目的评估和开发。它安装了一个名为 amazon-textract
的命令行工具。
安装
> python -m pip install amazon-textract-helper
请确保您的环境已通过配置文件、环境变量或附加的角色设置 AWS 凭据。(https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
测试
> amazon-textract --help
usage: amazon-textract [-h] (--input-document INPUT_DOCUMENT | --example | --stdin) [--features {FORMS,TABLES} [{FORMS,TABLES} ...]]
[--pretty-print {WORDS,LINES,FORMS,TABLES} [{WORDS,LINES,FORMS,TABLES} ...]]
[--pretty-print-table-format {csv,plain,simple,github,grid,fancy_grid,pipe,orgtbl,jira,presto,pretty,psql,rst,medi
awiki,moinmoin,youtrack,html,unsafehtml,latex,latex_raw,latex_booktabs,latex_longtable,textile,tsv}]
[--overlay {WORD,LINE,FORM,KEY,VALUE,TABLE,CELL} [{WORD,LINE,FORM,KEY,VALUE,TABLE,CELL} ...]]
[--pop-up-overlay-output] [--overlay-output-folder OVERLAY_OUTPUT_FOLDER] [--version] [--no-stdout] [-v | -vv]
optional arguments:
-h, --help show this help message and exit
--input-document INPUT_DOCUMENT
s3 object (s3://) or file from local filesystem
--example using the example document to call Textract
--stdin receive JSON from stdin
--features {FORMS,TABLES} [{FORMS,TABLES} ...]
features to call Textract with. Will trigger call to AnalyzeDocument instead of DetectDocumentText
--pretty-print {WORDS,LINES,FORMS,TABLES} [{WORDS,LINES,FORMS,TABLES} ...]
--pretty-print-table-format {csv,plain,simple,github,grid,fancy_grid,pipe,orgtbl,jira,presto,pretty,psql,rst,mediawiki,moinmoin,youtrac
k,html,unsafehtml,latex,latex_raw,latex_booktabs,latex_longtable,textile,tsv}
which format to output the pretty print information to. Only effects FORMS and TABLES
--overlay {WORD,LINE,FORM,KEY,VALUE,TABLE,CELL} [{WORD,LINE,FORM,KEY,VALUE,TABLE,CELL} ...]
defines what bounding boxes to draw on the output
--pop-up-overlay-output
shows image with overlay
--overlay-text shows image with WORD or LINE text overlay. When both WORD and LINE overlay are specified, WORD text will be overlayed
--overlay-confidence shows image with confidence overlay
--overlay-output-folder OVERLAY_OUTPUT_FOLDER
output with bounding boxes to folder
--version print version information
--no-stdout no output to stdout
-v >=INFO level logging output to stderr
-vv >=DEBUG level logging output to stderr
示例命令
快速开始
> amazon-textract --example
这将使用 DetectDocumentText API 运行示例文档。输出将打印到 stdout,类似于以下内容
{"DocumentMetadata": {"Pages": 1}, "Blocks": [{"BlockType": "PAGE", "Geometry": {"BoundingBox": {"Width": 1.0, "Height": 1.0, "Left": 0.0
, "Top": 0.0}, "Polygon": [{"X": 9.33321120033382e-17, "Y": 0.0}, {"X": 1.0, "Y": 1.6069064689339292e-16}, {"X": 1.0, "Y": 1.0}],
"HTTPHeaders": {"x-amzn-requestid": "12345678-1234-1234-1234-123456789012", "content-type": "a
pplication/x-amz-json-1.1", "content-length": "48177", "date": "Thu, 01 Apr 2021 21:50:29 GMT"}, "RetryAttempts": 0}}
它正在运行。
使用 S3 上的文档调用
> amazon-textract --input-document "s3://somebucket/someprefix/someobjectname.png"
输出类似于快速开始
使用本地文件系统上的文档调用
> amazon-textract --input-document "./somepath/somefilename.png"
输出类似于快速开始
我们将继续使用 --example
参数以保持其简单易复现。S3 和本地文件的工作方式相同,只需将 --example 替换为 --input-document。
使用 STDIN 调用
# first create JSON
amazon-textract --example > example.json
# now use a stored JSON with the ```amazon-textract``` command
cat example.json | amazon-textract --stdin -pretty-print LINES
使用 FORMS 和 TABLES 调用
> amazon-textract --example --features FORMS TABLES
这将调用 [AnalyzeDocument API] (https://docs.aws.amazon.com/textract/latest/dg/API_AnalyzeDocument.html),输出将与“快速开始”类似,但包括 FORMS 和 TABLES 信息
美化输出
美化输出将单词、行、表格或表格格式化得很好。
例如,要打印 Amazon Textract 识别的表格到 stdout,使用
> amazon-textract --example --features TABLES --pretty-print TABLES
输出将类似于以下内容
|------------|-----------|---------------------|-----------------|-----------------------|
| | | Previous Employment | History | |
| Start Date | End Date | Employer Name | Position Held | Reason for leaving |
| 1/15/2009 | 6/30/2011 | Any Company | Assistant Baker | Family relocated |
| 7/1/2011 | 8/10/2013 | Best Corp. | Baker | Better opportunity |
| 8/15/2013 | present | Example Corp. | Head Baker | N/A, current employer |
要美化输出 FORMS 和 TABLES,将输出
> amazon-textract --example --features FORMS TABLES --pretty-print FORMS TABLES
将
Phone Number:: 555-0100
Home Address:: 123 Any Street, Any Town, USA
Full Name:: Jane Doe
Mailing Address:: same as home address
|------------|-----------|---------------------|-----------------|-----------------------|
| | | Previous Employment | History | |
| Start Date | End Date | Employer Name | Position Held | Reason for leaving |
| 1/15/2009 | 6/30/2011 | Any Company | Assistant Baker | Family relocated |
| 7/1/2011 | 8/10/2013 | Best Corp. | Baker | Better opportunity |
| 8/15/2013 | present | Example Corp. | Head Baker | N/A, current employer |
覆盖
目前,覆盖仅适用于图像,我们很快将添加对 PDF 的支持。
以下命令运行 DetectDocumentText,将文档中的单词美化打印到 stdout,并在每个单词周围绘制边界框,并在弹出窗口中显示结果,并将其存储在名为 'overlay-output-folder-name' 的文件夹中。
amazon-textract --example --pretty-print WORDS --overlay WORD --pop-up-overlay-output --overlay-output-folder overlay-output-folder-name
以下命令运行 AnalyzeDocument 以处理 FORMS 和 TABLES,将 FORMS 和 TABLES 美化打印到 stdout,并在每个 TABLE-CELL 和 FORM KEY/VALUE 周围绘制边界框,并在弹出窗口中显示结果,并将其存储在名为 'overlay-output-folder-name' 的文件夹中。
> amazon-textract --example --features TABLES FORMS --pretty-print FORMS TABLES --overlay FORM CELL --pop-up-overlay-output --overlay-output-folder ../mywonderfuloutputfolderfordocs/
以下命令在每个单词周围绘制边界框,覆盖检测到的单词文本,并在弹出窗口中显示结果,并将其存储在名为 'overlay-output-folder-name' 的文件夹中。
> amazon-textract --example --overlay WORD --overlay-text --pop-up-overlay-output --overlay-output-folder overlay-output-folder-name
以下命令在每个行周围绘制边界框,覆盖行文本以及检测到的行文本的置信度百分比,并在弹出窗口中显示结果,并将其存储在名为 'overlay-output-folder-name' 的文件夹中。
> amazon-textract --example --overlay LINE --overlay-text --overlay-confidence --pop-up-overlay-output --overlay-output-folder overlay-output-folder-name
项目详细信息
amazon-textract-helper-0.0.35.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e5dc1afc4ade3cb5aa247ca556ee26a2e8e2b5e3aa7e176f3449df445262a53d |
|
MD5 | d0d8c2a102ac3adaa3f179503637f414 |
|
BLAKE2b-256 | 8c2be6b0aca31d5504bac5d4f9b47b8ba6cbb816c0bc787f3839456aa61138a8 |
amazon_textract_helper-0.0.35-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4f727e480da17d5cf8060a5b1f1c045f61331f782c90cbd0084b20fd92808ab9 |
|
MD5 | 2463f4fafea9515da5e21f7620ba8037 |
|
BLAKE2b-256 | 6ea6a16de3e84d357a68357dcda378bc80cd2def24e0065dfc0e692128f8d056 |