Reputation: 405
I trying to capture a part of the current screen to detect some number on the screen, but when the code run got this error:
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/bot/detect_num.py", line 12, in <module>
print(pytesseract.image_to_string(Image.open('test.jpg')))
File "C:\Python35\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
config=config)
File "C:\Python35\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "C:\Python35\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Python35\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
source code:
import pyscreenshot as ImageGrab
from PIL import Image
import subprocess
from pytesseract import *
if __name__=="__main__":
im = ImageGrab.grab(bbox=(1349, 34, 1357, 45))
im = im.convert('1')
im.save('test.jpg', 'JPEG')
im.show()
print(pytesseract.image_to_string(Image.open('test.jpg')))
Please some one tell me why, and how to fix it?
Upvotes: 0
Views: 3856
Reputation: 183
https://digi.bib.uni-mannheim.de/tesseract/
from this link, you can get an .exe
file, which will make you install the tesseract easier. then you can add the path of the tesseract into environment path. last you can use pytesseract
Upvotes: 0
Reputation: 307
When you are using pytesseract, first you have to make sure that you have installed Tesseract-OCR in your system. Then you have to insert the path of the tesseract in your code, as below
from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract
OCR/tesseract'
You can download the Tesseract-OCR form https://github.com/UB-Mannheim/tesseract/wiki
Upvotes: 2
Reputation: 37043
The issue here is that you haven't installed a necessary dependency. When you read pyteseeract
's documentation you see the following text:
I presume you haven't yet performed that step, so there's no tesseract
command to actually do the OCR work required.
Upvotes: 0