https://github.com/theognis1002/ocr-restaurant-menu-import
Simple OCR restaurant menu import script
https://github.com/theognis1002/ocr-restaurant-menu-import
machine-learning multiprocessing ocr precommit python3
Last synced: 30 days ago
JSON representation
Simple OCR restaurant menu import script
- Host: GitHub
- URL: https://github.com/theognis1002/ocr-restaurant-menu-import
- Owner: theognis1002
- License: mit
- Created: 2024-08-08T18:35:15.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-06T18:12:23.000Z (over 1 year ago)
- Last Synced: 2025-03-05T04:32:04.253Z (over 1 year ago)
- Topics: machine-learning, multiprocessing, ocr, precommit, python3
- Language: Python
- Homepage:
- Size: 6.22 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OCR Image Menu Text Extractor
## Overview

This script extracts text from images of restaurant menus using Optical Character Recognition (OCR) and then enhances and structures the extracted text using a language model. The script processes images in a specified directory and outputs the structured data to a JSON file.
## Features
- **OCR Extraction**: Uses `pytesseract` to extract text from images.
- **Text Enhancement**: Utilizes a language model (`litellm`) to convert raw text into structured JSON.
- **Multiprocessing**: Processes multiple images in parallel to improve performance.
- **Supports Multiple Formats**: Handles various image formats such as JPEG, PNG, BMP, and TIFF.
## Requirements
- Python 3.12
- `pytesseract`
- `Pillow` (PIL)
- `litellm`
- `multiprocessing` (part of Python standard library)
You can install the required Python packages using pip:
```bash
pip install -r requirements.txt
```
## Configuration
- `IMAGES_DIR`: Directory where the images are located (default: `images/`).
- `OUTPUT_FILE`: File where the structured JSON data will be saved (default: `output.json`).
## Usage
1. Place the script in your desired directory.
2. Ensure your images are located in the directory specified by `IMAGES_DIR`.
3. `pip install -r requirements.txt`
4. `python main.py`
## Script Details
### Functions
- `extract_text(image_path: str) -> str`: Extracts text from the specified image using OCR.
- `enhance_and_jsonify_text(raw_text: str) -> dict`: Enhances raw text and converts it into structured JSON using a language model.
- `process_image(image_file: Path) -> dict`: Processes a single image file and returns the result as a dictionary.
- `process_images_from_directory(directory_path: str) -> dict`: Processes all images in the given directory using multiprocessing.
- `main(directory_path: str, output_file: str) -> None`: Main function to process images and write results to a JSON file.
## 📜 License
Distributed under the MIT License. See [`LICENSE`](./LICENSE) for more information.