问题描述
我正在尝试使用tesseract-OCR从图像中打印文本.但是我收到了上面的错误.我已经使用 https://github.com/UB-Mannheim/tesseract/wiki 并在anaconda提示符中使用pytesseract进行pip install pytesseract,但无法正常工作.如果有人遇到过类似的问题,请提供帮助.
I am trying to use tesseract-OCR to print text from the image. But I am getting the above error. I have installed tesseract OCR using https://github.com/UB-Mannheim/tesseract/wiki and pytesseract in the anaconda prompt using pip install pytesseract but its not working. Please help if anyone has faced the similar issue.
(基本)C:\ Users \ 500066016> pip install pytesseract收集pytesseract 正在下载 https://orgs.pythonhosted. /packages/13/56/befaafbabb36c03e4fdbb3fea854e0aea294039308a93daf6876bf7a8d6b/pytesseract-0.2.4.tar.gz (169kB) 100%|████████████████████████████████|| 174kB 288kB/秒已满足要求:存放在c:\ users \ 500066016 \ appdata \ local \ continuum \ anaconda3 \ lib \ site-packages中(来自pytesseract)(5.1.0)用于收集包裹的建筑轮子:pytesseract 为pytesseract运行setup.py bdist_wheel ...完成 存储在以下目录中:C:\ Users \ 500066016 \ AppData \ Local \ pip \ Cache \ wheels \ a8 \ 0c \ 00 \ 32e4957a46128bea34fda60b8b01a8755986415cbab3ed8e38成功构建pytesseract
(base) C:\Users\500066016>pip install pytesseractCollecting pytesseract Downloading https://files.pythonhosted.org/packages/13/56/befaafbabb36c03e4fdbb3fea854e0aea294039308a93daf6876bf7a8d6b/pytesseract-0.2.4.tar.gz (169kB) 100% |████████████████████████████████| 174kB 288kB/sRequirement already satisfied: Pillow in c:\users\500066016\appdata\local\continuum\anaconda3\lib\site-packages (from pytesseract) (5.1.0)Building wheels for collected packages: pytesseract Running setup.py bdist_wheel for pytesseract ... done Stored in directory: C:\Users\500066016\AppData\Local\pip\Cache\wheels\a8\0c\00\32e4957a46128bea34fda60b8b01a8755986415cbab3ed8e38Successfully built 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'))
以下是错误:
回溯(最近通话最近一次):
Traceback (most recent call last):
文件",第1行,在 runfile('C:/Users/500066016/.spyder-py3/project1.py',wdir ='C:/Users/500066016/.spyder-py3')
File "", line 1, in runfile('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(文件名,命名空间)
File "C:\Users\500066016\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile execfile(filename, namespace)
exec文件中第102行的文件"C:\ Users \ 500066016 \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ spyder \ utils \ site \ sitecustomize.py" exec(compile(f.read(),文件名,'exec'),命名空间)
File "C:\Users\500066016\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
文件"C:/Users/500066016/.spyder-py3/project1.py",第23行,在 打印(get_string('quotes.jpg'))
File "C:/Users/500066016/.spyder-py3/project1.py", line 23, in print(get_string('quotes.jpg'))
文件"C:/Users/500066016/.spyder-py3/project1.py",第20行,位于get_string中 res = pytesseract.image_to_string('thesh.jpg')
File "C:/Users/500066016/.spyder-py3/project1.py", line 20, in get_string res = pytesseract.image_to_string('thesh.jpg')
image_to_string中的第294行,文件"C:\ Users \ 500066016 \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ pytesseract \ pytesseract.py" 返回run_and_get_output(* args)
File "C:\Users\500066016\AppData\Local\Continuum\anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 294, in image_to_string return run_and_get_output(*args)
在run_and_get_output中的第202行,文件"C:\ Users \ 500066016 \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ pytesseract \ pytesseract.py" run_tesseract(** kwargs)
File "C:\Users\500066016\AppData\Local\Continuum\anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 202, in run_and_get_output run_tesseract(**kwargs)
run_tesseract中的文件"C:\ Users \ 500066016 \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ pytesseract \ pytesseract.py",第172行 引发TesseractNotFoundError()
File "C:\Users\500066016\AppData\Local\Continuum\anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 172, in run_tesseract raise TesseractNotFoundError()
TesseractNotFoundError:未安装tesseract或它不在您的路径中
TesseractNotFoundError: tesseract is not installed or it's not in your path
推荐答案
步骤1:从链接.
第2步:安装后,找到" Tesseract-OCR "文件夹,双击该文件夹并找到 tesseract.exe .
Step 2: After installing find the "Tesseract-OCR" folder, double Click on this folder and find the tesseract.exe.
第3步:找到 tesseract.exe 后,复制文件位置.
Step 3: After finding the tesseract.exe, copy the file location.
第4步:像这样将这个位置传递到您的代码中
Step 4: Pass this location into your code like this
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
注意:C:\ Program Files \ Tesseract-OCR \ tesseract.exe ==您复制的位置
Note: C:\Program Files\Tesseract-OCR\tesseract.exe == your copied location
这篇关于TesseractNotFoundError:未安装tesseract或不在您的路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!