Package: trdg
TextRecognitionDataGeneratorA synthetic data generator for text recognitionWhat is it for?Generating text image samples to train an OCR software. Now supporting non-latin text! For a more thorough tutorial seethe official documentation.What do I need to make it work?Install the pypi packagepip install trdgAfterwards, you can usetrdgfrom the CLI. I recommend using a virtualenv instead of installing withsudo.If you want to add another language, you can clone the repository instead. Simply runpip install -r requirements.txtDocker imageIf you would rather not have to install anything to use TextRecognitionDataGenerator, you can pull the docker image.docker pull belval/trdg:latest

docker run -v /output/path/:/app/out/ -t belval/trdg:latest trdg [args]The path (/output/path/) must be absolute.NewAdd--stroke_widthargument to set the width of the text stroke (Thank you@SunHaozhe)Add--stroke_fillargument to set the color of the text contour if stroke > 0 (Thank you@SunHaozhe)Add--word_splitargument to split on word instead of per-character. This is useful for ligature-based languagesAdd--dictargument to specify a custom dictionary (Thank you@luh0907)Add--font_dirargument to specify the fonts to useAdd--output_maskto output character-level mask for each imageAdd--character_spacingto control space between characters (in pixels)Add python moduleAdd--fontto use only one font for all the generated images (Thank you@JulienCoutault!)Add--fitand--marginsfor finer layout controlChange the text orientation using the-orparameterSpecify text color range using-tc '#000000,#FFFFFF', please note that the quotes arenecessaryAdd support for Simplified and Traditional ChineseHow does it work?Words will be randomly chosen from a dictionary of a specific language. Then an image of those words will be generated by using font, background, and modifications (skewing, blurring, etc.) as specified.Basic (Python module)The usage as a Python module is very similar to the CLI, but it is more flexible if you want to include it directly in your training pipeline, and will consume less space and memory. There are 4 generators that can be used.fromtrdg.generatorsimport(GeneratorFromDict,GeneratorFromRandom,GeneratorFromStrings,GeneratorFromWikipedia,)# The generators use the same arguments as the CLI, only as parametersgenerator=GeneratorFromStrings(['Test1','Test2','Test3'],blur=2,random_blur=True)forimg,lblingenerator:# Do something with the pillow images here.You can see the full class definition here:GeneratorFromDictGeneratorFromRandomGeneratorFromStringsGeneratorFromWikipediaBasic (CLI)trdg -c 1000 -w 5 -f 64You get 1,000 randomly generated images with random text on them like:By default, they will be generated toout/in the current working directory.Text skewingWhat if you want random skewing? Add-kand-rk(trdg -c 1000 -w 5 -f 64 -k 5 -rk)Text distortionYou can also add distorsion to the generated text with-dand-doText blurringBut scanned document usually aren't that clear are they? Add-bland-rblto get gaussian blur on the generated image with user-defined radius (here 0, 1, 2, 4):BackgroundMaybe you want another background? Add-bto define one of the three available backgrounds: gaussian noise (0), plain white (1), quasicrystal (2) or image (3).When using image background (3). A image from the images/ folder will be randomly selected and the text will be written on it.HandwrittenOr maybe you are working on an OCR for handwritten text? Add-hw! (Experimental)It uses a Tensorflow model trained usingthis excellent projectby Grzego.The project does not require TensorFlow to run if you aren't using this featureDictionaryThe text is chosen at random in a dictionary file (that can be found in thedictsfolder) and drawn on a white background made with Gaussian noise. The resulting image is saved as [text]_[index].jpgThere are a lot of parameters that you can tune to get the results you want, therefore I recommend checking outtrdg -hfor more information.Create images with Chinese textIt is simple! Just dotrdg -l cn -c 1000 -w 5!Generated texts come both in simplified and traditional Chinese scripts.Traditional:Simplified:Create images with Japanese textIt is simple! Just dotrdg -l ja -c 1000 -w 5!OutputAdd new fontsThe script picks a font at random from thefontsdirectory.DirectoryLanguagesfonts/latinEnglish, French, Spanish, Germanfonts/cnChinesefonts/koKoreanfonts/jaJapanesefonts/thThaiSimply add/remove fonts until you get the desired output.If you want to add a new non-latin language, the amount of work is minimal.Create a new folder with your languagetwo-letters codeAdd a .ttf font in itEditrun.pyto add an if statement inload_fonts()Add a text file indictswith the same two-letters codeRun the tool as you normally would but add-lwith your two-letters codeIt only supports .ttf for now.BenchmarksNumber of images generated per second.Intel Core i7-4710HQ @ 2.50Ghz + SSD (-c 1000 -w 1)-t 1: 363 img/s-t 2: 694 img/s-t 4: 1300 img/s-t 8: 1500 img/sAMD Ryzen 7 1700 @ 4.0Ghz + SSD (-c 1000 -w 1)-t 1: 558 img/s-t 2: 1045 img/s-t 4: 2107 img/s-t 8: 3297 img/sContributingCreate an issue describing the feature you'll be working onCode said featureCreate a pull requestFeature request & issuesIf anything is missing, unclear, or simply not working, open an issue on the repository.What is left to do?Better background generationBetter handwritten text generationMore customization parameters (mostly regarding background)