Skip to content

HugoNicolau/text-extraction-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text Extraction from Images using FastAPI and Tesseract

This project provides a simple API for extracting text from images using FastAPI and Tesseract OCR.


Related Repositories


Features

  • Upload an image and extract text using Tesseract OCR.
  • FastAPI backend for handling image uploads and text extraction.
  • Easy to set up and run locally.

Prerequisites

Before running the project, ensure you have the following installed:

  • Python 3.8 or higher
  • Tesseract OCR
  • FastAPI
  • Uvicorn
  • Pillow
  • Pytesseract

Installation

  1. Clone the repository:

    git clone https://github.com/HugoNicolau/text-extraction-py.git
    cd text-extraction-py
  2. Set up a virtual environment:

    python -m venv venv
    source venv/bin/activate  
    # On Windows: venv\Scripts\activate

    Install dependencies:

    pip install -r requirements.txt
  3. Install Tesseract OCR:

    On Ubuntu/Debian:

    sudo apt-get install tesseract-ocr

    On macOS (using Homebrew):

    brew install tesseract

    On Windows, download the installer from Tesseract's GitHub page.


Running the Project

  1. Start the FastAPI server:

    uvicorn main:app --reload

    The server will start at http://localhost:8000.

  2. Test the API:

    You can test the API using curl or a tool like Postman.

    Example using curl:

    curl -X POST -F "file=@/path/to/your/image.png" http://localhost:8000/extract-text/

    Example response:

    {
      "text": "This is the extracted text from the image."
    }

API Endpoints

POST /extract-text/

Extract text from an uploaded image.

Request:

  • File: The image file to process (supported formats: PNG, JPEG, etc.).

Response:

  • text: The extracted text.

Project Structure

text-extraction-py/
├── venv/                  # Virtual environment
├── main.py                # FastAPI application
├── requirements.txt       # Python dependencies
├── README.md              # Project documentation
├── .gitignore             # Files to ignore in Git
└── image/                 # Folder for test images
    └── example-image.png

Usage

  1. Upload an Image:

    Use the /extract-text/ endpoint to upload an image and extract text.

  2. View Extracted Text:

    The API will return the extracted text in JSON format.


Example

Here’s an example of how to use the API with curl:

curl -X POST -F "file=@/path/to/your/image.png" http://localhost:8000/extract-text/

Response:

{
  "text": "This is the extracted text from the image."
}

Contributing

Contributions are welcome! If you'd like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourFeature).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/YourFeature).
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Acknowledgments


Contact

For questions or feedback, please reach out to me on LinkedIn or via email.


About

Python program that reads images

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages