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

来源:互联网 发布:雪肌精乳液好用吗 知乎 编辑:程序博客网 时间:2024/05/16 15:30
(一)使用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
原创粉丝点击