使用Python机器识别库pytesseract遇到的问题
# _*_ coding:utf-8 _*_
#机器识别使用tesseract
#导入机器识别库
import pytesseract
#导入PIL库
from PIL import Image
image = Image.open("page/test.png")
info = pytesseract.image_to_string(image)
print info
运行...然后报错
G:\Python27\python.exe G:/Py_Project/MyPythonProject2/mypython27.py
Traceback (most recent call last):
File "G:/Py_Project/MyPythonProject2/mypython27.py", line 11, in <module>
info = pytesseract.image_to_string(image)
File "G:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)
File "G:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "G:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "G:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2]
Process finished with exit code 1
找到pytesseract库里的pytesseract.py文件
找到:tesseract_cmd = 'tesseract'
改成:tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
tesseract_cmd = r'Tesseract安装路径'
改完后:
G:\Python27\python.exe G:/Py_Project/MyPythonProject2/mypython27.py
162408
Process finished with exit code 0
可以识别