Error in opening image file in PIL

前端 未结 6 562
闹比i
闹比i 2021-01-02 21:25

I am trying to execute the following code

from pytesser import *
import Image

i=\"C:/Documents and Settings/Administrator/Desktop/attachments/R1PNDTCB.jpg\"         


        
相关标签:
6条回答
  • 2021-01-02 22:05

    Try this first:

    os.path.expanduser('~/Desktop/attachments/R1PNDTCB.jpg')

    It could be that the space in the 'Documents and Settings' is causing this problem.

    EDIT:

    Use os.path.join so it uses the correct directory separator.

    0 讨论(0)
  • 2021-01-02 22:07

    If you are using pytesseract, you have to make sure that you have installed Tesseract-OCR in your system. After that you have to insert the path of the tesseract in your code, as below

    from PIL import Image
    import pytesseract
    
    pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract 
    OCR/tesseract'
    

    You can download the Tesseract-OCR form https://github.com/UB-Mannheim/tesseract/wiki

    0 讨论(0)
  • 2021-01-02 22:09

    The exception is pretty clear: the file either doesn't exist, or you lack sufficient permissions to access it. If neither is the case, please provide evidence (e.g. relevant dir commands with output, run as the same user).

    0 讨论(0)
  • 2021-01-02 22:10

    your image path maybe?

    i="C:\\Documents and Settings\\Administrator\\Desktop\\attachments\\R1PNDTCB.jpg"
    

    try this:

    import os
    os.path.join("C:\\", "Documents and Settings", "Administrator")
    

    you should get a string similar to the one in the previous line

    0 讨论(0)
  • 2021-01-02 22:10

    Just add these two lines in your code

    import OS

    os.chdir('C:\Python27\Lib\site-packages\pytesser')  
    

    before

    from pytesser import *
    
    0 讨论(0)
  • 2021-01-02 22:28

    You need to install Tesseract first. Just installing pytesseract is not enough. Then edit the tesseract_cmd variable in pytesseract.py to point the the tessseract binary. For example, in my installation I set it to

    tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
    
    0 讨论(0)
提交回复
热议问题