Skip to content

leftstone2015/TextRecognitionDataGenerator

 
 

Repository files navigation

TextRecognitionDataGenerator TravisCI codecov

A synthetic data generator for text recognition

What is it for?

Generating text image samples to train an OCR software

What do I need to make it work?

I use Archlinux so I cannot tell if it works on Windows yet.

Python 3.X
OpenCV 3.2 (It probably works with 2.4)
Pillow
Numpy
Requests
BeautifulSoup

You can simply use pip install -r requirements.txt too.

How does it work?

python run.py -w 5 -f 64

You get 1000 randomly generated images with random text on them like:

1 2 3 4 5

What if you want random skewing? Add -k and -rk (python run.py -w 5 -f 64 -k 5 -rk)

6 7 8 9 10

But scanned document usually aren't that clear are they? Add -bl and -rbl to get gaussian blur on the generated image with user-defined radius (here 0, 1, 2, 4):

11 12 13 14

Maybe you want another background? Add -b to define one of the three available backgrounds: gaussian noise (0), plain white (1), quasicrystal (2) or picture (3).

15 16 17 23

When using picture background (3). A picture from the pictures/ folder will be randomly selected and the text will be written on it.

Or maybe you are working on an OCR for handwritten text? Add -hw! (Experimental)

18 19 20 21 22

It uses a Tensorflow model trained using this excellent project by Grzego.

The project does not require TensorFlow to run if you aren't using this feature

You can also add distorsion to the generated text with -d and -do

23 24 25

The text is chosen at random in a dictionary file (that can be found in the dicts folder) and drawn on a white background made with Gaussian noise. The resulting image is saved as [text]_[index].jpg

New

  • You can add distorsion to the generated text
  • You can "fake" handwriting using -hw
  • You can add gaussian blur to the resulting image
  • Sentences from Wikipedia can be used instead of random words with python run.py -wk 1 (requires an Internet connection)
  • Sentences can be picked from a file passed as a parameter with python run.py -i ./texts/random_1.txt

There are a lot of parameters that you can tune to get the results you want, therefore I recommand checking out python run.py -h for more informations.

Can I add my own font?

Yes, the script picks a font at random from the fonts directory. Simply add / remove fonts until you get the desired output.

It only supports .ttf for now.

Contributing

  1. Create an issue describing the feature you'll be working on
  2. Code said feature
  3. Create a pull request

Feature request & issues

If anything is missing, unclear, or simply not working, open an issue on the repository.

What is left to do?

  • Better background generation
  • Better handwritten text generation
  • More customization parameters (mostly regarding background)
  • Implement --include_symbols
  • Implement --include_numbers

About

A synthetic data generator for text recognition

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%