为训练深度OCR 图像,生成文本图像
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
Please run
python3 main.py --helpto see all optional arguments and their meanings. And put your own data in corresponding folder.Config text effects and fraction in
configs/default.yamlfile(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 | ![]() |
- Run
main.pyfile.
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 图像,生成文本图像的更多相关文章
- 对抗生成网络-图像卷积-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特征图的 ...
- 【Python图像特征的音乐序列生成】图像特征在旋律生成中有什么用
jishude 首先援引一个资料网页:http://www.cosmosshadow.com/ml/%E5%BA%94%E7%94%A8/2016/03/01/%E9%9F%B3%E4%B9%90%E ...
- 基于Jittor框架实现LSGAN图像生成对抗网络
基于Jittor框架实现LSGAN图像生成对抗网络 生成对抗网络(GAN, Generative Adversarial Networks )是一种深度学习模型,是近年来复杂分布上无监督学习最具前景的 ...
- (原)caffe中通过图像生成lmdb格式的数据
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5909121.html 参考网址: http://www.cnblogs.com/wangxiaocvp ...
- 深度学习原理与框架-图像补全(原理与代码) 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 ...
- 第九讲_图像生成 Image Captioning
第九讲_图像生成 Image Captioning 生成式对抗网络 Generative Adversarial network 学习数据分布:概率密度函数估计+数据样本生成 生成式模型是共生关系,判 ...
- php基础之gd图像生成、缩放、logo水印和简单验证码实现
gd库是php最常用的图片处理库之一(另外一个是imagemagick),可以生成图片.验证码.水印.缩略图等等.要使用gd库首先需要开启gd库扩展,windows系统下需要在php.ini中将ext ...
- YChaos生成混沌图像
YChaos是一款通过数学公式生成混沌图像的软件,展示混沌之美,数学之美.软件中定义一套简易的脚本语言,用于描述数学表达式.使用时需要先要将数学表达式写成该脚本的形式,解析脚本代码以生成相应的图形与图 ...
- Why数学图像生成工具
该软件能够以给定的数学公式及算法生成各种绚烂的数学图像.软件中有两种生成图像的方法: (1)通过一种我自定义的脚本语言生成: 软件中定义一套简单易学的脚本语言,用于描述数学表达式.使用时需要先要将数学 ...
随机推荐
- python中的exec()、eval()以及complie()
参考博客:http://www.cnblogs.com/yyds/p/6276746.html 1.eval函数 函数的作用: 计算指定表达式的值.也就是说它要执行的python代码只能是单个表达式( ...
- 【Ansible】Playbook实例
Learn to build Ansible playbooks with our guide, one step at a time In our previous posts, we introd ...
- 自定义Lisp透明命令
我们知道在CAD中,如果我们在命令前面加一个单引号,则为透明命令.透明命令就是一个命令还没结束,中间插入另一个命令,然后继续完成前一个命令.插入的命令即透明命令,插入透明命令是为了更方便的完成第一个命 ...
- shapefile文件的符号化问题
我们都知道,ArcGIS的shp文件只以坐标形式保存地图数据,地图的显示方法则是存储都数据库或地图文件(mxd)中,这一点是深信不疑的. 如果我们打开ArcMap,新建一个普通的地图文件(使用标准的模 ...
- The connection to adb is down, and a severe error has occured. 错误
错误:The connection to adb is down, and a severe error has occured. [2010-03-11 09:36:56 - HelloOPone] ...
- SQL:1999基本语法(学习笔记)
SQL:1999基本语法 SELECT [DISTINCT] * | 列名称 [AS]别名,........ FROM 表名称1 [别名1][CROSS JOIN表名称2 别名2]| [NATURAL ...
- The Web Sessions List
The Web Sessions list contains the list of HTTP Requests that are sent by your computer. You can res ...
- 'htmlentities(): charset `utf8' not supported, assuming utf-8'
TP5.1框架报错! Fatal error: Uncaught exception 'think\exception\ErrorException' with message 'htmlentit ...
- $nextTick 宏任务 微任务 macrotasks microtasks
1.nextTick调用方法 首先看nextTick的调用方法: https://cn.vuejs.org/v2/api/#Vue-nextTick // 修改数据 vm.msg = 'Hello' ...
- CSDN开源夏令营 基于Compiz的switcher插件设计与实现之compiz特效插件介绍及特效实现
compiz自带的特效插件不够多,也不够强大.为了更好的体验compiz的特效,我们能够安装特效插件,在终端输入命令:sudo apt-get install compiz-plugins就能够下载特 ...













