Skip to main content

Detect and convert table image to html table

Project description

Table2HTML

A Python package that converts table images into HTML format using Object Detection model and OCR.

Installation

pip install table2html

Usage

Initialize

from table2html import Table2HTML
table2html = Table2HTML()

Table Detection

detection_data = table2html.TableDetect(image)
# Output: {"table_bbox": Tuple[int]}

# Visualize table detection
from table2html.source import visualize_boxes
cv2.imwrite(
    "table_detection.jpg", 
    visualize_boxes(
        image, 
        [detection_data["table_bbox"]], 
        color=(0, 0, 255),
        thickness=1
    )
)

Table detection result:

Table Detection Example

Structure Detection

data = table2html.StructureDetect(image)
# Output: {
#   "cells": List[Dict],
#   "num_rows": int,
#   "num_cols": int,
#   "html": str
# }

# Visualize structure detection
from table2html.source import visualize_boxes
cv2.imwrite(
    "structure_detection.jpg", 
    visualize_boxes(
        image, 
        [cell['box'] for cell in data['cells']], 
        color=(0, 255, 0),
        thickness=1
    )
)

# Write HTML output
with open('table.html', 'w') as f:
    f.write(data["html"])

Structure detection result:

Structure Detection Example

Full Pipeline

Note: The cell coordinates are relative to the cropped table image.

data = table2html(image)
# Output: {
#   "table_bbox": Tuple[int],
#   "cells": List[Dict],
#   "num_rows": int,
#   "num_cols": int,
#   "html": str
# } 

Extracted html:

Age Sample Size Mean S.E. Ratio Index a
19-30years 5 78980 15580 5.1
31-35years 13 25300 4860 2.1
36-40 years 14 21450 2650 4.7
41-45 years 32 7320 1450 0.8
>45 years 36 1880 310 1.0

Input

  • image: numpy.ndarray (OpenCV/cv2 image format)

Outputs

  1. table_bbox: Tuple[int] - Bounding box coordinates (x1, y1, x2, y2) of the table
  2. cells: List[Dict] - List of cell dictionaries, where each dictionary contains:
    • row: int - Row index
    • column: int - Column index
    • box: Tuple[int] - Bounding box coordinates (x1, y1, x2, y2)
    • text: str - Cell text content
  3. num_rows: int - Number of rows in the table
  4. num_cols: int - Number of columns in the table
  5. html: str - HTML representation of the table

License

This project is licensed under the Apache License 2.0. See the LICENSE file for 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

table2html-1.2.0.tar.gz (80.1 MB view details)

Uploaded Source

Built Distribution

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

table2html-1.2.0-py3-none-any.whl (80.1 MB view details)

Uploaded Python 3

File details

Details for the file table2html-1.2.0.tar.gz.

File metadata

  • Download URL: table2html-1.2.0.tar.gz
  • Upload date:
  • Size: 80.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for table2html-1.2.0.tar.gz
Algorithm Hash digest
SHA256 5a41a9e34a27b0b9f6caad9030fdc83854d8e214fdc8ce4d90de0a652efb67d1
MD5 bc0e710b285ccb6a127b53b98db545a4
BLAKE2b-256 86a9edd6cc032893f3cb0dd2134e5561ebdeccc710454e9a624fde5ced0d48fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for table2html-1.2.0.tar.gz:

Publisher: workflow.yml on jayllfpt/table2html

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file table2html-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: table2html-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 80.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for table2html-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50722fe9c96a6c1fe4403454ac80f34eb39dd54ed61f6990ce7ac0eebace7238
MD5 6a6d726a9278b67e64195a31e122cf16
BLAKE2b-256 43a9d5ca8783c8ca3bf8777a435bb29ddac53b53f81f6882507e537fbda1b327

See more details on using hashes here.

Provenance

The following attestation bundles were made for table2html-1.2.0-py3-none-any.whl:

Publisher: workflow.yml on jayllfpt/table2html

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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