I have downloaded Tesseract OCR for Windows and I can easily convert images to text by this way:
C:\>"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe" screenshot22.png output -l spa
It works fine, and its execution takes just one second.
This is its version:
C:\>"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe" -v
tesseract 3.05.02
leptonica-1.75.3
libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 1.5.3) : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.2.0
Thus, I've downloaded pytesseract python library:
C:\Users\ghade\Desktop>pip3 install pytesseract --no-cache-dir
Collecting pytesseract
Downloading https://files.pythonhosted.org/packages/f9/4d/0cc26dbb2298080ed0f1ca848c06a1b68ab041e809f3583fe8642ee228cc/pytesseract-0.2.5.tar.gz (169kB)
100% |████████████████████████████████| 174kB 817kB/s
Requirement already satisfied: Pillow in c:\users\ghade\appdata\local\programs\python\python37-32\lib\site-packages (from pytesseract) (5.3.0)
Installing collected packages: pytesseract
Running setup.py install for pytesseract ... done
Successfully installed pytesseract-0.2.5
So I can execute by this way using python:
import pytesseract
from PIL import Image
# If I comment this line, it does not works
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
print(pytesseract.image_to_string(Image.open('screenshot22.png'), lang='spa'))
Same image and same parameters. But it gets stuck in the last line, and it never returns anything. What I am missing? Do you have any alternative?
I reinstalled the required packages involved and updated the TESSDATA_PREFIX environment variable and now it works fine!