簡體   English   中英

使用tesseract和pytesseract的圖像到文本Python 3.6錯誤

[英]Image to text Python 3.6 error using tesseract and pytesseract

我正在嘗試使用pytesseract的image_to_string函數,但無法做到這一點。 我已經安裝了pytesseract模塊和tesseract模塊,但是最后一個似乎無法正常工作,我有以下代碼

import argparse
import cv2
import os
import time
import sys
from PIL import Image
import pytesseract
A=Image.open("C:/Users/Martin/Python/Python36/Tickets/2.jpg")
pytesseract.image_to_string(A)

運行此命令時,出現以下錯誤消息

Traceback (most recent call last):
  File "C:/Users/Martin/Python/Python36/cosa.py", line 9, in <module>
    pytesseract.image_to_string(A)
  File "C:\Users\Martin\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 193, in image_to_string
    return run_and_get_output(image, 'txt', lang, config, nice)
  File "C:\Users\Martin\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 140, in run_and_get_output
    run_tesseract(**kwargs)
  File "C:\Users\Martin\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 111, in run_tesseract
    proc = subprocess.Popen(command, stderr=subprocess.PIPE)
  File "C:\Users\Martin\Python\Python36\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Martin\Python\Python36\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] El sistema no puede encontrar el archivo especificado

所以我嘗試運行import tesseract,這顯示了

Traceback (most recent call last):
  File "<pyshell#53>", line 1, in <module>
    import tesseract
  File "C:\Users\Martin\Python\Python36\lib\site-packages\tesseract\__init__.py", line 34
    print 'Creating user config file: {}'.format(_config_file_usr)
                                    ^
SyntaxError: invalid syntax

我猜這是一個兼容性問題(我正在使用Python 3.6.5,現在print是一個函數,所以()可以預期),但是當我運行pip install --upgrade tesseract時,我已經知道它已經是最新的了,所以我不知道知道如何使這項工作。 我正在使用Windows 7 64位。 任何幫助,不勝感激。

您的系統中沒有安裝Tesseract。

pip一起安裝的tesseract軟件包是另一個與Tesseract OCR引擎無關的Python軟件包

您有以下安裝正方體這個指令。 然后你可以使用pytesseract

並非完全確定這是否可以解決您的問題,因為它是Windows,錯誤不是英語,但對於其他Google員工,如果您遇到

pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path

ocr需要與pip的python軟件包分開安裝:

sudo apt install tesseract-ocr

將其安裝到您的路徑中。

ocr需要與pip的python軟件包分開安裝:

sudo apt install tesseract-ocr

暫無
暫無

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

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