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. Scala中_(下划线)的常见用法

    Scala中_(下划线)的常见用法 地址:https://www.jianshu.com/p/0497583ec538

  2. SQL-重复记录查询的几种方法

    1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * from people where peopleId in (select peopleId from ...

  3. 【理解】column must appear in the GROUP BY clause or be used in an aggregate function

    column "ms.xxx_time" must appear in the GROUP BY clause or be used in an aggregate functio ...

  4. Oracle查询client编码集

    Oracle查询client编码集 SQL> select userenv('language') from dual; USERENV('LANGUAGE') ---------------- ...

  5. Postgresql监控pgwatch的搭建

    一,需要环境: You will need a handful of components to make this work: - Apache (webserver) #apache搭建web页面 ...

  6. 大型应用的javascript架构

    来源:http://blog.leezhong.com/tech/2010/11/29/javascript-arch.html 目前很多网站基本没有明确的前端架构,大多是服务端渲染视图页,输出到浏览 ...

  7. remote: ERROR: missing Change-Id in commit message footer

    remote: ERROR: missing Change-Id in commit message footer [摘要:git 提交到近程版本库失足:remote: ERROR: missing ...

  8. Hibernate(五)基本数据类型

    一.Hibernate的基本数据类型 3种数据类型之间的对应关系 Hibernate映射类型 Java类型 标准SQL类型 integer java.lang.Integer INTEGER long ...

  9. 安装 启动sshd服务:

    .先确认是否已安装ssh服务: [root@localhost ~]# rpm -qa | grep openssh-server openssh-server-.3p1-.fc12.i686 (这行 ...

  10. Druid register mbean error

    key: [com.alibaba.druid.stat.DruidDataSourceStatManager.addDataSource(DruidDataSourceStatManager.jav ...