python pytesseract 使用说明

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      
.......

再次运行,可以显示数据

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值