A simple Python application that extracts text from images using OCR (Optical Character Recognition) technology.
This project uses Tesseract OCR engine through the pytesseract Python wrapper to extract text content from image files. It's built with Python and leverages the Pillow library for image processing.
- Extract text from various image formats
- Simple and straightforward implementation
- Error handling for robust operation
Before running this application, you need to install:
- Windows: Download from python.org
- macOS: Pre-installed or use
brew install python3 - Linux: Usually pre-installed or use
sudo apt-get install python3(Debian/Ubuntu) orsudo yum install python3(RHEL/CentOS)
- Download the installer from UB Mannheim's Tesseract releases
- Run the installer and follow the installation wizard
- Add Tesseract to your system PATH or specify the path in your code:
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
Using Homebrew:
brew install tesseractUsing MacPorts:
sudo port install tesseractUbuntu/Debian:
sudo apt update
sudo apt install tesseract-ocrRHEL/CentOS/Fedora:
sudo yum install tesseractArch Linux:
sudo pacman -S tesseract-
Clone this repository or download the files
-
Install Python dependencies:
Windows (Command Prompt or PowerShell):
pip install -r requirements.txt
macOS/Linux:
pip3 install -r requirements.txt
Or use a virtual environment (recommended for all platforms):
# Create virtual environment python -m venv venv # Activate virtual environment # Windows: venv\Scripts\activate # macOS/Linux: source venv/bin/activate # Install dependencies pip install -r requirements.txt
-
Place your image file in the project directory
-
Update the
image_pathvariable inapp.pyto point to your image file:image_path = "your_image.jpg"
-
Run the application:
Windows:
python app.py
macOS/Linux:
python3 app.py
The extracted text will be printed to the console.
Windows Users:
If you get a "TesseractNotFoundError", add this line at the beginning of app.py:
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'All Platforms: To verify Tesseract installation:
tesseract --versionread-image/
├── app.py # Main application script
├── requirements.txt # Python dependencies
├── image1.png # Sample image file
└── README.md # This file
- Pillow: Python Imaging Library for opening and manipulating images
- pytesseract: Python wrapper for Google's Tesseract-OCR Engine
The application includes basic error handling to catch and display any issues that occur during:
- Image file loading
- Text extraction process
- The accuracy of text extraction depends on image quality
- Currently processes one image at a time
- Image path is hardcoded in the script
- Command-line argument support for image paths
- Batch processing of multiple images
- Support for different languages
- Output formatting options (save to file, JSON, etc.)
This project is open source and available under the MIT License.