python pytesseract 使用说明

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/kezhen/article/details/42967789

1、安装

pip install pytesseract

2、使用

#!/usr/bin/python
import Image
import pytesseract
imageObject=Image.open('test.jpg')
print (imageObject)
print (pytesseract.image_to_string(imageObject))
#print (pytesseract.image_to_string(Image.open('/root/Desktop/pythoncode/test.png')))
#print (open('test.png').read())

运行,出错:

root@TestBackTrack:~/Desktop/pythoncode# python testOcr.py
<PngImagePlugin.PngImageFile image mode=P size=70x15 at 0xB73A47EC>
Traceback (most recent call last):
  File "testOcr.py", line 6, in <module>
    print (pytesseract.image_to_string(imageObject))
  File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 142, in image_to_string
    config=config)
  File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 75, in run_tesseract
    stderr=subprocess.PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

首先想到的是:是不是test.jpg找不到?

测试了读文件函数,没有问题

而后网搜了下,发现没有安装tesseract-ocr包

参考:http://stackoverflow.com/questions/18322933/pytesser-simple-usage-error

root@TestBackTrack:~/Desktop/pythoncode# sudo apt-get install tesseract-ocr
Reading package lists... Done
Building dependency tree      
.......

再次运行,可以显示数据

展开阅读全文

没有更多推荐了,返回首页