Giter VIP home page Giter VIP logo

text_renderer's Introduction

Text Renderer

Generate text images for training deep learning ocr model.

example1.jpg example2.jpg

example3.jpg example4.jpg

Setup

The code was only tested on Ubuntu 16.04.

Install dependencies:

pip3 install -r requirements.txt

Generate image

Run python3 main.py, images and labels.txt will generate at output/default/

Some optional arguments:

  • num_img: how many images to generate
  • output_dir: where to save the images
  • corpus_dir: put txt file in corpus_dir
  • corpus_mode: different corpus type have different load/get_sample method, see corresponding function for detail
  • chars_file: chars not contained in chars_file will be filtered
  • bg_dir: 50% image background are loaded from background image dir
  • line: add underline, crop from table line, middle highlight
  • noise: add gauss noise, uniform, salt/pepper noise, poisson noise

There are a lot of configs used in renderer.py, you should change it to meet your own requirements.

Strict mode

If some chars in corpus is not supported by your font, your will get bad result:

bad_example1

bad_example2

bad_example3

Run main.py with --strict, renderer will retry get sample from corpus until all chars are supported by a font.

Tools

Check how many chars your font not support for a charset:

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:
[]

Debug mode

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

debug_demo

Generate image using GPU

If you want to use GPU to speed up image generating, first compile opencv with CUDA. Compiling OpenCV with CUDA support

Then build Cython part, and add --gpu options when run main.py

cd libs/gpu
python3 setup.py build_ext --inplace

Todo

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

text_renderer's People

Contributors

sanster avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.