{ "info": { "author": "Edouard Belval", "author_email": "edouard@belval.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# TextRecognitionDataGenerator [![TravisCI](https://travis-ci.org/Belval/TextRecognitionDataGenerator.svg?branch=master)](https://travis-ci.org/Belval/TextRecognitionDataGenerator) [![PyPI version](https://badge.fury.io/py/trdg.svg)](https://badge.fury.io/py/trdg) [![codecov](https://codecov.io/gh/Belval/TextRecognitionDataGenerator/branch/master/graph/badge.svg)](https://codecov.io/gh/Belval/TextRecognitionDataGenerator) [![Documentation Status](https://readthedocs.org/projects/textrecognitiondatagenerator/badge/?version=latest)](https://textrecognitiondatagenerator.readthedocs.io/en/latest/?badge=latest)\n\nA synthetic data generator for text recognition\n\n## What is it for?\n\nGenerating text image samples to train an OCR software. Now supporting non-latin text! For a more thorough tutorial see [the official documentation](https://textrecognitiondatagenerator.readthedocs.io/en/latest/index.html).\n\n## What do I need to make it work?\n\nInstall the pypi package\n\n```\npip install trdg\n```\n\nAfterwards, you can use `trdg` from the CLI. I recommend using a virtualenv instead of installing with `sudo`.\n\nIf you want to add another language, you can clone the repository instead. Simply run `pip install -r requirements.txt`\n\n## Docker image\n\nIf you would rather not have to install anything to use TextRecognitionDataGenerator, you can pull the docker image.\n\n```\ndocker pull belval/trdg:latest\n\ndocker run -v /output/path/:/app/out/ -t belval/trdg:latest trdg [args]\n```\n\nThe path (`/output/path/`) must be absolute.\n\n## New\n- Add python module\n- Move `run.py` to an executable python file ([`trdg/bin/trdg`](trdg/bin/trdg))\n- Add `--font` to use only one font for all the generated images (Thank you @JulienCoutault!)\n- Add `--fit` and `--margins` for finer layout control\n- Change the text orientation using the `-or` parameter\n- Specify text color range using `-tc '#000000,#FFFFFF'`, please note that the quotes are **necessary**\n- Add support for Simplified and Traditional Chinese\n\n## How does it work?\n\nWords 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.\n\n### Basic (Python module)\n\nThe 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.\n\n```py\nfrom TextRecognitionDataGenerator.generators import (\n GeneratorFromDict,\n GeneratorFromRandom,\n GeneratorFromStrings,\n GeneratorFromWikipedia,\n)\n\n# The generators use the same arguments as the CLI, only as parameters\ngenerator = GeneratorFromStrings(\n ['Test1', 'Test2', 'Test3'],\n blur=2,\n random_blur=True\n)\n\nfor img, lbl in generator:\n # Do something with the pillow images here.\n```\n\nYou can see the full class definition here:\n\n- [`GeneratorFromDict`](trdg/generators/from_dict.py)\n- [`GeneratorFromRandom`](trdg/generators/from_random.py)\n- [`GeneratorFromStrings`](trdg/generators/from_strings.py)\n- [`GeneratorFromWikipedia`](trdg/generators/from_wikipedia.py)\n\n### Basic (CLI)\n\n`trdg -c 1000 -w 5 -f 64`\n\nYou get 1,000 randomly generated images with random text on them like:\n\n![1](samples/1.jpg \"1\")\n![2](samples/2.jpg \"2\")\n![3](samples/3.jpg \"3\")\n![4](samples/4.jpg \"4\")\n![5](samples/5.jpg \"5\")\n\nBy default, they will be generated to `out/` in the current working directory.\n\n### Text skewing\n\nWhat if you want random skewing? Add `-k` and `-rk` (`trdg -c 1000 -w 5 -f 64 -k 5 -rk`)\n\n![6](samples/6.jpg \"6\")\n![7](samples/7.jpg \"7\")\n![8](samples/8.jpg \"8\")\n![9](samples/9.jpg \"9\")\n![10](samples/10.jpg \"10\")\n\n### Text distortion\nYou can also add distorsion to the generated text with `-d` and `-do`\n\n![23](samples/24.jpg \"0\")\n![24](samples/25.jpg \"1\")\n![25](samples/26.jpg \"2\")\n\n### Text blurring\n\nBut 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):\n\n![11](samples/11.jpg \"0\")\n![12](samples/12.jpg \"1\")\n![13](samples/13.jpg \"2\")\n![14](samples/14.jpg \"4\")\n\n### Background\n\nMaybe 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).\n\n![15](samples/15.jpg \"0\")\n![16](samples/16.jpg \"1\")\n![17](samples/17.jpg \"2\")\n![23](samples/23.jpg \"3\")\n\nWhen using picture background (3). A picture from the pictures/ folder will be randomly selected and the text will be written on it.\n\n### Handwritten\n\nOr maybe you are working on an OCR for handwritten text? Add `-hw`! (Experimental)\n\n![18](samples/18.jpg \"0\")\n![19](samples/19.jpg \"1\")\n![20](samples/20.jpg \"2\")\n![21](samples/21.jpg \"3\")\n![22](samples/22.jpg \"4\")\n\nIt uses a Tensorflow model trained using [this excellent project](https://github.com/Grzego/handwriting-generation) by Grzego.\n\n**The project does not require TensorFlow to run if you aren't using this feature**\n\n### Dictionary\n\nThe 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\n\nThere are a lot of parameters that you can tune to get the results you want, therefore I recommend checking out `trdg -h` for more information.\n\n## Create images with Chinese text\n\nIt is simple! Just do `trdg -l cn -c 1000 -w 5`!\n\nGenerated texts come both in simplified and traditional Chinese scripts.\n\nTraditional:\n\n![27](samples/27.jpg \"0\")\n\nSimplified:\n\n![28](samples/28.jpg \"1\")\n\n## Add new fonts\n\nThe script picks a font at random from the *fonts* directory.\n\n| Directory | Languages |\n|:----|:-----|\n| fonts/latin | English, French, Spanish, German |\n| fonts/cn | Chinese |\n\nSimply add/remove fonts until you get the desired output.\n\nIf you want to add a new non-latin language, the amount of work is minimal.\n\n1. Create a new folder with your language [two-letters code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)\n2. Add a .ttf font in it\n3. Edit `bin/trdg` to add an if statement in `load_fonts()`\n4. Add a text file in `dicts` with the same two-letters code\n5. Run the tool as you normally would but add `-l` with your two-letters code\n\nIt only supports .ttf for now.\n\n## Benchmarks\n\nNumber of images generated per second.\n\n- Intel Core i7-4710HQ @ 2.50Ghz + SSD (-c 1000 -w 1)\n - `-t 1` : 363 img/s\n - `-t 2` : 694 img/s\n - `-t 4` : 1300 img/s\n - `-t 8` : 1500 img/s\n- AMD Ryzen 7 1700 @ 4.0Ghz + SSD (-c 1000 -w 1)\n - `-t 1` : 558 img/s\n - `-t 2` : 1045 img/s\n - `-t 4` : 2107 img/s\n - `-t 8` : 3297 img/s\n\n## Contributing\n\n1. Create an issue describing the feature you'll be working on\n2. Code said feature\n3. Create a pull request\n\n## Feature request & issues\n\nIf anything is missing, unclear, or simply not working, open an issue on the repository.\n\n## What is left to do?\n- Better background generation\n- Better handwritten text generation\n- More customization parameters (mostly regarding background)", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Belval/TextRecognitionDataGenerator", "keywords": "synthetic data text-recognition training-set-generator ocr dataset fake text", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "trdg", "package_url": "https://pypi.org/project/trdg/", "platform": "", "project_url": "https://pypi.org/project/trdg/", "project_urls": { "Homepage": "https://github.com/Belval/TextRecognitionDataGenerator" }, "release_url": "https://pypi.org/project/trdg/1.2.0/", "requires_dist": null, "requires_python": "", "summary": "TextRecognitionDataGenerator: A synthetic data generator for text recognition", "version": "1.2.0" }, "last_serial": 5777349, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "77224aabb681c91f0cece97957428d80", "sha256": "685ecc5db4029a0c9f3cc81a5cf03f3f2ca652e58ed12d90fdc7fcb3056d013d" }, "downloads": -1, "filename": "trdg-0.1.1.tar.gz", "has_sig": false, "md5_digest": "77224aabb681c91f0cece97957428d80", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 47542725, "upload_time": "2019-08-29T17:25:55", "url": "https://files.pythonhosted.org/packages/2f/06/f29c7989154a97fd2928ad42b299b49090cc43838f56a876f4d40da4ec01/trdg-0.1.1.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "a2fb0ba6a4f9c4f47939189236cc434e", "sha256": "30ba63c835f8b8ea3df1c459150cceb91334bc344477cb5a06a2813b24c802f0" }, "downloads": -1, "filename": "trdg-1.1.1.tar.gz", "has_sig": false, "md5_digest": "a2fb0ba6a4f9c4f47939189236cc434e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 47534748, "upload_time": "2019-08-30T17:41:21", "url": "https://files.pythonhosted.org/packages/7a/cf/5a7a080e580c9b7d20b609707ba6fca45f3d56ae57c291bf81e195a4b2e2/trdg-1.1.1.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "695123085fbbf1139e650ee3a85afb2a", "sha256": "337693ee5191f01058bcdb752abdcbe35e8317781bd4752eb4aa1e0afb384812" }, "downloads": -1, "filename": "trdg-1.2.0.tar.gz", "has_sig": false, "md5_digest": "695123085fbbf1139e650ee3a85afb2a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 47542838, "upload_time": "2019-09-03T18:21:39", "url": "https://files.pythonhosted.org/packages/dd/d3/bf71ff1abe9874a49a93de68fa8502d147f31f518035a3c83fa1725c6968/trdg-1.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "695123085fbbf1139e650ee3a85afb2a", "sha256": "337693ee5191f01058bcdb752abdcbe35e8317781bd4752eb4aa1e0afb384812" }, "downloads": -1, "filename": "trdg-1.2.0.tar.gz", "has_sig": false, "md5_digest": "695123085fbbf1139e650ee3a85afb2a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 47542838, "upload_time": "2019-09-03T18:21:39", "url": "https://files.pythonhosted.org/packages/dd/d3/bf71ff1abe9874a49a93de68fa8502d147f31f518035a3c83fa1725c6968/trdg-1.2.0.tar.gz" } ] }