[英]How do I get the largest text in an image using tesseract in Python?
[英]Using Python Tesseract to get text from image, but getting an error
我正在嘗試使用Python Tesseract在macOS桌面上從圖像獲取文本,並且遇到了無法解決的錯誤。 我正在運行macOS High Sierra 10.3.2
我的目錄設置為桌面(圖像所在的位置),並且已經指定了tesseract可執行文件的路徑。
我在跑
print(pytesseract.image_to_string(Image.open('test.png'))
並得到以下錯誤:
File "/Users/name/anaconda2/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 140, in run_and_get_output
run_tesseract(**kwargs)
File "/Users/name/anaconda2/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 116, in run_tesseract
raise TesseractError(status_code, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (1, u'File "/var/folders/cp/dg2snlxn2631h8jx1bwb7jk80000gn/T/tess_cK4lka.PNG", line 1 SyntaxError: Non-ASCII character \'\\x89\' in file /var/folders/cp/dg2snlxn2631h8jx1bwb7jk80000gn/T/tess_cK4lka.PNG on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details')
知道是什么原因造成的,如何解決? 很樂意提供任何澄清的細節。
謝謝!
使用unidecode庫
from unidecode import unidecode
.
.
.
print unidecode(pytesseract.image_to_string(Image.open('test.png')))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.