To see what's going on with your code I used below simple debugging implementation and tried it. Then I found out its not the filepath of *.png. Then I saw tempfile-names defined in pytesseract.py. This pytesseract
converts and saves the new temp-png file, creates a new temporariy bmp file (changed colorscheme) and when done it passes that as command to Tesseract
...
... and because Tesserac
t is not installed on my machine I get the error which reads like yours:
Traceback (most recent call last):
File "D:......\Image text converter.py", line 55, in
text = pytesseract.image_to_string(Image.open(filename))
File "c:......\lib\site-packages\pytesseract\pytesseract.py", line 132, in image_to_string
config=config)
File "c:......\lib\site-packages\pytesseract\pytesseract.py", line 50, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "c:......\lib\subprocess.py", line 390, in init
errread, errwrite)
File "c:......\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
So...
My Conclusion:
WindowsError: [Error 2] The system cannot find the file specified
is the systems way of telling you indirectly that Tesseract is not installed/compiled...etc. And has nothing to do with your input *.png filpath.
Suggestion:
Install Tesseract from here and see if the error persist. If solved report it here as answer and "accept answer" which will give us both rep.
Code for debugging purpose:
Implement after "im" in your code:
im = raw_input("Enter Image: ") # just to shows what "im" was.
print im # debuggin: show filepath to use.
if not os.path.exists(im): # checks if filepath is true.
print 'filepath "%s" is incorrect, exit..' % im
exit()
else:
print "filepath correct, continue.."
... and finally a bonus to be come debugging expert yourself...
Hacking pytesseract.py
When you add:
time.sleep(10) at:
import time # needs to be imported too...
def image_to_string(image, lang=None, boxes=False, config=None):
...snippet...
try:
image.save(input_file_name)
time.sleep(10)
status, error_string = run_tesseract(input_file_name,
output_file_name_base,
lang=lang,
boxes=boxes,
config=config)
replace: filename = "{}.png".format(os.getpid())
with filename = "Test_{}.png".format(os.getpid())
in your code ....
... You then will be rewarded and see the creation of the tempfile at:
C:\Users\...\AppData\Local\Temp
Enjoy.. and let us know if its fixed by installing the Tesseract library.