tesseract-ocr tips

本文涉及的产品
小语种识别,小语种识别 200次/月
教育场景识别,教育场景识别 200次/月
通用文字识别,通用文字识别 200次/月
简介:

【基本用法】

1、tesseract 基本语法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Usage:tesseract.exe 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.
 
Single options:
-v --version: version info
--list-langs: list available languages for tesseract engine
 
tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]
tesseract    图片名  输出文件名 -l 字库文件 -psm pagesegmode 配置文件

2、示例:

(1)、

1
2
3
4
5
6
tesseract code.jpg code -l chi_sim -psm 7 digits
code 生成code.txt的结果文件
-l chi_sim 表示用简体中文字库
-psm 7 表示告诉tesseract code.jpg图片是一行文本,默认为 3
configfile 参数值为tessdata\configs 和 tessdata\tessconfigs 目录下的文件名
digits 内容为 tessedit_char_whitelist 0123456789-. 表示数字

(2)、白名单

1
tesseract code.jpg code -l eng -psm 7 -c tessedit_char_whitelist="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

(2)、黑名单

1
tesseract code.jpg code -l eng -psm 7 -c tessedit_char_blacklist="abcdefghijklmnopqrstuvwxy"


【训练】(以训练arial字体为例)

1、准备一张字体图片如下。

wKiom1fHmdCirb-FAAC5R8mRSJw347.png-wh_50

2、用 jTessBoxEditor 将图片转为tif文件,将tif文件命名为 eng.arial.exp0.tif。注意这里其实可以选多张图片。

1
Tools -> Merge TIFF...

3、生成坐标文件(.box)。

1
tesseract.exe eng.arial.exp0.tif eng.arial.exp0 batch.nochop makebox

【语法】:tesseract [lang].[fontname].exp[num].tif [lang].[fontname].exp[num] batch.nochop makebox

lang为语言名称,fontname为字体名称,num为序号;在tesseract中,一定要注意格式。

4、在当前目录创建 font_properties 文件,内容如下。

1
eng.arial.exp0.box 1 1 1 0 0

【语法】:<fontname> <italic> <bold> <fixed> <serif> <fraktur>  

fontname为字体名称,italic为斜体,bold为黑体字,fixed为默认字体,serif为衬线字体,fraktur德文黑字体,1和0代表有和无,精细区分时可使用。

5、字符校正。

打开jTessBoxEditor,BOX Editor -> Open,打开 eng.arial.exp0.tif,注意多页时页面切换。

6、执行批处理文件(arial.bat),生成.traineddata文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
echo  Run Tesseract  for  Training.. 
tesseract eng.arial.exp0.tif eng.arial.exp0 nobatch box.train 
  
echo  Compute the Character Set.. 
unicharset_extractor eng.arial.exp0.box 
mftraining -F font_properties -U unicharset -O arial.unicharset eng.arial.exp0. tr 
 
 
echo  Clustering.. 
cntraining eng.arial.exp0. tr 
 
echo  Rename Files.. 
rename normproto arial.normproto 
rename inttemp arial.inttemp 
rename pffmtable arial.pffmtable 
rename shapetable arial.shapetable  
 
echo  Create Tessdata.. 
combine_tessdata arial. 
 
echo . & pause

7、将生成文件中的arial.traineddata 文件拷贝到相应tessdata目录就可以使用啦!

1
tesseract code.jpg code -l arial


【参考文献】

1、啥都不懂也能识别验证码

2、Tesseract-OCR的简单使用与训练

3、Adding New Fonts to Tesseract 3 OCR Engine

4、Python做简单的验证码识别(ocr)


*** walker ***

本文转自walker snapshot博客51CTO博客,原文链接http://blog.51cto.com/walkerqt/1844753如需转载请自行联系原作者


RQSLT

相关文章
|
文字识别 Java C++
Tesseract-OCR的简单使用与训练
Tesseract,一款由HP实验室开发由Google维护的开源OCR(Optical Character Recognition , 光学字符识别)引擎,与Microsoft Office Document Imaging(MODI)相比,我们可以不断的训练的库,使图像转换文本的能力不断增强;如果团队深度需要,还可以以它为模板,开发出符合自身需求的OCR引擎。
5727 0
|
4月前
|
文字识别 块存储 Python
Python 图片文字识别和 tesseract 问题解决
Python 图片文字识别和 tesseract 问题解决
144 1
|
4月前
|
文字识别 Android开发 C++
Tesseract OCR集成Android Studio实现OCR识别
Tesseract OCR集成Android Studio实现OCR识别
213 0
|
5月前
|
文字识别 JavaScript 前端开发
在文字识别OCR中,有没有 ts 调试ocr 的教程啊
在文字识别OCR中,有没有 ts 调试ocr 的教程啊
68 2
|
5月前
|
机器学习/深度学习 人工智能 文字识别
通用场景OCR文本识别任务-baseline学习(PaddleOCR)
通用场景OCR文本识别任务-baseline学习(PaddleOCR)
248 0
|
机器学习/深度学习 文字识别 算法
文本识别 (OCR)引擎之Tesseract的使用
esseract是一个开源文本识别 (OCR)引擎,用于识别图片中的文字并将其转换为可编辑的文本。
1333 0
|
人工智能 文字识别 Linux
Tesseract OCR与文本智能识别
Tesseract OCR与文本智能识别
362 0
|
文字识别 并行计算 算法
【DSW Gallery】基于EasyCV的文字识别示例
EasyCV是基于Pytorch,以自监督学习和Transformer技术为核心的 all-in-one 视觉算法建模工具,并包含图像分类,度量学习,目标检测,姿态识别等视觉任务的SOTA算法。本文以文字识别为例,为您介绍如何在PAI-DSW中使用EasyCV。
【DSW Gallery】基于EasyCV的文字识别示例
Tesseract-OCR安装及使用
Tesseract-OCR安装及使用
Tesseract-OCR安装及使用
|
文字识别
autojs之浩然ocr-不安装插件就能用ocr
使用场景 不想安装浩然ocr插件
1584 0