Tesseract-OCR引擎 入门

OCR(Optical Character Recognition):光学字符识别,是指对图片文件中的文字进行分析识别,获取的过程。

Tesseract:开源的OCR识别引擎,初期Tesseract引擎由HP实验室研发,后来贡献给了开源软件业,后经由Google进行改进,消除bug,优化,重新发布。当前版本为3.01.

项目地址为:http://code.google.com/p/tesseract-ocr


Windows 命令行使用Tesseract-OCR引擎识别验证码:

1、下载安装Tesseract-OCR引擎(3.0版本+才支持中文识别)

tesseract-ocr-setup-3.01-1.exe

下载完后进行安装,默认情况下安装程序会给你配置系统环境变量,以指向安装目录(之后可以通过DOS界面在任意目录运行tesseract)。安装完成后目录如下:

附录:

 tessdata 目录存放的是语言字库文件,和在命令行界面中可能用到的参数所对应的文件.  这个安装程序默认包含了英文字库。

如果想能识别中文,可以到http://code.google.com/p/tesseract-ocr/downloads/list下载对应的语言的字库文件. 

简体中文字库文件下载地址为:http://tesseract-ocr.googlecode.com/files/chi_sim.traineddata.gz 下载完成后解压,然后将该文件剪切到tessdata目录下去就可以了。


2、使用Tessract-OCR引擎识别验证码

打开DOS界面,输入tesseract:


如果出现如上输出,表示安装正常。

我准备了一张验证码code.jpg放在D盘根目录下 ,上图:


结果为:



附录:

Usage:tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]
pagesegmode values are:
0 = Orientation and script detection (OSD) only.
1 = Automatic page segmentation with OSD.
2 = Automatic page segmentation, but no OSD, or OCR
3 = Fully automatic page segmentation, but no OSD. (Default)
4 = Assume a single column of text of variable sizes.
5 = Assume a single uniform block of vertically aligned text.
6 = Assume a single uniform block of text.
7 = Treat the image as a single text line.
8 = Treat the image as a single word.
9 = Treat the image as a single word in a circle.
10 = Treat the image as a single character.
-l lang and/or -psm pagesegmode must occur before anyconfigfile.


tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]

tesseract    图片名  输出文件名 -l 字库文件 -psd pagesegmode 配置文件

例如:

tesseract code.jpg result  -l chi_sim -psd 7 nobatch

-l chi_sim 表示用简体中文字库(需要下载中文字库文件,解压后,存放到tessdata目录下去,字库文件扩展名为  .raineddata 简体中文字库文件名为:  chi_sim.traineddata)

-psd 7 表示告诉tesseract code.jpg图片是一行文本  这个参数可以减少识别错误率.  默认为 3

configfile 参数值为tessdata\configs 和  tessdata\tessconfigs 目录下的文件名

转载于:https://www.cnblogs.com/springside6/archive/2012/01/11/2525113.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装pytesseract库和tesseract-ocr引擎的步骤如下: 1. 首先,确保你已经安装了Python和pip。 2. 打开命令行终端,并执行以下命令来安装pytesseract库: ```shell pip install pytesseract ``` 3. 安装完成后,你还需要安装tesseract- Windows: - 访问https://github.com/UB-Mannheim/tesseract/wiki下载最新的tesseract-ocr安装程序。 - 运行安装程序,并按照提示完成安装。 - 在安装过程中,记住tesseract-OCR。 - macOS: - 打开终端,并执行以下命令来安装tesseract-ocr: ```shell brew install tesseract ``` - Linux(Ubuntu): - 打开终端,并执行以下命令来安装tesseract-ocr: ```shell sudo apt-get install tesseract-ocr ``` 4. 安装完成后,你还需要配置pytesseract库以使用正确的tesseract-ocr引擎路径。根据你的操作系统,可以按照以下步骤进行配置: - Windows: - 打开pytesseract库的安装目录,例如:C:\Users\huxiu\AppData\Local\Programs\Python\Python35\Lib\site-packages\pytesseract。 - 打开pytesseract.py文件,并找到以下行: ```python tesseract_cmd = 'tesseract' ``` - 将该行修改为你的tesseract-ocr引擎的路径,例如: ```python tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract.exe' ``` - macOS和Linux: - 不需要进行额外的配置,pytesseract库会自动找到正确的tesseract-ocr引擎路径。 5. 现在,你已经成功安装了pytesseract库和tesseract-ocr引擎。你可以在Python代码中导入pytesseract库,并使用它来进行OCR(光学字符识别)操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值