Pyocr ไม่รู้จัก get_available_languages

ฉันใช้ Python และไม่สามารถโหลดภาษาจากแพ็คเกจ pyocr ได้

from PIL import Image
import sys
import pyocr
from pyocr import builders
im=Image.open("Img1.gif")
tool=pyocr.get_available_tools()
lang = tool.get_available_languages()[0]

ที่นี่ฉันได้รับ "วัตถุรายการไม่มีแอตทริบิวต์ 'get_available_languages'

มีความคิดเห็นเกี่ยวกับวิธีการแก้ไขหรือไม่? ฉันไม่เคยใช้ pyocr

ขอบคุณ


person GabyLP    schedule 28.05.2014    source แหล่งที่มา
comment
tool ควรเป็นรายการ แต่ฉันได้ len(tool)=0   -  person GabyLP    schedule 28.05.2014


คำตอบ (2)


tools คือรายการ และคุณต้องวนซ้ำ รายการเป็นเครื่องมือส่วนบุคคล:

for tool in pyocr.get_available_tools():
    for lang in tool.get_available_languages():
        print("Tool {} supports language {}".format(tool, lang))

หรือหากคุณรู้ว่าต้องการใช้ tesseract คุณสามารถนำเข้าได้โดยตรง:

from pyocr import tesseract as tool

อย่างไรก็ตาม รายการเครื่องมือจะสะท้อนถึงโปรแกรมที่ติดตั้งบนระบบ เพื่อเปิดใช้งานเครื่องมือ tesseract ใน pyocr คุณต้องติดตั้งโปรแกรม tesseract แยกต่างหาก หากพบในพาธคำสั่ง get_available_tools() จะแสดงรายการ tesseract เครื่องมืออื่นที่ pyocr รองรับคือ cuneiform

person Antti Haapala    schedule 28.05.2014
comment
ใช่ ฉันรู้ ประเด็นก็คือฉันไม่ได้รับอะไรเลยจากรายการ ถ้าฉันเรียกใช้ len(tool) ฉันจะได้ 0 - person GabyLP; 28.05.2014

หาก len(tool) == 0 (ซึ่งคุณแนะนำในความคิดเห็นอื่น) แสดงว่า tesseract ไม่อยู่ใน PATH ของคุณ กล่าวอีกนัยหนึ่ง หากคุณไม่สามารถเรียกใช้ Tesseract จากเชลล์ของคุณได้ PyOCR ก็จะไม่พบมันเช่นกัน

person Jerome Flesch    schedule 07.10.2016
comment
ฉันสามารถเรียกใช้จากเชลล์ได้ แต่ PyOCR ก็ไม่พบมัน - person pceccon; 14.11.2017
comment
PyOCR ค้นหาคำสั่ง 'tesseract' บน PATH ของคุณโดยเฉพาะ มันมีชื่อว่า 'tesseract' หรือมีชื่ออื่นเช่น 'tesseract-ocr' หรือไม่? - person Jerome Flesch; 14.11.2017