Generate text images for training deep learning ocr model.
Install dependencies:
pip3 install -r requirements.txt
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.
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
- refactor code, make more configurable
- pre check each font supportted chars
- draw word on background image use Seamless cloning
- make char space configurable, currently it's rely on Pillow's implement
- word balance
- generate color text image