This tool automatically extracts text from newspaper images and translates it to your target language. The script processes all images in an input folder and outputs both the original and translated text to an output folder.
Before using the script, you need to install the following:
-
Python 3.7+: Download from python.org
-
Tesseract OCR:
- Windows: Download installer from GitHub
- macOS:
brew install tesseract - Linux:
sudo apt install tesseract-ocr
-
Required Python Libraries:
pip install pillow pytesseract googletrans==4.0.0rc1
-
Create two folders:
input- Place newspaper images hereoutput- Translated files will be saved here
-
Download the script (
newspaper_translator.py) to the same directory as the input and output folders.
Run the script with default settings:
python newspaper_translator.pyThis will:
- Process all images in the
inputfolder - Translate extracted text to Spanish (default)
- Save results in the
outputfolder
Customize the behavior with command-line arguments:
python newspaper_translator.py --input custom_input --output custom_output --lang frAvailable arguments:
--input: Specify input folder (default: "input")--output: Specify output folder (default: "output")--lang: Specify target language code (default: "es" for Spanish)
Common language codes:
es: Spanishfr: Frenchde: Germanit: Italianpt: Portugueseru: Russianja: Japaneseko: Koreanzh-cn: Chinese (Simplified)hi: Hindiar: Arabic
For each image processed, the script generates two files in the output folder:
[image_name]_original.txt: The extracted text from the image[image_name]_translated.txt: The translated text
-
Image Quality:
- Use clear, well-lit images
- Ensure text is in focus and not blurry
- Avoid wrinkled or damaged newspaper pages
-
Cropping:
- Crop images to include only the text you want to extract
- Remove unnecessary graphics or images
-
Language Support:
- For non-Latin scripts (e.g., Arabic, Chinese), install the appropriate Tesseract language packages
-
No text extracted:
- Check image quality
- Ensure Tesseract is properly installed
- Try installing additional language packs for Tesseract
-
Translation errors:
- Check internet connection
- If receiving rate limit errors, increase the sleep time in the script
-
File not found errors:
- Ensure input and output folders exist
- Check file permissions
A log file (newspaper_translator.log) is created in the same directory as the script. This log contains detailed information about each processing step and any errors encountered.
-
Place newspaper images in the
inputfolder:news1.jpgarticle2.png
-
Run the script:
python translator.py --lang fr
-
Check the
outputfolder for results:news1_original.txt- Contains the extracted English textnews1_translated.txt- Contains the French translationarticle2_original.txt- Contains the extracted English textarticle2_translated.txt- Contains the French translation