AWS textract with hand-written checkboxes

北战南征 提交于 2020-01-23 11:53:09

问题


I have 1000s of survey forms which I need to scan and then upload onto my C# system in order to extract the data and enter it into a database. The surveys are a mix of hand-written 1) text boxes and 2) checkboxes. I am currently using the the Azure Read Api to extract hand-written text which should work fine e.g. question #4 below returns 'Python' and 'coding'.

So my question; will any AWS Textract give me the capability to extract data for which checkbox is marked? e.g. see question #1 below - I need a string back saying 'disagree', is this possible with any AWS Textract API?

Azure Read API and Google Vision OCR do not offer this functionality unfortunately so if AWS Textract doesn't help me with this I will have to do something manual like checking changes in pixel color to detect ticked checkboxes.

Survey type:


回答1:


Yes, Amazon Textract supports detection of various field inputs like checkboxes and radio buttons. You can read more about the details in the docs here and here.

I wrote a quick script to call Textract for your image with the following code, which properly identified the keys and values for the different form fields, in addition to identifying whether a given field was selected/unselected.

# python 3
import boto3

# instantiate client
textract = boto3.client('textract')

# read image bytes
with open("textract-test.png", "rb") as image:
  f = image.read()
  image_data = bytearray(f)
  print(image_data[0])

# call textract endpoint
textract.analyze_document(Document={'Bytes': image_data}, FeatureTypes=['FORMS'])

The resulting output will be a series of "blocks", which represent individual blocks of text or form inputs. Parsing this JSON, we can find blocks that correspond to selected checked boxes that resemble the following:

"Id": "0abb6f4e-4512-4581-b261-a45f2426973f",
      "SelectionStatus": "SELECTED" // value of interest. Alternatively, "NOT_SELECTED"
    },
    {
      "BlockType": "SELECTION_ELEMENT",
      "Confidence": 54.00064468383789,
      "Geometry": {
        "BoundingBox": {
          "Width": 0.030619779601693153,
          "Height": 0.024501724168658257,
          "Left": 0.4210366904735565,
          "Top": 0.439885675907135
        },
        "Polygon": [
          {
            "X": 0.4210366904735565,
            "Y": 0.439885675907135
          },
          {
            "X": 0.4516564607620239,
            "Y": 0.439885675907135
          },
          {
            "X": 0.4516564607620239,
            "Y": 0.4643873870372772
          },
          {
            "X": 0.4210366904735565,
            "Y": 0.4643873870372772
          }
        ]
      },

Apologies for not whipping up an example in C#, but you can leverage Textract via the CLI or the AWS .NET SDK for similar effects.


Note: If you're looking to just get a feel for what response Amazon Textract will return for your data, you can navigate to the Amazon Textract page in the AWS Management Console and use the image test application in there. You can use the GUI to visualize some of the results, or download the API responses in their entirety.



来源:https://stackoverflow.com/questions/58886391/aws-textract-with-hand-written-checkboxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!