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 -e .

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.0.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.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ocr_layout_formatter-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 f926a627baf3f9fe679f5c7828e26b94e5bc0267553043cb685d9f6ddac899f4
MD5 6f494161222bf8956bd824fad7f75f2d
BLAKE2b-256 d5e22765ae90fd18c2e535eef7e6f6a98c5f8bf67042c86184a0e7e80cd9dc73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ocr_layout_formatter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f00af29752110f5e343794cac36ef137b67b050bfb76fee6e372029fdffb9dd9
MD5 9e495786bc00c90e2f14b4c1d21068e7
BLAKE2b-256 10ca12adc4c79cb4d5eaa180b2008f046ed82a7ca49cf8e74a61ad81076007b5

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