繁体   English   中英

Python Tesseract“没有这样的文件或目录”

[英]Python Tesseract “No such file or directory”

我正在尝试使用python创建OCR程序,并且正在使用枕头使图像具有高对比度的黑白图像,但是当我尝试使用tesseract提取文本时,在终端中出现以下错误输出:

错误

Traceback (most recent call last):
  File "OCR.py", line 41, in <module>
    print(pytesseract.image_to_string(img))
  File                 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pytesseract/pytesseract.py", line 122, in image_to_string
config=config)
  File     "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-    packages/pytesseract/pytesseract.py", line 46, in run_tesseract
    proc = subprocess.Popen(command, stderr=subprocess.PIPE)
  File     "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess    .py", line 707, in __init__
    restore_signals, start_new_session)
  File     "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess    .py", line 1333, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory:     '/usr/local/bin/tesseract'

蟒蛇

from PIL import Image
import numpy as np
import pytesseract

sens = int(input("Sensitivity (0-255): "))

im = Image.open("book.jpg")
pixels = np.asarray(im)
width, height = im.size

px = pixels.mean(axis=2)
ppx = px.flatten()


for i in range(ppx.size):
    if ppx[i] > sens:
        ppx[i] = 255
    else:
        ppx[i] = 0


pixels = ppx.reshape(height, width)

img = Image.fromarray(np.uint8(pixels))
img.show()
img.save("images2.jpg")

print(pytesseract.image_to_string(img))

根据自述文件 ,必须安装tesseract才能使用pytesseract。

在Ubuntu上:

sudo apt install tesseract-ocr

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM