Skip to main content

Convert OCR JSON to spatial text preserving document layout

Project description

OCR Layout

Convert OCR JSON to spatial text preserving document layout.

Installation

pip install ocr-layout-formatter

Usage

from ocr_layout import Formatter

formatter = Formatter(gap_threshold=40, y_threshold=15)
result = formatter.format(ocr_data)
print(result)

Parameters

  • gap_threshold (int): Minimum horizontal gap to split text into segments (default: 40)
  • y_threshold (int): Maximum vertical distance to group texts on same line (default: 15)

Input Format

ocr_data = [
    {
        "result": [{
            "text_lines": [
                {"text": "Hello", "bbox": [10, 10, 50, 30]},
                {"text": "World", "bbox": [60, 10, 100, 30]}
            ],
            "image_bbox": [0, 0, 200, 300]
        }]
    }
]

Output

--- Page 1 ---
Hello World

Logging

Enable logging to see processing details:

import logging
logging.basicConfig(level=logging.DEBUG)

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

ocr_layout_formatter-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

ocr_layout_formatter-0.1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file ocr_layout_formatter-0.1.1.tar.gz.

File metadata

  • Download URL: ocr_layout_formatter-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for ocr_layout_formatter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e56b77886d29912c4caa4781022012bece4d9b4c4ab4d8a2c24a9b90aee4cc08
MD5 c464e612a9265a679829c1099a5e3086
BLAKE2b-256 e7bd04c79892e0f7aa09d218fac6a2845a8670b85b4bcc975b33b2fb8a925f7e

See more details on using hashes here.

File details

Details for the file ocr_layout_formatter-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ocr_layout_formatter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a84342392f633a7e0af75b9a117923f205d864255a796ded1c619f66a8c57d0
MD5 65c6e74f493c6191c7668cf9b8854d1e
BLAKE2b-256 75e8e9d25ee7f646c0017e6e6a06fb5c4e6c3881de50e95abfdcd3c330fe7dc2

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