Recently I have been trying to create a tool that utilise Tkinter GUI to capture a certain part of the screen, then use OCR to convert the screen capture to a string and pass the string to another part of the python program.
I was originally thinking of using Keras or other ML framework to train my own LSTM network in order to achieve OCR. Then I came across this OCR engine by Google that is also utilising LSTM network to do text recognition, which is called Tesseract. Reading through the development docs for Tesseract, only Tesseract 4.0+ has LSTM text recognition. Unexpectedly, after I got everything working in Linux easily with Anaconda, I was having problem to deploy Tesseract 4.0+ onto my office computer (Windows 64 bit environment), and the only working version from Anaconda on Windows is 3.7.
This tutorial is to make the newest Tesseract 5.0 alpha to work on the windows environment with Python.
After a bit of research, I finally found the following method to make the whole thing work(without having to change PATH etc).
- Download the windows installer from https://github.com/UB-Mannheim/tesseract/wiki
- Manually install Tesseract to a preferred directory, in my case “C:\Program Files\Tesseract-OCR”
- After installation, check Tesseract version by changing into your directory in cmd
>>> cd C:\Program Files\Tesseract-OCR\
And
>>> tesseract -v
If you can see your tesseract version here, you are pretty much good to go.
4. Install the tesseract python wrapper pytesseract by
>>>pip install pytesseract
5. In the python application, do
>>> import pytesseract
>>> pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
6. Make use of the Tesseract python wrapper to do fun stuffs with OCR!