https://github.com/Sanster/text_renderer

Generate text images for training deep learning ocr model

在Windows中也可以运行,只需要将Unicode编码 encoding='utf-8' 即可。

说明:

这个开源项目可以根据你提供的语料文字,来生成对应的多变文本图像,这样可以方便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 参数设定 ,否则跑不出结果。

生成新样本如下:

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/.

 

 

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:

Effect name Image
Origin(Font size 25)
Perspective Transform
Random Crop
Curve
Light border
Dark border
Random char space big
Random char space small
Middle line
Table line
Under line
Emboss
Reverse color
Blur
  1. 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:

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.

Todo

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

为训练深度OCR 图像,生成文本图像的更多相关文章

  1. 对抗生成网络-图像卷积-mnist数据生成(代码) 1.tf.layers.conv2d(卷积操作) 2.tf.layers.conv2d_transpose(反卷积操作) 3.tf.layers.batch_normalize(归一化操作) 4.tf.maximum(用于lrelu) 5.tf.train_variable(训练中所有参数) 6.np.random.uniform(生成正态数据

    1. tf.layers.conv2d(input, filter, kernel_size, stride, padding) # 进行卷积操作 参数说明:input输入数据, filter特征图的 ...

  2. 【Python图像特征的音乐序列生成】图像特征在旋律生成中有什么用

    jishude 首先援引一个资料网页:http://www.cosmosshadow.com/ml/%E5%BA%94%E7%94%A8/2016/03/01/%E9%9F%B3%E4%B9%90%E ...

  3. 基于Jittor框架实现LSGAN图像生成对抗网络

    基于Jittor框架实现LSGAN图像生成对抗网络 生成对抗网络(GAN, Generative Adversarial Networks )是一种深度学习模型,是近年来复杂分布上无监督学习最具前景的 ...

  4. (原)caffe中通过图像生成lmdb格式的数据

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5909121.html 参考网址: http://www.cnblogs.com/wangxiaocvp ...

  5. 深度学习原理与框架-图像补全(原理与代码) 1.tf.nn.moments(求平均值和标准差) 2.tf.control_dependencies(先执行内部操作) 3.tf.cond(判别执行前或后函数) 4.tf.nn.atrous_conv2d 5.tf.nn.conv2d_transpose(反卷积) 7.tf.train.get_checkpoint_state(判断sess是否存在

    1. tf.nn.moments(x, axes=[0, 1, 2])  # 对前三个维度求平均值和标准差,结果为最后一个维度,即对每个feature_map求平均值和标准差 参数说明:x为输入的fe ...

  6. 第九讲_图像生成 Image Captioning

    第九讲_图像生成 Image Captioning 生成式对抗网络 Generative Adversarial network 学习数据分布:概率密度函数估计+数据样本生成 生成式模型是共生关系,判 ...

  7. php基础之gd图像生成、缩放、logo水印和简单验证码实现

    gd库是php最常用的图片处理库之一(另外一个是imagemagick),可以生成图片.验证码.水印.缩略图等等.要使用gd库首先需要开启gd库扩展,windows系统下需要在php.ini中将ext ...

  8. YChaos生成混沌图像

    YChaos是一款通过数学公式生成混沌图像的软件,展示混沌之美,数学之美.软件中定义一套简易的脚本语言,用于描述数学表达式.使用时需要先要将数学表达式写成该脚本的形式,解析脚本代码以生成相应的图形与图 ...

  9. Why数学图像生成工具

    该软件能够以给定的数学公式及算法生成各种绚烂的数学图像.软件中有两种生成图像的方法: (1)通过一种我自定义的脚本语言生成: 软件中定义一套简单易学的脚本语言,用于描述数学表达式.使用时需要先要将数学 ...

随机推荐

  1. python 分词计算文档TF-IDF值并排序

    文章来自于我的个人博客:python 分词计算文档TF-IDF值并排序 该程序实现的功能是:首先读取一些文档,然后通过jieba来分词,将分词存入文件,然后通过sklearn计算每一个分词文档中的tf ...

  2. [置顶] ios 无限循环翻页源码例子

    原创文章,转载请注明出处:http://blog.csdn.net/donny_zhang/article/details/9923053 demo功能:ios 无限循环翻页源码例子.iphone 6 ...

  3. 如何使用Octave 在Ubuntu上科学处理音频

    Octave 是一个类似于 Linux 上的 Matlab 的软件,它拥有数量众多的函数和命令,支持声音采集.记录.回放以及音频信号的数字化处理,用于娱乐应用.研究.医学以及其它科学领域.在本教程中, ...

  4. RS开发值提示默认为当前月

    在报表的开发过程中,按月查询数据,但是由于数据仓库中涉及多年历史数据,而用户最关心的却是最近的数据,针对这个情况.当用户第一次点击报表想看到的就是当前月的数据,那么如何去做呢? 下面用一个小例子来实战 ...

  5. [React] Simplify and Convert a Traditional React Form to Formik

    Forms in React are not easy. T render() { return ( <React.Fragment> <h2>Regular Maintena ...

  6. Drupal Working with nodes, content types and fields

    一个大概的总结,便于对接下来的学习进行理解和运行 在使用Drupal过程中.站点中的内容的不论什么一个部分都是一个节点(node),而每一个节点中又包括了一些默认的字段(fields). 值得说明的是 ...

  7. Vue 生命周期LIFECYCLE是8个吗?

    vue生命周期钩子个数是:11个. export const LIFECYCLE_HOOKS = [ 'beforeCreate', 'created', 'beforeMount', 'mounte ...

  8. DOS批处理高级教程

    转载-->http://blog.csdn.net/lanbing510/article/details/7461073 前言 本教程主要引用伤脑筋版主的系列文章,同时参考引用[英雄]教程等其他 ...

  9. Linux 系统文件类型

    在Linux中只有一下7种文件类型 1.普通文件(-表示,可用ls -l查看) 2.目录(d)[在linux中,任何东西都被看成文件,外设备也看成文件,注意是任何东西] 3.字符设备文件(c) 4.块 ...

  10. 前端工程精粹(一):静态资源版本更新与缓存(附精简js的工具)

    转自:http://www.infoq.com/cn/articles/front-end-engineering-and-performance-optimization-part1/ 每个参与过开 ...