This project provides a simple command-line tool to extract text from images using Optical Character Recognition (OCR) with Tesseract. It supports processing single image files or directories containing multiple images.
- Python 3.x
- Tesseract OCR installed and added to your system's PATH
- Required Python packages:
Pillow,pytesseract
- Clone the repository or download the script.
- Install the required Python packages using pip:
pip install Pillow pytesseract
The script can be run from the command line. Below are the available options:
python ocr.py [-h] [-o OUTPUT] [-l LANG] inputinput: Path to an image file or directory containing images.-o OUTPUT,--output OUTPUT: Path to save the extracted text (file or directory). If not provided, the extracted text will be printed to the console or saved in a directory namedocr_resultswithin the input directory.-l LANG,--lang LANG: Language code for OCR (default:engfor English). See Tesseract language data files for available language codes.
-
Extract text from a single image and print to console:
python ocr.py path/to/image.jpg
-
Extract text from a single image and save to a file:
python ocr.py path/to/image.jpg -o path/to/output.txt
-
Extract text from all images in a directory and save to a directory:
python ocr.py path/to/images -o path/to/output_directory
The script uses Python's logging module to log information and errors. Logs are printed to the console with timestamps and log levels.
If Tesseract OCR is not installed or not in the system's PATH, the script will print an error message and exit. Ensure Tesseract is installed and accessible before running the script.
One of the future goals of this project is to enhance its capabilities to recognize handwritten text. Handwriting recognition is more challenging than printed text due to the variability in individual writing styles. We plan to explore and integrate advanced machine learning models and techniques to improve the accuracy of handwriting recognition.
In addition to extracting text, we aim to incorporate Natural Language Processing (NLP) packages to further process and analyze the extracted text. This could include features such as:
- Text summarization
- Named entity recognition (NER)
- Sentiment analysis
- Language translation
By leveraging NLP, we can provide more meaningful insights and applications for the extracted text, making the tool more versatile and powerful.
This project is licensed under the MIT License. See the LICENSE file for details.