资源技术动态为训练深度OCR 图像,生成文本图像

为训练深度OCR 图像,生成文本图像

2019-10-19 | |  99 |   0

原标题:为训练深度OCR 图像,生成文本图像      原文来自:CSDN微博        

链接:https://blog.csdn.net/weixin_30346033/article/details/95351701


说明:

这个开源项目可以根据你提供的语料文字,来生成对应的多变文本图像,这样可以方便OCR在训练时需要大量的训练样本。

 运行 python main.py --help 可以看到在生成自己的 文本图像时需要设置的一些参数.


主要参数:

语料模型:curpus_mode  包括:chn,eng,random,list

语料目录:corpus_dir

输出目录:output_dir

图像保存:--tag  在输出目录的一个子目录下面


运行代码如下:

python main.py --corpus_mode chn --corpus_dir MY_corpus --output_dir MY_samples --tag image

一定要有 tag 参数设定 ,否则跑不出结果。


 生成新样本如下:


01.png


Text Renderer

Generate text images for training deep learning OCR model (e.g. CRNN). Support both latin and non-latin text.

Setup

  • Ubuntu 16.04

  • python 3.5+

Install dependencies:


pip3 install -r requirements.txt


Demo

By default, simply run python3 main.py will generate 20 text images and a labels.txt file in output/default/.

02.png


Use your own data to generate image

1、Please run python3 main.py --help to see all optional arguments and their meanings. And put your own data in corresponding folder.

2、Config text effects and fraction in configs/default.yaml file(or create a new config file and use it by --config_fileoption), here are some examples:

03.png

3、Run main.py file.


Strict mode


For no-latin language(e.g Chinese), it's very common that some fonts only support limited chars. In this case, you will get bad results like these:

04.png


Select fonts that support all chars in --chars_file is annoying. Run main.py with --strict option, renderer will retry get text from corpus during generate processing until all chars are supported by a font.


Tools


You can use check_font.py script to check how many chars your font not support in --chars_file:

python3 tools/check_font.py

checking font ./data/fonts/eng/Hack-Regular.ttf

chars not supported(4971):

['第', '朱', '广', '沪', '联', '自', '治', '县', '驼', '身', '进', '行', '纳', '税', '防', '火', '墙', '掏', '心', '内', '容', '万', '警','钟', '上', '了', '解'...]

0 fonts support all chars(5071) in ./data/chars/chn.txt:

[]


Generate image using GPU


If you want to use GPU to make generate image faster, first compile opencv with CUDA. Compiling OpenCV with CUDA support

Then build Cython part, and add --gpu option when run main.py


cd libs/gpu

python3 setup.py build_ext --inplace


Debug mode


Run python3 main.py --debug will save images with extract information. You can see how perspectiveTransform works and all bounding/rotated boxes.

05.png


Todo

See https://github.com/Sanster/text_renderer/projects/1

转载于:https://www.cnblogs.com/Allen-rg/p/9773258.html

THE END

免责声明:本文来自互联网新闻客户端自媒体,不代表本网的观点和立场。

合作及投稿邮箱:E-mail:editor@tusaishared.com

上一篇:文本生成图像简要回顾 text to image synthesis

下一篇:万物皆可“计算机视觉”

用户评价
全部评价

热门资源

  • 应用笔画宽度变换...

    应用背景:是盲人辅助系统,城市环境中的机器导航...

  • GAN之根据文本描述...

    一些比较好玩的任务也就应运而生,比如图像修复、...

  • 端到端语音识别时...

    从上世纪 50 年代诞生到 2012 年引入 DNN 后识别效...

  • 人体姿态估计的过...

    人体姿态估计是计算机视觉中一个很基础的问题。从...

  • 谷歌发布TyDi QA语...

    为了鼓励对多语言问答技术的研究,谷歌发布了 TyDi...