【发布时间】:2018-12-12 14:21:02
【问题描述】:
我正在定义一个函数,它将图像转换为灰度(有点黑白色),然后我将它传递给:
text = pytesseract.image_to_string(Image.open(gray_scale_image))
然后我打印我收到的文本,但它抛出错误:
Traceback (most recent call last):
File "C:\Users\HP\PycharmProjects\nayaproject\venv\lib\site-packages\PIL\Image.py", line 2613, in open
fp.seek(0)
AttributeError: 'numpy.ndarray' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/HP/PycharmProjects/nayaproject/new.py", line 17, in <module>
text = pytesseract.image_to_string(Image.open(g))
File "C:\Users\HP\PycharmProjects\nayaproject\venv\lib\site-packages\PIL\Image.py", line 2615, in open
fp = io.BytesIO(fp.read())
AttributeError: 'numpy.ndarray' object has no attribute 'read'
当我使用 Image.fromarray(grayscale) 而不是 Image.open(grayscale) 时,我得到了这些错误:
Traceback (most recent call last):
File "C:\Users\HP\PycharmProjects\nayaproject\venv\lib\site-packages\pytesseract\pytesseract.py", line 170, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/HP/PycharmProjects/nayaproject/new.py", line 17, in <module>
text = pytesseract.image_to_string(Image.fromarray(g))
File "C:\Users\HP\PycharmProjects\nayaproject\venv\lib\site-packages\pytesseract\pytesseract.py", line 294, in image_to_string
return run_and_get_output(*args)
File "C:\Users\HP\PycharmProjects\nayaproject\venv\lib\site-packages\pytesseract\pytesseract.py", line 202, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\HP\PycharmProjects\nayaproject\venv\lib\site-packages\pytesseract\pytesseract.py", line 172, in run_tesseract
raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path
我正在研究 PyCharm,我已经为这个项目安装了 Pillow、numpy、opencv-python、pip 和 pytesseract。
【问题讨论】:
-
你是如何安装 tesseract 的?
-
Image.open(gray_scale_image) => 你在这里传递什么作为 gray_scale_image ?这应该是图像的完整路径,即字符串而不是图像对象(不是数组)
标签: python python-3.x numpy tesseract