Skip to content

SharathxD/TableExtraction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TABLE EXTRACTION using OCR

This project automates table extraction from scanned images or documents using a hybrid deep learning approach:

  1. Table detection with Hugging Face’s Table Transformer.
  2. Cropping & padding detected regions.
  3. Table structure recognition with PaddleOCR PPStructureV3.
  4. Export to Excel for easy downstream use.

πŸš€ Features

  • Detects multiple tables in a single page image.
  • Automatically crops detected regions with margin padding.
  • Recognizes table structure and cell text.
  • Exports structured tables into Excel (.xlsx).
  • Supports both CPU and GPU acceleration.
  • Works with JPEG / PNG / scanned document images.

πŸ“‚ Project Structure

project/
│── main.py              # Main pipeline script
│── requirements.txt     # Python dependencies
│── README.md            # Documentation
│── input/               # Place input images here
│── output/              # Cropped tables + extracted Excel files

βš™οΈ Installation

1. Clone the repository

git clone https://github.com/yourusername/table-extraction.git
cd table-extraction

2. Create a virtual environment (recommended)

python3 -m venv venv
source venv/bin/activate   # Linux / Mac
venv\Scripts\activate      # Windows

3. Install dependencies

pip install -r requirements.txt

▢️ Usage

  1. Place your input image (e.g., try.jpeg) in the input/ folder.

  2. Run the script:

python main.py
  1. Outputs:
  • Cropped tables β†’ stored as .png in output/.
  • Extracted structured tables β†’ saved as Excel .xlsx in output/.

πŸ”„ Workflow / Userflow

  1. Input Image

    • User provides a scanned image/document (JPEG or PNG).
  2. Table Detection

    • Hugging Face Table Transformer locates tables and returns bounding boxes.
  3. Cropping & Expansion

    • Each bounding box is expanded by 0.3 cm margin (converted to pixels).
    • The table region is cropped and saved as an image.
  4. Table Recognition

    • Cropped tables are passed to PaddleOCR PPStructureV3.

    • Recognizes:

      • Table grid structure (rows/columns).
      • Text inside each cell.
  5. Export Results

    • Each detected table is exported as:

      • table_XX.png (cropped table image).
      • table_XX.xlsx (structured Excel file).
  6. Logs & Timing

    • Console prints:

      • Number of detected tables.
      • Confidence scores.
      • Output file paths.
      • Total execution time.

πŸ’» Example Run

python main.py

Example output:

Table 0 cropped: output/table_00.png (score=0.912)
Table 1 cropped: output/table_01.png (score=0.878)
Parsed results saved in output/
Execution time: 1.42 mins

⚑ Tech Stack

  • PyTorch β†’ Table Transformer inference.
  • Hugging Face Transformers β†’ Pretrained model loading.
  • Pillow β†’ Image manipulation.
  • PaddleOCR (PPStructureV3) β†’ Table structure + OCR.
  • NumPy β†’ Array operations.

About

Table Extraction from images , using microsoft DETR model and PPStructure-V3 from PaddleOCR

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages