Python TesseractNotFoundError:未安装tesseract或它';它不在你的道路上
我正在尝试使用tesseract OCR打印图像中的文本。但是我得到了上面的错误。我已经在anaconda提示符下使用pip install pytesseract安装了tesseract OCR和pytesseract,但它不起作用。如果有人遇到过类似的问题,请提供帮助 (基本)C:\Users\500066016>pip安装pytesseract 收集肾盂 下载(169kB) 100% |████████████████████████████████| 174kB 288kB/s 已满足要求:c:\users\500066016\appdata\local\continuum\anaconda3\lib\site软件包中的枕头(来自pytesseract)(5.1.0) 为收集的包构建控制盘:pytesseract 正在运行PyteSeract的setup.py bdist\u控制盘。。。完成 存储在以下目录中:C:\Users\500066016\AppData\Local\pip\Cache\wheels\a8\0c\00\32e4957a46128bea34fda60b8b01a8755986415cbab3ed8e38 成功构建了pytesseract 代码如下:Python TesseractNotFoundError:未安装tesseract或它';它不在你的道路上,python,python-3.x,image-processing,python-tesseract,Python,Python 3.x,Image Processing,Python Tesseract,我正在尝试使用tesseract OCR打印图像中的文本。但是我得到了上面的错误。我已经在anaconda提示符下使用pip install pytesseract安装了tesseract OCR和pytesseract,但它不起作用。如果有人遇到过类似的问题,请提供帮助 (基本)C:\Users\500066016>pip安装pytesseract 收集肾盂 下载(169kB) 100% |████████████████████████████████| 174kB 288kB/s 已满足要
import pytesseract
import cv2
import numpy as np
def get_string(img_path):
img = cv2.imread(img_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((1,1), np.uint8)
dilate = cv2.dilate(img, kernel, iterations=1)
erosion = cv2.erode(img, kernel, iterations=1)
cv2.imwrite('removed_noise.jpg', img)
img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
cv2.imwrite('thresh.jpg', img)
res = pytesseract.image_to_string('thesh.jpg')
return res
print('Getting string from the image')
print(get_string('quotes.jpg'))
以下是错误:
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
运行文件('C:/Users/500066016/.spyder-py3/project1.py',wdir='C:/Users/500066016/.spyder-py3')
文件“C:\Users\500066016\AppData\Local\Continuum\anaconda3\lib\site packages\spyder\utils\site\sitecustomize.py”,第705行,在runfile中
execfile(文件名、命名空间)
文件“C:\Users\500066016\AppData\Local\Continuum\anaconda3\lib\site packages\spyder\utils\site\sitecustomize.py”,第102行,在execfile中
exec(编译(f.read(),文件名,'exec'),命名空间)
文件“C:/Users/500066016/.spyder-py3/project1.py”,第23行,在
打印(获取字符串('quotes.jpg'))
文件“C:/Users/500066016/.spyder-py3/project1.py”,第20行,get_字符串
res=pytesseract.image_to_字符串('thesh.jpg'))
文件“C:\Users\500066016\AppData\Local\Continuum\anaconda3\lib\site packages\pytesseract\pytesseract.py”,第294行,在图像字符串中
返回运行和获取输出(*args)
文件“C:\Users\500066016\AppData\Local\Continuum\anaconda3\lib\site packages\pytesseract\pytesseract.py”,第202行,在运行和获取输出中
运行_tesseract(**kwargs)
文件“C:\Users\500066016\AppData\Local\Continuum\anaconda3\lib\site packages\pytesseract\pytesseract.py”,第172行,在run\u tesseract中
引发TesseractNotFoundError()
TesseractNotFoundError:tesseract未安装或不在您的路径中从错误中可以明显看出,如果您在windows上,则系统无法找到tesseract软件包,只需在命令提示符下运行以下命令即可
pip install tesseract
希望它能解决您的问题:)步骤1:从此处下载并安装Tesseract OCR 步骤2:安装find the“Tesseract OCR”文件夹后,双击该文件夹并查找Tesseract.exe 步骤3:找到tesseract.exe后,复制文件位置 步骤4:像这样将此位置传递到代码中
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
注意:C:\Program Files\Tesseract OCR\Tesseract.exe==您复制的位置您应该安装:
! apt install tesseract-ocr
! apt install libtesseract-dev
及
我有谷歌硬盘上的可乐代码要运行。下面是我的示例代码:
我在网站上拍摄了任何文本的示例图片
步骤1:导入一些包
import pytesseract
import cv2
import matplotlib.pyplot as plt
from PIL import Image
步骤2:在Colab上上传text.png文件
from google.colab import files
uploaded = files.upload()
current browser session. Please rerun this cell to enable.
---------------------------------------------------------------------------
MessageError Traceback (most recent call last)
<ipython-input-31-21dc3c638f66> in <module>()
1 from google.colab import files
----> 2 uploaded = files.upload()
2 frames
/usr/local/lib/python3.6/dist-packages/google/colab/_message.py in read_reply_from_input(message_id, timeout_sec)
104 reply.get('colab_msg_id') == message_id):
105 if 'error' in reply:
--> 106 raise MessageError(reply['error'])
107 return reply.get('data', None)
108
MessageError: TypeError: Cannot read property '_uploadFiles' of undefined
打印出来
print(string)
完成。嗨,穆罕默德,实际上我在代码中添加了tesseract的路径,然后它就工作了。问题是它没有检测到tesseract的路径。谢谢你的建议哇,像魅力一样工作,我甚至不需要添加路径,谢谢。这是步骤1中的源文件夹:。您可能会在那里找到更新版本的Tesseract OCR。
string = pytesseract.image_to_string(image)
print(string)