🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

ocr-layout-formatter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ocr-layout-formatter

Convert OCR JSON to spatial text preserving document layout

pipPyPI
Version
0.1.1
Maintainers
1

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)

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts