Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Generate text images for training deep learning ocr model

License

NotificationsYou must be signed in to change notification settings

Sanster/text_renderer

Repository files navigation

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 runpython3 main.py will generate 20 text imagesand a labels.txt file inoutput/default/.

example1.jpgexample2.jpg

example3.jpgexample4.jpg

Use your own data to generate image

  1. Please runpython3 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 inconfigs/default.yaml file(or create anew config file and use it by--config_file option), here are some examples:

Effect nameImage
Origin(Font size 25)origin
Perspective Transformperspective
Random Croprand_crop
Curvecurve
Light borderlight border
Dark borderdark border
Random char space bigrandom char space big
Random char space smallrandom char space small
Middle linemiddle line
Table linetable line
Under lineunder line
Embossemboss
Reverse colorreverse color
Blurblur
Text colorfont_color
Line colorline_color
  1. Runmain.py file.

Strict mode

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

bad_example1

bad_example2

bad_example3

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

Tools

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

python3 tools/check_font.pychecking font ./data/fonts/eng/Hack-Regular.ttfchars 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 runmain.py

cd libs/gpupython3 setup.py build_ext --inplace

Debug mode

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

debug_demo

Todo

Seehttps://github.com/Sanster/text_renderer/projects/1

Citing text_renderer

If you use text_renderer in your research, please consider use the following BibTeX entry.

@misc{text_renderer,author ={weiqing.chu},title ={text_renderer},howpublished ={\url{https://github.com/Sanster/text_renderer}},year ={2021}}

About

Generate text images for training deep learning ocr model

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp