我正在使用pytesseract在python中将图像读取为文本。以下是我的代码:
from PIL import Image
from pytesseract import image_to_string
import os.path
if (os.path.exists('image.png')):
filename = 'image.png'
image = Image.open(filename)
image.show()
s = image_to_string(Image.open(filename))
else:
print('Does not exist')代码获取文件image.png,将其打开并向我显示图像,这意味着该文件存在于该目录中。但是当它转到下一行s = image_to_string(Image.open(filename))时,它会给出以下错误。
Traceback (most recent call last):
File "C:/Users/hp/Desktop/GII/Genetic_Algorithm.py", line 8, in <module>
s = image_to_string(Image.open(filename))
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
config=config)
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified我努力了,但不知道该如何处理。
发布于 2016-07-25 02:48:38
也许可以试试:
f2 =os.path.abspath(文件名)
S= image_to_string(Image.open(f2))
显然,PIL正在使用一些子进程,这些子进程可能与主进程具有不同的“默认目录”
https://stackoverflow.com/questions/38555408
复制相似问题