Skip to content

andalike/python-image-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Image Text Extraction Tool

A simple Python application that extracts text from images using OCR (Optical Character Recognition) technology.

Overview

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.

Features

  • Extract text from various image formats
  • Simple and straightforward implementation
  • Error handling for robust operation

Prerequisites

Before running this application, you need to install:

1. Python 3.x

  • 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) or sudo yum install python3 (RHEL/CentOS)

2. Tesseract OCR Engine

Windows

  1. Download the installer from UB Mannheim's Tesseract releases
  2. Run the installer and follow the installation wizard
  3. 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'

macOS

Using Homebrew:

brew install tesseract

Using MacPorts:

sudo port install tesseract

Linux

Ubuntu/Debian:

sudo apt update
sudo apt install tesseract-ocr

RHEL/CentOS/Fedora:

sudo yum install tesseract

Arch Linux:

sudo pacman -S tesseract

Installation

  1. Clone this repository or download the files

  2. 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

Usage

  1. Place your image file in the project directory

  2. Update the image_path variable in app.py to point to your image file:

    image_path = "your_image.jpg"
  3. Run the application:

    Windows:

    python app.py

    macOS/Linux:

    python3 app.py

The extracted text will be printed to the console.

Troubleshooting

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 --version

Project Structure

read-image/
├── app.py              # Main application script
├── requirements.txt    # Python dependencies
├── image1.png         # Sample image file
└── README.md          # This file

Dependencies

  • Pillow: Python Imaging Library for opening and manipulating images
  • pytesseract: Python wrapper for Google's Tesseract-OCR Engine

Error Handling

The application includes basic error handling to catch and display any issues that occur during:

  • Image file loading
  • Text extraction process

Limitations

  • The accuracy of text extraction depends on image quality
  • Currently processes one image at a time
  • Image path is hardcoded in the script

Future Enhancements

  • Command-line argument support for image paths
  • Batch processing of multiple images
  • Support for different languages
  • Output formatting options (save to file, JSON, etc.)

License

This project is open source and available under the MIT License.

About

python-image-reader

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages