2017-03-16 73 views
0

我第一次使用Pytesseract並且遇到問題。我假設我忽略了一些基本的東西,我仍然在學習python。我在我的電腦上安裝了Tesseract-OCR,然後使用pip install來安裝pytesseract。我也嘗試點擊安裝枕頭,但couldnt,因爲它已經通過pyautogui安裝。我嘗試運行下面的代碼,但得到一個錯誤。Pytesseract回溯錯誤

問題:我需要改變什麼,或者我該如何改正?

回溯:

Traceback (most recent call last): 
    File "C:\Users\bweibley\HC\test.py", line 20, in <module> 
    text = get_text(img, region) 
    File "C:\Users\bweibley\HC\test.py", line 8, in get_text 
    return pytesseract.image_to_string(image.crop(region)) 
    File "C:\Users\bweibley\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string 
    config=config) 
    File "C:\Users\bweibley\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract 
    stderr=subprocess.PIPE) 
    File "C:\Users\bweibley\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__ 
    restore_signals, start_new_session) 
    File "C:\Users\bweibley\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child 
    startupinfo) 
FileNotFoundError: [WinError 2] The system cannot find the file specified 

代碼:

#python 3.6 
from PIL import Image 
import pytesseract 

# --- functions --- 

def get_text(image, region): 
    return pytesseract.image_to_string(image.crop(region)) 

def get_int(image, region): 
    return int(get_text(image, region).replace(',', '')) 

# --- main --- 

# test on screenshots: 0.jpg ... 9.jpg 
for x in range(10): 
    img = Image.open('screenshots/{}.jpg'.format(x)) 

    region = (288, 664, 487, 706) 
    text = get_text(img, region) 
    print('Name:', text) 

    region = (8666, 871, 1036, 920) 
    value = get_int(img, region) 
    print('Power:', value) 

    region = (1292, 466, 1420, 515) 
    value = get_int(img, region) 
    print('Loot #1:', value) 

    region = (1292, 555, 1420, 604) 
    value = get_int(img, region) 
    print('Loot #2:', value) 

    region = (1292, 645, 1420, 694) 
    value = get_int(img, region) 
    print('Loot #3:', value) 

    print('-----') 
+0

我回答這類問題[這裏](http://stackoverflow.com/a/43330889/7802055)。 –

回答

1

至於我的Python不能找到tesseract.exe

您可能需要手動將其找到並將其文件夾添加到PATH

BTW:有關於PATH內部文件pytesseract.py一些評論

+0

我已經找到了你在說什麼,甚至在哪裏改變它,但不完全明白要改變它。 Tesseract.exe位於C:\ Program Files(x86)\ Tesseract-OCR文件夾中,但它看起來並不像它想要在該變量中的文件夾目標,因爲現在它只是'tesseract' – Brandon