This is a self hostable Flask application that allows users to upload an image and extract text from it using Optical Character Recognition (OCR) via pytesseract. The extracted text is then displayed in a textarea on the page.
- Upload an image file (e.g., PNG, JPEG).
- Automatically extract text from the uploaded image using OCR.
- Display the extracted text in a textarea.
- Flask: A lightweight WSGI web application framework.
- Pillow: A Python Imaging Library (PIL) fork to handle image files.
- pytesseract: Python wrapper for Tesseract OCR to perform the text extraction.
-
Python (3.x recommended)
-
Tesseract OCR: Install Tesseract OCR engine:
- For Ubuntu: sudo apt install tesseract-ocr
- For Windows: Download Tesseract OCR
- Clone the repository:
git clone https://github.com/tshenolo/image-to-text-converter.git
cd image-to-text-converter
- Create a virtual environment:
python3 -m venv venv
- Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- Install the required Python packages:
pip install -r requirements.txt
- Run the Flask app:
python app.py
- Access the application: Open a web browser and go to http://127.0.0.1:5000 to use the Image to Text Converter.
When you're finished, you can deactivate the virtual environment with:
deactivate
You can use Docker to containerize the application, making it easy to deploy and run consistently across different environments.
- Build the Docker image:
docker build -t image-to-text-converter .
- Run the Docker container:
docker run -d -p 5000:5000 --name image-to-text-converter image-to-text-converter
- Open a web browser and go to http://localhost:5000 to access the app.
image-to-text-converter/
│
├── app.py # Main Flask application
├── README.md # Project documentation
├── Dockerfile # Docker configuration file
├── requirements.txt # Project dependencies
├── uploads/ # Folder to temporarily store uploaded images
│
└── templates/
└── index.html # HTML template for the main page
- Go to the main page of the app.
- Upload an image using the file input.
- Click the "Convert to Text" button.
- The extracted text will be displayed in the textarea below.
If you receive an error related to Tesseract, ensure that it is installed and accessible in your system's PATH.
For Windows users, you may need to specify the Tesseract executable path in app.py:
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
If you want to contribute to this project, follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Make your changes and commit them.
- Push your changes to your fork.
- Open a pull request.
This project is open source and available under the MIT License.