tesseract应用

tesseract应用


from PIL import Image
import pytesseract
print(pytesseract.image_to_string(Image.open('test.png')))
print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'))


核心代码就是image_to_string函数,该函数还支持-l eng 参数,支持-psm 参数。

--psm: 指定识别对象属性,如果要识别的图像中文字的分布是只有一行,就是用 “--psm 7”

Page segmentation modes:
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.
11 Sparse text. Find as much text as possible in no particular order.
12 Sparse text with OSD.
13 Raw line. Treat the image as a single text line,

bypassing hacks that are Tesseract-specific.



image_to_string(Image.open('test.png'),lang="eng" config="-psm 7")


命令行使用
tesseract chi_sm.png result -l chi_sim
格式的意思是:软件 图片名 识别结果保存为result.txt -l表示选择语言 最后是语言
chi_sim(简体中文)
eng(英文)


训练自己的库
jTessBoxEditor
这个东西是用来训练一个叫做teesseract智能图片识别软件的训练框架,

在进行训练之前还有几个小步骤:
1.将图片转换成tif格式,用于后面生成box文件。可以通过画图,然后另存为tif即可。(标签图像文件格式)
更改图片名字,这个是有要求的=。=
tif文面命名格式[lang].[fontname].exp[num].tif
lang是语言 fontname是字体
比如我们要训练自定义字库 mjorcen字体名normal
那么我们把图片文件重命名 mjorcen.normal.exp0.jpg在转tif。

2.生成box文件,CMD命令:
tesseract mjorcen.normal.exp0.jpg mjorcen.normal.exp0 -l chi_sim batch.nochop makebox
这里生成的box是存储这图片文字的识别位置参数,如果没有识别出任何文字,里面应该是空的,不信的可以用记事本方式打开。顺表可以随手添加几个数据,分别是字体坐标,和文字宽高,还有图片序号,因为这里只有一张图片,所以我最后就写0

[url]https://blog.csdn.net/ProgramOfApe/article/details/78288622[/url](jTessBoxEditor使用)

[url]http://www.cnblogs.com/cnlian/p/5765871.html[/url](jTessBoxEditor使用)

[url]https://blog.csdn.net/woaipangruimao/article/details/78741022[/url](用jTessBoxEditor自动训练3500常用汉字)

[url]https://blog.csdn.net/Metamorpho/article/details/80835574[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jie310600

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值