TableOCR
========
.. image:: https://img.shields.io/pypi/v/tableocr.svg
:target: https://pypi.python.org/pypi/tableocr
.. image:: https://readthedocs.org/projects/tableocr/badge/?version=latest
:target: https://tableocr.readthedocs.io/en/latest/?version=latest
:alt: Documentation Status
TableOCR is a powerful and versatile Python library that provides an easy-to-use Optical Character Recognition (OCR) solution for extracting tables from images and PDFs. It offers flexible output options, allowing you to export the extracted data in CSV, XLSX, or other spreadsheet formats.
* Free software: MIT license
* Documentation: https://tableocr.readthedocs.io.
Features
--------
- **Accurate Table Detection**: TableOCR uses advanced computer vision algorithms to accurately detect and extract tables from images and PDFs, even in challenging scenarios with complex layouts or low-quality scans. It employs techniques such as edge detection, connected component analysis, and deep learning-based object detection to locate and isolate tables within the input document.
- **Multiple Input Formats**: Supports a wide range of input formats, including PNG, JPG, BMP, TIFF, and PDF files, allowing for flexibility in processing various types of document sources.
- **Customizable Output**: Offers flexible output options, allowing you to export the extracted data in CSV, XLSX, or other spreadsheet formats of your choice, ensuring seamless integration with your existing data processing workflows.
- **Batch Processing**: Easily process multiple files in a directory or a folder structure, making it ideal for high-volume data extraction tasks, such as digitizing large archives or processing scanned documents at scale.
- **Multi-language Support**: Leverages state-of-the-art OCR engines to support a wide range of languages, enabling accurate table extraction from documents in various languages, including English, Spanish, French, German, Chinese, Arabic, and many more.
- **Parallel Processing**: Utilizes multi-threading and parallel processing capabilities to speed up the table extraction process, significantly reducing processing times for large datasets or complex documents.
- **Configurable Settings**: Provides a range of configuration options to fine-tune the table extraction process, including options for adjusting image pre-processing (e.g., deskewing, denoising, and binarization), OCR engine settings (e.g., language packs, character whitelists), and output formatting (e.g., column delimiters, date formats).
- **Embedded OCR Engines**: TableOCR comes bundled with several popular OCR engines, including Tesseract and LSTM-based models, ensuring high accuracy and flexibility in table extraction. Additional OCR engines can be easily integrated, thanks to the modular design of the library.
- **Seamless Integration**: Designed with a user-friendly API, TableOCR can be easily integrated into your existing Python projects, allowing for efficient table data extraction and analysis workflows, enabling applications in areas such as data mining, research, and business intelligence.
Installation
------------
TableOCR can be installed from PyPI using pip:
.. code-block:: bash
pip install tableocr
Usage
-----
Here's a simple example of how to use TableOCR to extract tables from an image file:
.. code-block:: python
from tableocr import TableOCR
# Initialize the TableOCR instance
ocr = TableOCR()
# Path to the input image or PDF file
image_path = "path/to/image.png"
# Extract tables from the image
tables = ocr.extract(image_path)
# Export the extracted tables to a CSV file
ocr.to_csv("output.csv", tables)
Usage Examples
-----------------------
1. **Batch Processing**:
TableOCR supports batch processing of multiple files in a directory or folder structure. Here's an example:
.. code-block:: python
from tableocr import TableOCR
import os
# Initialize the TableOCR instance
ocr = TableOCR()
# Directory containing input files
input_dir = "path/to/input/directory"
# Iterate over files in the directory
for filename in os.listdir(input_dir):
file_path = os.path.join(input_dir, filename)
tables = ocr.extract(file_path)
# Export tables to individual CSV files
output_file = f"output_{filename}.csv"
ocr.to_csv(output_file, tables)
2. **Configuring OCR Settings**:
You can fine-tune the OCR engine settings to optimize performance for specific document types or languages:
.. code-block:: python
from tableocr import TableOCR, OCRSettings
# Initialize the TableOCR instance
ocr = TableOCR()
# Configure OCR settings
settings = OCRSettings(language="fra", whitelist="0123456789")
ocr.set_ocr_settings(settings)
# Extract tables using the configured settings
image_path = "path/to/image.png"
tables = ocr.extract(image_path)
3. **Customizing Output Formatting**:
TableOCR allows you to customize the output format by specifying column delimiters, date formats, and other formatting options:
.. code-block:: python
from tableocr import TableOCR, OutputSettings
# Initialize the TableOCR instance
ocr = TableOCR()
# Configure output settings
output_settings = OutputSettings(delimiter="|", date_format="%Y-%m-%d")
ocr.set_output_settings(output_settings)
# Extract tables and export to CSV with custom settings
image_path = "path/to/image.png"
tables = ocr.extract(image_path)
ocr.to_csv("output.csv", tables)
For more advanced usage, such as handling PDF files, table structure analysis, and table merging, refer to the `documentation <https://tableocr.readthedocs.io>`_.
Contributing
------------
Contributions to TableOCR are welcome! If you encounter any issues or have ideas for improvements, please open an issue or submit a pull request on the `GitHub repository <https://github.com/salim-benhamadi/tableocr>`_.
Credits
-------
TableOCR was created and is maintained by `Salim Benhamadi <https://github.com/salim-benhamadi>`_.
License
-------
This project is licensed under the terms of the MIT license.
=======
History
=======
0.1.0 (2024-03-07)
------------------
* First release on PyPI.
Raw data
{
"_id": null,
"home_page": "https://github.com/salim-benhamadi/tableocr",
"name": "TabularOCR",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "TabularOCR",
"author": "Salim Benhamadi",
"author_email": "salim.benhamadi@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/dc/23/e82f3a7c31a18faff2f767ed7a4f7deccf5ab8e2ff1f803b486f2696b69c/TabularOCR-0.1.0.tar.gz",
"platform": null,
"description": "TableOCR\r\n========\r\n\r\n.. image:: https://img.shields.io/pypi/v/tableocr.svg\r\n :target: https://pypi.python.org/pypi/tableocr\r\n\r\n.. image:: https://readthedocs.org/projects/tableocr/badge/?version=latest\r\n :target: https://tableocr.readthedocs.io/en/latest/?version=latest\r\n :alt: Documentation Status\r\n\r\nTableOCR is a powerful and versatile Python library that provides an easy-to-use Optical Character Recognition (OCR) solution for extracting tables from images and PDFs. It offers flexible output options, allowing you to export the extracted data in CSV, XLSX, or other spreadsheet formats.\r\n\r\n* Free software: MIT license\r\n* Documentation: https://tableocr.readthedocs.io.\r\n\r\nFeatures\r\n--------\r\n\r\n- **Accurate Table Detection**: TableOCR uses advanced computer vision algorithms to accurately detect and extract tables from images and PDFs, even in challenging scenarios with complex layouts or low-quality scans. It employs techniques such as edge detection, connected component analysis, and deep learning-based object detection to locate and isolate tables within the input document.\r\n\r\n- **Multiple Input Formats**: Supports a wide range of input formats, including PNG, JPG, BMP, TIFF, and PDF files, allowing for flexibility in processing various types of document sources.\r\n\r\n- **Customizable Output**: Offers flexible output options, allowing you to export the extracted data in CSV, XLSX, or other spreadsheet formats of your choice, ensuring seamless integration with your existing data processing workflows.\r\n\r\n- **Batch Processing**: Easily process multiple files in a directory or a folder structure, making it ideal for high-volume data extraction tasks, such as digitizing large archives or processing scanned documents at scale.\r\n\r\n- **Multi-language Support**: Leverages state-of-the-art OCR engines to support a wide range of languages, enabling accurate table extraction from documents in various languages, including English, Spanish, French, German, Chinese, Arabic, and many more.\r\n\r\n- **Parallel Processing**: Utilizes multi-threading and parallel processing capabilities to speed up the table extraction process, significantly reducing processing times for large datasets or complex documents.\r\n\r\n- **Configurable Settings**: Provides a range of configuration options to fine-tune the table extraction process, including options for adjusting image pre-processing (e.g., deskewing, denoising, and binarization), OCR engine settings (e.g., language packs, character whitelists), and output formatting (e.g., column delimiters, date formats).\r\n\r\n- **Embedded OCR Engines**: TableOCR comes bundled with several popular OCR engines, including Tesseract and LSTM-based models, ensuring high accuracy and flexibility in table extraction. Additional OCR engines can be easily integrated, thanks to the modular design of the library.\r\n\r\n- **Seamless Integration**: Designed with a user-friendly API, TableOCR can be easily integrated into your existing Python projects, allowing for efficient table data extraction and analysis workflows, enabling applications in areas such as data mining, research, and business intelligence.\r\n\r\nInstallation\r\n------------\r\n\r\nTableOCR can be installed from PyPI using pip:\r\n\r\n.. code-block:: bash\r\n\r\n pip install tableocr\r\n\r\nUsage\r\n-----\r\n\r\nHere's a simple example of how to use TableOCR to extract tables from an image file:\r\n\r\n.. code-block:: python\r\n\r\n from tableocr import TableOCR\r\n\r\n # Initialize the TableOCR instance\r\n ocr = TableOCR()\r\n\r\n # Path to the input image or PDF file\r\n image_path = \"path/to/image.png\"\r\n\r\n # Extract tables from the image\r\n tables = ocr.extract(image_path)\r\n\r\n # Export the extracted tables to a CSV file\r\n ocr.to_csv(\"output.csv\", tables)\r\n\r\nUsage Examples\r\n-----------------------\r\n\r\n1. **Batch Processing**:\r\n\r\nTableOCR supports batch processing of multiple files in a directory or folder structure. Here's an example:\r\n\r\n.. code-block:: python\r\n\r\n from tableocr import TableOCR\r\n import os\r\n\r\n # Initialize the TableOCR instance\r\n ocr = TableOCR()\r\n\r\n # Directory containing input files\r\n input_dir = \"path/to/input/directory\"\r\n\r\n # Iterate over files in the directory\r\n for filename in os.listdir(input_dir):\r\n file_path = os.path.join(input_dir, filename)\r\n tables = ocr.extract(file_path)\r\n\r\n # Export tables to individual CSV files\r\n output_file = f\"output_{filename}.csv\"\r\n ocr.to_csv(output_file, tables)\r\n\r\n2. **Configuring OCR Settings**:\r\n\r\nYou can fine-tune the OCR engine settings to optimize performance for specific document types or languages:\r\n\r\n.. code-block:: python\r\n\r\n from tableocr import TableOCR, OCRSettings\r\n\r\n # Initialize the TableOCR instance\r\n ocr = TableOCR()\r\n\r\n # Configure OCR settings\r\n settings = OCRSettings(language=\"fra\", whitelist=\"0123456789\")\r\n ocr.set_ocr_settings(settings)\r\n\r\n # Extract tables using the configured settings\r\n image_path = \"path/to/image.png\"\r\n tables = ocr.extract(image_path)\r\n\r\n3. **Customizing Output Formatting**:\r\n\r\nTableOCR allows you to customize the output format by specifying column delimiters, date formats, and other formatting options:\r\n\r\n.. code-block:: python\r\n\r\n from tableocr import TableOCR, OutputSettings\r\n\r\n # Initialize the TableOCR instance\r\n ocr = TableOCR()\r\n\r\n # Configure output settings\r\n output_settings = OutputSettings(delimiter=\"|\", date_format=\"%Y-%m-%d\")\r\n ocr.set_output_settings(output_settings)\r\n\r\n # Extract tables and export to CSV with custom settings\r\n image_path = \"path/to/image.png\"\r\n tables = ocr.extract(image_path)\r\n ocr.to_csv(\"output.csv\", tables)\r\n\r\nFor more advanced usage, such as handling PDF files, table structure analysis, and table merging, refer to the `documentation <https://tableocr.readthedocs.io>`_.\r\n\r\nContributing\r\n------------\r\n\r\nContributions to TableOCR are welcome! If you encounter any issues or have ideas for improvements, please open an issue or submit a pull request on the `GitHub repository <https://github.com/salim-benhamadi/tableocr>`_.\r\n\r\nCredits\r\n-------\r\n\r\nTableOCR was created and is maintained by `Salim Benhamadi <https://github.com/salim-benhamadi>`_.\r\n\r\nLicense\r\n-------\r\n\r\nThis project is licensed under the terms of the MIT license.\r\n\r\n\r\n=======\r\nHistory\r\n=======\r\n\r\n0.1.0 (2024-03-07)\r\n------------------\r\n\r\n* First release on PyPI.\r\n",
"bugtrack_url": null,
"license": "MIT license",
"summary": "TabularOCR is a Python library that provides an easy-to-use Optical Character Recognition (OCR) solution for extracting tables from images and PDFs. It offers flexible output options, allowing you to export the extracted data in CSV, XLSX, or other spreadsheet formats.",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/salim-benhamadi/tableocr"
},
"split_keywords": [
"tabularocr"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5ab606ad408f816e963296277d0e7f65ab8587e0f744222f456c6bce348dc31a",
"md5": "76cdf5bd7de05ad211984608377cef7d",
"sha256": "6f4493b6e80bb7f701a7885dee6d0b28f132a8ecc0c231728c13e05fdefd701d"
},
"downloads": -1,
"filename": "TabularOCR-0.1.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "76cdf5bd7de05ad211984608377cef7d",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.6",
"size": 5016,
"upload_time": "2024-03-08T23:52:38",
"upload_time_iso_8601": "2024-03-08T23:52:38.247070Z",
"url": "https://files.pythonhosted.org/packages/5a/b6/06ad408f816e963296277d0e7f65ab8587e0f744222f456c6bce348dc31a/TabularOCR-0.1.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dc23e82f3a7c31a18faff2f767ed7a4f7deccf5ab8e2ff1f803b486f2696b69c",
"md5": "d00d470cbe4f91b39c6877ca9844d40a",
"sha256": "cf7bbdeaeb78fb93070549a4c160aeae9391cf6b6c32c802edab4146642ea2f1"
},
"downloads": -1,
"filename": "TabularOCR-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "d00d470cbe4f91b39c6877ca9844d40a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 10846,
"upload_time": "2024-03-08T23:52:41",
"upload_time_iso_8601": "2024-03-08T23:52:41.252851Z",
"url": "https://files.pythonhosted.org/packages/dc/23/e82f3a7c31a18faff2f767ed7a4f7deccf5ab8e2ff1f803b486f2696b69c/TabularOCR-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-08 23:52:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "salim-benhamadi",
"github_project": "tableocr",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "anyio",
"specs": [
[
"==",
"4.3.0"
]
]
},
{
"name": "astor",
"specs": [
[
"==",
"0.8.1"
]
]
},
{
"name": "attrdict",
"specs": [
[
"==",
"2.0.1"
]
]
},
{
"name": "Babel",
"specs": [
[
"==",
"2.14.0"
]
]
},
{
"name": "bce-python-sdk",
"specs": [
[
"==",
"0.9.5"
]
]
},
{
"name": "beautifulsoup4",
"specs": [
[
"==",
"4.12.3"
]
]
},
{
"name": "blinker",
"specs": [
[
"==",
"1.7.0"
]
]
},
{
"name": "cachetools",
"specs": [
[
"==",
"5.3.3"
]
]
},
{
"name": "certifi",
"specs": [
[
"==",
"2024.2.2"
]
]
},
{
"name": "cffi",
"specs": [
[
"==",
"1.16.0"
]
]
},
{
"name": "charset-normalizer",
"specs": [
[
"==",
"3.3.2"
]
]
},
{
"name": "click",
"specs": [
[
"==",
"8.1.7"
]
]
},
{
"name": "colorama",
"specs": [
[
"==",
"0.4.6"
]
]
},
{
"name": "contourpy",
"specs": [
[
"==",
"1.2.0"
]
]
},
{
"name": "cryptography",
"specs": [
[
"==",
"42.0.5"
]
]
},
{
"name": "cssselect",
"specs": [
[
"==",
"1.2.0"
]
]
},
{
"name": "cssutils",
"specs": [
[
"==",
"2.9.0"
]
]
},
{
"name": "cycler",
"specs": [
[
"==",
"0.12.1"
]
]
},
{
"name": "Cython",
"specs": [
[
"==",
"3.0.9"
]
]
},
{
"name": "decorator",
"specs": [
[
"==",
"5.1.1"
]
]
},
{
"name": "et-xmlfile",
"specs": [
[
"==",
"1.1.0"
]
]
},
{
"name": "fire",
"specs": [
[
"==",
"0.5.0"
]
]
},
{
"name": "Flask",
"specs": [
[
"==",
"3.0.2"
]
]
},
{
"name": "flask-babel",
"specs": [
[
"==",
"4.0.0"
]
]
},
{
"name": "flatbuffers",
"specs": [
[
"==",
"24.3.6"
]
]
},
{
"name": "fonttools",
"specs": [
[
"==",
"4.49.0"
]
]
},
{
"name": "future",
"specs": [
[
"==",
"1.0.0"
]
]
},
{
"name": "h11",
"specs": [
[
"==",
"0.14.0"
]
]
},
{
"name": "httpcore",
"specs": [
[
"==",
"1.0.4"
]
]
},
{
"name": "httpx",
"specs": [
[
"==",
"0.27.0"
]
]
},
{
"name": "idna",
"specs": [
[
"==",
"3.6"
]
]
},
{
"name": "imageio",
"specs": [
[
"==",
"2.34.0"
]
]
},
{
"name": "imgaug",
"specs": [
[
"==",
"0.4.0"
]
]
},
{
"name": "iopath",
"specs": [
[
"==",
"0.1.10"
]
]
},
{
"name": "itsdangerous",
"specs": [
[
"==",
"2.1.2"
]
]
},
{
"name": "Jinja2",
"specs": [
[
"==",
"3.1.3"
]
]
},
{
"name": "kiwisolver",
"specs": [
[
"==",
"1.4.5"
]
]
},
{
"name": "layoutparser",
"specs": [
[
"==",
"0.3.4"
]
]
},
{
"name": "lazy_loader",
"specs": [
[
"==",
"0.3"
]
]
},
{
"name": "libclang",
"specs": [
[
"==",
"16.0.6"
]
]
},
{
"name": "lmdb",
"specs": [
[
"==",
"1.4.1"
]
]
},
{
"name": "lxml",
"specs": [
[
"==",
"5.1.0"
]
]
},
{
"name": "MarkupSafe",
"specs": [
[
"==",
"2.1.5"
]
]
},
{
"name": "matplotlib",
"specs": [
[
"==",
"3.8.3"
]
]
},
{
"name": "networkx",
"specs": [
[
"==",
"3.2.1"
]
]
},
{
"name": "numpy",
"specs": [
[
"==",
"1.26.4"
]
]
},
{
"name": "opencv-contrib-python",
"specs": [
[
"==",
"4.6.0.66"
]
]
},
{
"name": "opencv-python",
"specs": [
[
"==",
"4.6.0.66"
]
]
},
{
"name": "opencv-python-headless",
"specs": [
[
"==",
"4.9.0.80"
]
]
},
{
"name": "openpyxl",
"specs": [
[
"==",
"3.1.2"
]
]
},
{
"name": "opt-einsum",
"specs": [
[
"==",
"3.3.0"
]
]
},
{
"name": "packaging",
"specs": [
[
"==",
"23.2"
]
]
},
{
"name": "paddleocr",
"specs": [
[
"==",
"2.7.0.3"
]
]
},
{
"name": "paddlepaddle",
"specs": [
[
"==",
"2.6.0"
]
]
},
{
"name": "pandas",
"specs": [
[
"==",
"2.2.1"
]
]
},
{
"name": "pdf2docx",
"specs": [
[
"==",
"0.5.8"
]
]
},
{
"name": "pdf2image",
"specs": [
[
"==",
"1.17.0"
]
]
},
{
"name": "pdfminer.six",
"specs": [
[
"==",
"20231228"
]
]
},
{
"name": "pdfplumber",
"specs": [
[
"==",
"0.11.0"
]
]
},
{
"name": "pillow",
"specs": [
[
"==",
"10.2.0"
]
]
},
{
"name": "portalocker",
"specs": [
[
"==",
"2.8.2"
]
]
},
{
"name": "premailer",
"specs": [
[
"==",
"3.10.0"
]
]
},
{
"name": "protobuf",
"specs": [
[
"==",
"3.20.2"
]
]
},
{
"name": "psutil",
"specs": [
[
"==",
"5.9.8"
]
]
},
{
"name": "pyclipper",
"specs": [
[
"==",
"1.3.0.post5"
]
]
},
{
"name": "pycparser",
"specs": [
[
"==",
"2.21"
]
]
},
{
"name": "pycryptodome",
"specs": [
[
"==",
"3.20.0"
]
]
},
{
"name": "pyparsing",
"specs": [
[
"==",
"3.1.2"
]
]
},
{
"name": "pypdfium2",
"specs": [
[
"==",
"4.27.0"
]
]
},
{
"name": "python-dateutil",
"specs": [
[
"==",
"2.9.0.post0"
]
]
},
{
"name": "python-docx",
"specs": [
[
"==",
"1.1.0"
]
]
},
{
"name": "pytz",
"specs": [
[
"==",
"2024.1"
]
]
},
{
"name": "pywin32",
"specs": [
[
"==",
"306"
]
]
},
{
"name": "PyYAML",
"specs": [
[
"==",
"6.0.1"
]
]
},
{
"name": "rapidfuzz",
"specs": [
[
"==",
"3.6.2"
]
]
},
{
"name": "rarfile",
"specs": [
[
"==",
"4.1"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.31.0"
]
]
},
{
"name": "scikit-image",
"specs": [
[
"==",
"0.22.0"
]
]
},
{
"name": "scipy",
"specs": [
[
"==",
"1.12.0"
]
]
},
{
"name": "shapely",
"specs": [
[
"==",
"2.0.3"
]
]
},
{
"name": "six",
"specs": [
[
"==",
"1.16.0"
]
]
},
{
"name": "sniffio",
"specs": [
[
"==",
"1.3.1"
]
]
},
{
"name": "soupsieve",
"specs": [
[
"==",
"2.5"
]
]
},
{
"name": "tensorboard-data-server",
"specs": [
[
"==",
"0.7.2"
]
]
},
{
"name": "tensorflow-estimator",
"specs": [
[
"==",
"2.15.0"
]
]
},
{
"name": "tensorflow-io-gcs-filesystem",
"specs": [
[
"==",
"0.31.0"
]
]
},
{
"name": "termcolor",
"specs": [
[
"==",
"2.4.0"
]
]
},
{
"name": "tifffile",
"specs": [
[
"==",
"2024.2.12"
]
]
},
{
"name": "tqdm",
"specs": [
[
"==",
"4.66.2"
]
]
},
{
"name": "typing_extensions",
"specs": [
[
"==",
"4.10.0"
]
]
},
{
"name": "tzdata",
"specs": [
[
"==",
"2024.1"
]
]
},
{
"name": "urllib3",
"specs": [
[
"==",
"2.2.1"
]
]
},
{
"name": "visualdl",
"specs": [
[
"==",
"2.5.3"
]
]
},
{
"name": "Werkzeug",
"specs": [
[
"==",
"3.0.1"
]
]
},
{
"name": "wrapt",
"specs": [
[
"==",
"1.14.1"
]
]
}
],
"tox": true,
"lcname": "tabularocr"
}