为训练深度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 --help
to see all optional arguments and their meanings. And put your own data in corresponding folder.Config text effects and fraction in
configs/default.yaml
file(or create a new config file and use it by--config_file
option), 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.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 图像,生成文本图像的更多相关文章
- 对抗生成网络-图像卷积-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)通过一种我自定义的脚本语言生成: 软件中定义一套简单易学的脚本语言,用于描述数学表达式.使用时需要先要将数学 ...
随机推荐
- 如何通过js关闭微信浏览器页面
WeixinJSBridge.call('closeWindow'); jssdk wx.closeWindow(); WeixinJSBridge对象还提供了哪些功能: WeixinJSBridge ...
- CPC广告反作弊
原文:http://blog.csdn.net/xwm1000/article/details/45460957 CPC广告上线也2年了,从上线以来就一直存在着作弊和反作弊的斗争,刚开始的时候流量少, ...
- 重新安装 RCU-数据库 2014-11-22
删除数据库Endv(原RCU数据库) 重建数据库为LLS(新RCU数据库)..略.. Database Control URL 为 https://www:1158/em 管理资料档案库已置于安全模式 ...
- C#.NET常见问题(FAQ)-如何在系统变量中加入新的环境变量
比如我要将C:\Windows\Microsoft.NET\Framework\v3.5这个目录加入环境变量 则在系统的环境变量中点击Path,编辑,然后加入一个分号";",然后粘 ...
- Office WORD如何关闭自动检查语法
只要把打钩的地方全部去掉即可.
- Spring boot 与quart集成并在Job中注入服务
1:AutowiringSpringBeanJobFactory.java package com.microwisdom.grgzpt.jobs; import org.quartz.spi.Tri ...
- Oracle的REGEXP_SUBSTR函数简单使用方法
REGEXP_SUBSTR延伸SUBSTR函数的功能.让你搜索一个正則表達式模式字符串. 这也相似于REGEXP_INSTR.而是返回子字符串的位置,它返回的子字符串本身. 语法 Oracle数据库中 ...
- Fail Fast and Fail Safe Iterators in Java
https://www.geeksforgeeks.org/fail-fast-fail-safe-iterators-java/ Fail Fast and Fail Safe Iterators ...
- HTML+CSS浏览器兼容性问题
浏览器兼容问题一:不同浏览器的标签默认的外补丁和内补丁不同 问题症状:随便写几个标签,不加样式控制的情况下,各自的margin 和padding差异较大. 碰到频率:100% 解决方案:CSS里 ...
- 中国城市线划分—Where do you want to develop......