Skip to content

This Python script uses Tesseract OCR to recognize handwritten text from an image file. It is optimized for Windows and includes error handling for missing files and processing issues.

Notifications You must be signed in to change notification settings

Kerim-N/Handwritten-text-recognizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Handwritten Text Recognizer from Photo

This Python script uses Tesseract OCR to recognize handwritten text from an image file. It is optimized for Windows and includes error handling for missing files and processing issues.

Features

  • Uses pytesseract and Pillow for OCR and image handling
  • Checks if the image file exists before processing
  • Handles errors gracefully
  • Prints recognized text to the console

Requirements

  • Python 3.x
  • Tesseract OCR installed on Windows
  • Python packages: pillow, pytesseract

Installation

  1. Install Python and Tesseract OCR.
  2. Install required Python packages:
    pip install pillow pytesseract
  3. Set the correct path to Tesseract in the script if needed:
    pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
  4. Place your image file (e.g., handwritten_note.jpg) in the same folder as the script.

Usage

Run the script in PowerShell:

python "text recognizer from photo.py"

Example Output

πŸ“ Recognized text:
 <recognized text here>

Code

from PIL import Image
import pytesseract
import os

# Set Tesseract path for Windows
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

# Use tessdata_best for handwritten models if available
custom_config = r'--oem 1 --psm 6 -l eng'

def recognize_handwritten(image_path):
    if not os.path.exists(image_path):
        print(f"❌ Image file not found: {image_path}")
        return None
    try:
        img = Image.open(image_path)
        text = pytesseract.image_to_string(img, config=custom_config)
        return text
    except Exception as e:
        print(f"❌ Error processing image: {e}")
        return None

# Example usage
image_file = "handwritten_note.jpg"
text = recognize_handwritten(image_file)
if text:
    print("πŸ“ Reconized text:\n", text)

About

This Python script uses Tesseract OCR to recognize handwritten text from an image file. It is optimized for Windows and includes error handling for missing files and processing issues.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages