簡體   English   中英

從tesseract導入image_to_string時出現Python錯誤

[英]Python error when importing image_to_string from tesseract

我最近使用了tesseract OCR和python,當我嘗試從tesseract導入image_to_string時,我一直收到錯誤。

導致問題的代碼:

# Perform OCR using tesseract-ocr library
from tesseract import image_to_string
image = Image.open('input-NEAREST.tif')
print image_to_string(image)

上述代碼導致的錯誤:

Traceback (most recent call last):  
file "./captcha.py", line 52, in <module>  
from tesseract import image_to_string  
ImportError: cannot import name image_to_string

我已經確認安裝了tesseract模塊:

digital_alchemy@roaming-gnome /home $ pydoc modules | grep 'tesseract'
Hdf5StubImagePlugin _tesseract          gzip                sipconfig
ORBit               cairo               mako                tesseract

我相信我已經抓住了所有必需的套餐,但不幸的是我只是陷入了困境。 看來該功能不在模塊中。

任何幫助非常感謝。

似乎對我有用的另一種可能性是修改pytesseract,而不是從PIL導入Image導入Image

修改pytesseract后在PyCharm中有效的代碼:

from pytesseract import image_to_string
from PIL import Image

im = Image.open(r'C:\Users\<user>\Downloads\dashboard-test.jpeg')
print(im)

print(image_to_string(im))

Pytesseract我通過PyCharm內置的包管理安裝

您的語法對於已安裝的模塊是否正確? image_to_string功能看起來是每使用例如PyTesser此頁上: https://code.google.com/p/pytesser/

您的導入類似於python-tesseract,其中列出了一個更復雜的用法示例: https//code.google.com/p/python-tesseract/

對於Windows遵循以下步驟

pip3 install pytesseract 
pip3 install pillow

安裝tessaract-ocr也是必需的https://github.com/tesseract-ocr/tesseract/wiki否則你會收到一個錯誤Tessract不在路徑上

Python代碼

from PIL import Image
from pytesseract import image_to_string

print ( image_to_string(Image.open('test.tif'),lang='eng')  )

什么對我有用:

在我安裝pytesseract表單tesseract-ocr-setup-3.05.02-20180621.exe后,我添加了行pytesseract.pytesseract.tesseract_cmd="C:\\\\Program Files (x86)\\\\Tesseract-OCR\\\\tesseract.exe"並使用上面的代碼形式這是所有代碼:

import pytesseract
from PIL import Image

pytesseract.pytesseract.tesseract_cmd="C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe"
im=Image.open("C:\\Users\\<user>\\Desktop\\ro\\capt.png")
print(pytesseract.image_to_string(im,lang='eng'))

我使用的是帶有PyCharm Community Edition 2018.2.3 x64的Windows 10

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM