Pytesseract.TesseractError 'Usage: python pytesseract.py [-l lang] input_file

前端 未结 1 1785
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 07:54

I am getting the following error when trying to print a simple test image to text.

I\'ve verified that I have Pillow (PIL 1.1.7) and tried uninstalling and reinstalling

相关标签:
1条回答
  • 2021-02-04 08:51

    The problem is pytesseract is just a nice Python wrapper for the command line program Tesseract. You're supposed to point tesseract_cmd at the actual Tesseract binary, not the pytesseract CLI util.

    So, you'll need to install Tesseract. Windows builds are available. I chose the version 3.05 installer, and it installed by default to C:\Program Files (x86)\Tesseract-OCR\tesseract. Then, I ran the following and it worked fine:

    from PIL import Image
    import pytesseract
    
    pytesseract.pytesseract.tesseract_cmd = (
        r"C:\Program Files (x86)\Tesseract-OCR\tesseract"
    )
    
    img = r"C:\Users\cody\Desktop\ocrtest.png"
    
    print(pytesseract.image_to_string(Image.open(img)))
    

    Test input:

    Result:

    The (quick) [brown] {fox} jumps!
    Over the $43,456.78 <lazy> #90 dog
    & duck/goose, as 12.5% of E-mail
    from aspammer@website.com is spam.
    Der ,,schnelle” braune Fuchs springt
    fiber den faulen Hund. Le renard brun
    «rapide» saute par-dessus le chien
    paresseux. La volpe marrone rapida
    salta sopra i] cane pigro. El zorro
    marrén répido salta sobre el perro
    perezoso. A raposa marrom répida
    salta sobre 0 C50 preguicoso.
    
    0 讨论(0)
提交回复
热议问题