python:文字识别 (转自 新浪博客 恬月园)

(一)使用pytesser
1、下载安装pil
下载 : http://www.pythonware.com/products/pil/
执行安装文件
2、下载安装pytesser
下载:http://code.google.com/p/pytesser/
解压,“...\pytesser”, 设置环境变量PYTHONPATH,添加“...\pytesser”
3、程序执行
import os 
import pytesser
os.chdir("E:/software/python/pytesser")
pytesser.image_file_to_string('c:/check.bmp')

参考:http://code.google.com/p/pytesser/
说明: 该项目似乎只是"tesseract-ocr"一个ptyhon封装的外壳,并且此项目似乎还一直停留在0.01版没有更新,而且该外壳似乎还存在比较严重的bug,更深入的解决方案应该是参考"tesseract-ocr" 参考 http://code.google.com/p/tesseract-ocr/。

4、改进程序只能在当前目录下调用的问题
在目录下新增一个文件  mypytesser.py 文件
import os
import pytesser
def image_file_to_string(file):
      cwd = os.getcwd()
      try :
            os.chdir("E:\software\python\pytesser")
            return pytesser.image_file_to_string(file)
      finally:
            os.chdir(cwd)

在命令航使用一下命令进行图片解析
import mypytesser
print mypytesser.image_file_to_string("c:/check.bmp");


(二)自己编写代码来实现
http://blog.feshine.net/technology/1163.html


(三)tesseract-ocr基础
1、基本操作
cmd>tesseract c:\check1.bmp c:\check1
在tesseract.log可以看见程序反馈,但可以了解的信息不多,需要深入了解tesseract项目。
2、极容易出现的问题是,图像文件打开会报错,需要将图像文件的dpi改为200*200,可以用python代码解决:
python>>>import Image
python>>>image = Image.open(r”c:\check.bmp”)
python>>>image.save(r”c:\check1.bmp”, dpi=(200,200))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值