man*_*ngh 0 python image-processing python-3.x python-tesseract
我正在尝试使用tesseract-OCR从图像中打印文本。但我收到上述错误。我已使用pip install pytesseract在anaconda提示符中使用https://github.com/UB-Mannheim/tesseract/wiki和pytesseract 安装了tesseract OCR,但它不起作用。如果有人遇到过类似问题,请提供帮助。
(基本)C:\ Users \ 500066016> pip install pytesseract收集pytesseract下载https://files.pythonhosted.org/packages/13/56/befaafbabb36c03e4fdbb3fea854e0aea294039308a93daf6876bf7a8d6b/pytesseractz 0.2.4(?169)。 ?????????????????????????????????? | 174kB 288kB / s已满足要求:存放在c:\ users \ 500066016 \ appdata \ local \ continuum \ anaconda3 \ lib \ site-packages中(来自pytesseract)(5.1.0)组装收集包的轮子:pytesseract正在运行setup.py pytesseract的bdist_wheel ...完成存储在目录中:C:\ Users \ 500066016 \ AppData \ Local \ pip \ Cache \ wheels \ a8 \ 0c \ 00 \ 32e4957a46128bea34fda60b8b01a8755986415cbab3ed8e38成功构建pytesseract
下面是代码:
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'))
Run Code Online (Sandbox Code Playgroud)
下面是错误:
追溯(最近一次通话):
文件“”,运行文件中的第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行,位于运行文件execfile(文件名,名称空间)中
文件“ C:\ Users \ 500066016 \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ spyder \ utils \ site \ sitecustomize.py”,行102,位于execfile exec(compile(f.read(),filename ,'exec'),名称空间)
文件“ C:/Users/500066016/.spyder-py3/project1.py”,第23行,打印(get_string('quotes.jpg'))
文件“ C:/Users/500066016/.spyder-py3/project1.py”,第20行,位于get_string res = pytesseract.image_to_string('thesh.jpg')中
image_to_string中的文件“ C:\ Users \ 500066016 \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ pytesseract \ pytesseract.py”第294行返回run_and_get_output(* args)
在run_and_get_output run_tesseract(** kwargs)中的第202行中,文件“ C:\ Users \ 500066016 \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ pytesseract \ pytesseract.py”
在run_tesseract的第172行的文件“ C:\ Users \ 500066016 \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ pytesseract \ pytesseract.py”中,引发TesseractNotFoundError()
TesseractNotFoundError:未安装tesseract或不在您的路径中
小智 6
步骤1:从此链接下载并安装Tesseract OCR 。
步骤2:安装后找到“ Tesseract-OCR ”文件夹,双击该文件夹并找到tesseract.exe。
步骤3:找到tesseract.exe之后,复制文件位置。
步骤4:像这样将这个位置传递到您的代码中
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
Run Code Online (Sandbox Code Playgroud)
注意:C:\ Program Files \ Tesseract-OCR \ tesseract.exe ==您复制的位置
| 归档时间: |
|
| 查看次数: |
7842 次 |
| 最近记录: |