A console/terminal demo of OCR with Tesseract via pytesseract, for Windows 11 and Ubuntu Linux 24.04. It recognizes the text in an image, prints it, and saves it to model/ocr/output.txt. Windows uses the bundled Tesseract 4.00 (in bin/Tesseract-OCR, with 106 language packs including English and Chinese) out of the box; Ubuntu uses the system Tesseract. It runs fully offline after setup and needs no GPU.
[Prerequisites]
- Operating system: Windows 11 or Ubuntu Linux 24.04.
- Python 3 and pip.
- Windows needs no separate Tesseract install, because it is bundled; on Ubuntu, install it first with sudo apt install tesseract-ocr.
- No GPU required; an ordinary CPU is enough.
[Instructions]
Step 1: Create the virtual environment
Create the venv and install the requirements (pytesseract and Pillow).
Windows: src\01_venv_create.bat
Linux: sudo apt install tesseract-ocr
Linux: bash src/01_venv_create.sh
Step 2: Activate the virtual environment
Activate the venv. On Linux, source the script.
Windows: src\02_venv_activate.bat
Linux: source src/02_venv_activate.sh
Step 3: Run the OCR
Recognize the text in the image. Any extra arguments are forwarded to the program.
Windows: src\03_ocr.bat
Linux: bash src/03_ocr.sh
Step 4: Remove the virtual environment
Delete the venv/ folder.
Windows: src\99_venv_clear.bat
Linux: bash src/99_venv_clear.sh
[Python Entry Point]
- src/ocr.py: [--image data/input.png] [--lang eng] [--tesseract PATH] [--output model/ocr/output.txt] [--show]. --lang takes language codes such as eng or chi_tra, and several languages can be combined with a plus sign, for example eng+chi_tra.
[Usage Notes]
- The bundled Windows Tesseract ships all 106 language packs; on Ubuntu, install extra languages with sudo apt install tesseract-ocr-{lang}, for example tesseract-ocr-chi-tra for traditional Chinese.
- bin/tesseract-ocr-setup-4.00.00dev.exe is the original Windows installer and is not needed to run the demo, because the extracted bin/Tesseract-OCR is used directly.
[References]
- Tesseract OCR: https://github.com/tesseract-ocr/tesseract
- pytesseract: https://pypi.org/project/pytesseract/
This SDK is built in AppForAI - AI Dev Tools.
Purchase license separately: USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.