【发布时间】:2021-02-19 10:57:16
【问题描述】:
我从一些使用 OpenCV 的基本 Python 教程开始,第一个教程使用 Tesseract、Pytesseract 和 OpenCV。我已经下载了 Tesseract 并安装了 pip,我已经下载、安装了 Pytesseract 和 OpenCV,并将其包含在我的 PyCharm 包中,所以我认为问题在于我如何在我的代码中处理 Tesseract 文件,因为我是新手一台Mac。 (我使用的是 Python 3.8,但也安装了 Python 2.7,因为我需要它来达到这一点。奇怪的是,到目前为止,如果我安装了 Python 2.7,代码只有在没有错误的情况下运行,但安装了 3.8我的 PyCharm 解释器。)
当我将 Tesseract 放入终端时,它告诉我文件地址只是“Applications/tesseract”。但是当我在 PyCharm 中使用它作为地址时,我收到下面的错误消息。如果有人能帮我弄清楚如何处理这个错误,我将不胜感激!!! (顺便说一句,我对所有计算机都不熟悉。这就是我的学习方式。)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/george/PycharmProjects/pythonProject2/main.py", line 7, in <module>
print(pytesseract.image_to_string(img))
File "/Users/george/Library/Python/3.8/lib/python/site-packages/pytesseract/pytesseract.py", line 370, in image_to_string
return {
File "/Users/george/Library/Python/3.8/lib/python/site-packages/pytesseract/pytesseract.py", line 373, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "/Users/george/Library/Python/3.8/lib/python/site-packages/pytesseract/pytesseract.py", line 282, in run_and_get_output
run_tesseract(**kwargs)
File "/Users/george/Library/Python/3.8/lib/python/site-packages/pytesseract/pytesseract.py", line 254, in run_tesseract
raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: \Applications\tesseract is not installed or it's not in your PATH. See README file for more information."
不过,我不知道要在 README 文件中查找什么。
这是启动错误消息的代码:
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = '\\Applications\\tesseract'
img = cv2.imread('im1.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
print(pytesseract.image_to_string(img))
cv2.imshow('Result', img)
cv2.waitKey(0)
【问题讨论】:
标签: python python-3.x python-2.7 pycharm tesseract