Skip to main content

A nice package OCR for Amazon Textract and Google Document AI

Project description

License: MIT PyPI Version Downloads

ReadyOCR

ReadyOCR is a Python library that allows you to quickly and easily parse data from various OCR API services, including AWS Textract and Google Document AI. The package also comes with nice features for searching and visualizing.

Textract Output Visualize

Installation

You can install ReadyOCR using pip. Depending on the OCR API service you want to use, you can install the corresponding version of ReadyOCR:

  • For minimal usage, if you only want to create ReadyOCR document object format:

    pip install readyocr
    
  • Or you can choose a specific version to support a specific API response:

    # support AWS Textract response
    pip install "readyocr[textract]"
    
    # support Google Document AI response
    pip install "readyocr[documentai]"
    
    # support all available
    pip install "readyocr[all]"
    

Basic Usage

  • ReadyOCR allows you to create a Document object, which represents the OCR results. A Document can contain one or many pages, and each page can have multiple page entity objects, such as line, word, or table.

    from readyocr.entities import Document, Page, Block, Paragraph, Line, Word, Table, Cell, Key, Value
    
    document = Document(...)
    page = Page(...)
    word = Word(...)
    
    # linking all object
    page.add(word)
    document.pages.append(page)
    
  • You can define any document structure you want by using the .children property for page entities. For example, a line object can have many word objects as children.

    page = Page(...)
    line = Line(...)
    word1 = Word(...)
    word2 = Word(...)
    
    line.children = [word1, word2]
    
    # add line object to page children
    page.add(line)
    
    # you can get descendant of a object
    all_page_entity = page.descendant
    
    # you can also filter all object by class, tag or attribute
    all_word = page.descendant.filter_by_class(Word)
    
  • ReadyOCR allows you to read PDF file with page object Line, Character, Figure, and Image. You can read from both path and byte stream

    from readyocr.parsers.pdf_parser import load
    
    document = load(pdf_path, load_image=True, remove_text=False)
    ...
    with open(pdf_path, 'rb') as fp:
        byte_obj = fp.read()
        document = load(byte_obj, load_image=True, remove_text=False)
    
  • You can also use tags attribute to identify some specific attribute:

    table = Table(...)
    cell = Cell(...)
    cell.tags.add('COLUMN_HEADER')
    table.add(cell)
    
    # Get all table cell which is column header
    table.children.filter_by_tags('COLUMN_HEADER') 
    
  • ReadyOCR support export json object and also load from same json object

    from readyocr.parsers.readyocr_parser import load
    
    ...
    # python object -> python dict
    dict_resp = document.export_json()
    
    # python dict -> python object
    same_document = load(dict_resp)
    
  • ReadyOCR support visualize for bounding box and textbox

    from readyocr.utils.visualize import draw_bbox, draw_textbox
    
    bbox_image = page.image.copy()
    text_image = page.image.copy()
    
    for item in page.descendants.filter_by_class(Line):
        bbox_image = draw_bbox(
            image=bbox_image,
            bbox=item,
            fill_color=(0, 255, 0),
            outline_color=(0, 255, 0), 
            opacity=0.2
        )
        text_image = draw_textbox(
            image=text_image, 
            textbox=item,
            padding=1,
            true_font_path="../fonts/arial.ttf",
        )
    

    Textract Textbox Output Visualize

Examples

Please find all the available examples for better understanding ReadyOCR.

License

ReadyOCR is released under the MIT license. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

readyocr-0.0.43.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

readyocr-0.0.43-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

Details for the file readyocr-0.0.43.tar.gz.

File metadata

  • Download URL: readyocr-0.0.43.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for readyocr-0.0.43.tar.gz
Algorithm Hash digest
SHA256 9256799f3718988600768453185ce0a97ac3da2bb7d67c45ac6e3266948431fa
MD5 c7b974a340a2644f2cd070979915199e
BLAKE2b-256 cd3e2ec2eb8160a6298361bb77d6e779b907c1c1fff3fdc32043ebfae6c0fe6b

See more details on using hashes here.

File details

Details for the file readyocr-0.0.43-py3-none-any.whl.

File metadata

  • Download URL: readyocr-0.0.43-py3-none-any.whl
  • Upload date:
  • Size: 41.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for readyocr-0.0.43-py3-none-any.whl
Algorithm Hash digest
SHA256 8c17da599590e919d306b5446550bf7c1a60d7874564657bc8d1a6d351d1c0d0
MD5 949e37bcdacb2e954193029788703888
BLAKE2b-256 ba9a23e2588e6077ddfc3bcdeee4aca07b15c59315914193f04bf05155849c03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page