2017-07-25 69 views
1
import pytesser3 
import Image 
a = Image.open("C:\\Users\\dell\\Desktop\\test.png") 
b = pytesser3.image_to_string(a) 
print(b) 

我试图制作一个简单的OCR程序,但每当我运行它时,我都会收到以下错误消息。我甚至卸载pytesser3并重新安装它,但没有任何改变。我究竟做错了什么?在Pytesser3中未发现错误

Traceback (most recent call last): 
    File "C:/Users/dell/Desktop/crossword.py", line 4, in <module> 
    b = pytesser3.image_to_string(a) 
    File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\site- packages\pytesser3\__init__.py", line 30, in image_to_string 
call_tesseract(scratch_image_name, scratch_text_name_root) 
    File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\site- packages\pytesser3\__init__.py", line 20, in call_tesseract 
proc = subprocess.Popen(args) 
    File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__ 
restore_signals, start_new_session) 
    File "C:\Users\dell\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: 

这里是test.png: https://i.stack.imgur.com/NBjbc.png


import pytesser3 
import Image 
import pytesseract 
pytesseract.pytesseract.tesseract_cmd = 'C:\\Users\\dell\\AppData\\Local\\Programs\\Python\\Python36-32\\Lib\\site-packages\\pytesseract' 
a = Image.open("C:\\Users\\dell\\Desktop\\test.png") 
b = pytesseract.image_to_string(a) 
print(b) 

我没有你所说的话,但现在我已经有了一个不同的错误:

Traceback (most recent call last): 
    File "C:/Users/dell/Desktop/crossword.py", line 6, in <module> 
b = pytesseract.image_to_string(a) 
    File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string 
config=config) 
    File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract 
proc = subprocess.Popen(command, stderr=subprocess.PIPE) 
    File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__ 
restore_signals, start_new_session) 
    File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child 
startupinfo) 
PermissionError: [WinError 5] Access denied. 

回答

0

你会必须申报pytesseract路径:

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