Coder Social home page Coder Social logo

lajokoch / synthtextgerman Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 24.87 MB

[German] Code for generating synthetic text images as described in "Synthetic Data for Text Localisation in Natural Images", Ankush Gupta, Andrea Vedaldi, Andrew Zisserman, CVPR 2016.

Home Page: http://www.robots.ox.ac.uk/~vgg/data/scenetext/

License: Apache License 2.0

Python 6.70% MATLAB 0.23% C++ 93.08%
scene-text-images synthetic-data data-engine

synthtextgerman's Introduction

SynthText with German Language Support

Modified from here to support german characters and text. The project was carried out during an internship at the Fraunhofer-Institute for Production Technology and Automation (IPA) in Stuttgart.

Scene-Text Image Samples generated with the code German Scene-Text Samples

Environment

OS: Windows10

python==3.8.5

opencv==4.5.1

pygame==1.9.6

Adjustments to support german text

  • added german text source with 3 million sentences taken from 2015 newspaper texts

    • integrated it in text_utils.py within the class RenderFont()
    • set the encoding to utf-8 in class TextSource()
    • created corresponding character frequency model with update_freq.py
  • added fonts with umlauts (most of them were google fonts) and updated the fontlist.txt

    • created corresponding font model with invert_font_size.py
    • integrated font model in text_utils.py within the class FontState

Usage Steps

  1. Run the script add_more_data.py to download the pre-processed background images with their depth and segmentation masks and to merge them into one h5 file.

    If downloading with add_more_data.py doesn't work you can use wget in git bash terminal to download them manually (more information to use wget on windows see here).

  2. Run gen_more.py to generate new synthetic scene text images withe the pre-processed data.

    Or run gen_more.py --viz to get a visualization after each generated sample.

  3. Visualize your results with visualize_results.py.

  • If you have the same issue as described in issue #105 you can use the test_fonts.py to see which fonts are the reason for this problem.

Data Structure

data
├── bg_img                                   : pre-processed images
├── fonts
│   ├── ubuntu.ttf
│   ├── ...                                  : added fonts
│   └── fontlist.txt                         : updated fontlist
├── german_textSource
│   ├── 3M_sentences_LeipzigCorpora.txt      : added text source
│   └── words_LeipzigCorpora.csv
├── models
│   ├── char_freq.cp                         : updated character model
│   ├── colors_new.cp
│   └── font_px2pt.cp                        : updated font model
├── newsgroup
│   └── newsgroup.txt
├── depth.h5
├── dset_8000.h5                             : pre-processed data [img, depth, seg]
├── dset.h5
└── seg.h5

Parameter Settings

  • number of images: in gen_more.py line 24

  • rendering words, lines or paragraphs: in text_utils.py line 86

    • max words for lines/paragraphs: in text_utils.py line 532
  • font state (curved, underlined, etc.): in text_utils.py line 400

  • text regions: in synthgen.py line 32, line 380 and line 681

The rest of the README is from the original repository

Code for generating synthetic text images as described in "Synthetic Data for Text Localisation in Natural Images", Ankush Gupta, Andrea Vedaldi, Andrew Zisserman, CVPR 2016.

Synthetic Scene-Text Image Samples Synthetic Scene-Text Samples

The code in the master branch is for Python2. Python3 is supported in the python3 branch.

The main dependencies are:

pygame, opencv (cv2), PIL (Image), numpy, matplotlib, h5py, scipy

Generating samples

python gen.py --viz

This will download a data file (~56M) to the data directory. This data file includes:

  • dset.h5: This is a sample h5 file which contains a set of 5 images along with their depth and segmentation information. Note, this is just given as an example; you are encouraged to add more images (along with their depth and segmentation information) to this database for your own use.
  • data/fonts: three sample fonts (add more fonts to this folder and then update fonts/fontlist.txt with their paths).
  • data/newsgroup: Text-source (from the News Group dataset). This can be subsituted with any text file. Look inside text_utils.py to see how the text inside this file is used by the renderer.
  • data/models/colors_new.cp: Color-model (foreground/background text color model), learnt from the IIIT-5K word dataset.
  • data/models: Other cPickle files (char_freq.cp: frequency of each character in the text dataset; font_px2pt.cp: conversion from pt to px for various fonts: If you add a new font, make sure that the corresponding model is present in this file, if not you can add it by adapting invert_font_size.py).

This script will generate random scene-text image samples and store them in an h5 file in results/SynthText.h5. If the --viz option is specified, the generated output will be visualized as the script is being run; omit the --viz option to turn-off the visualizations. If you want to visualize the results stored in results/SynthText.h5 later, run:

python visualize_results.py

Pre-generated Dataset

A dataset with approximately 800000 synthetic scene-text images generated with this code can be found here.

Adding New Images

Segmentation and depth-maps are required to use new images as background. Sample scripts for obtaining these are available here.

  • predict_depth.m MATLAB script to regress a depth mask for a given RGB image; uses the network of Liu etal. However, more recent works (e.g., this) might give better results.
  • run_ucm.m and floodFill.py for getting segmentation masks using gPb-UCM.

For an explanation of the fields in dset.h5 (e.g.: seg,area,label), please check this comment.

Pre-processed Background Images

The 8,000 background images used in the paper, along with their segmentation and depth masks, have been uploaded here: http://www.robots.ox.ac.uk/~vgg/data/scenetext/preproc/<filename>, where, <filename> can be:

filenames size description md5 hash
imnames.cp 180K names of images which do not contain background text
bg_img.tar.gz 8.9G images (filter these using imnames.cp) 3eac26af5f731792c9d95838a23b5047
depth.h5 15G depth maps af97f6e6c9651af4efb7b1ff12a5dc1b
seg.h5 6.9G segmentation maps 1605f6e629b2524a3902a5ea729e86b2

Note: due to large size, depth.h5 is also available for download as 3-part split-files of 5G each. These part files are named: depth.h5-00, depth.h5-01, depth.h5-02. Download using the path above, and put them together using cat depth.h5-0* > depth.h5.

use_preproc_bg.py provides sample code for reading this data.

Note: I do not own the copyright to these images.

Generating Samples with Text in non-Latin (English) Scripts

  • @JarveeLee has modified the pipeline for generating samples with Chinese text here.
  • @adavoudi has modified it for arabic/persian script, which flows from right-to-left here.
  • @MichalBusta has adapted it for a number of languages (e.g. Bangla, Arabic, Chinese, Japanese, Korean) here.
  • @gachiemchiep has adapted for Japanese here.
  • @gungui98 has adapted for Vietnamese here.
  • @youngkyung has adapted for Korean here.

Further Information

Please refer to the paper for more information, or contact me (email address in the paper).

synthtextgerman's People

Contributors

ankush-me avatar codeveryslow avatar lajokoch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

synthtextgerman's Issues

Facing problem while installing specific Numpy version

Hello Sir, We were doing a similar project , So we tried running various Synthtext repositories which are mentioned in the readme,md of Ankush/SythText But we are facing numerous errors while installing, We are trying from a week to install packages and run , We had problem always, Since this is the recently updated repository we tried installing packages mentioned here, But we are getting microsoft visual build failure even though we installed it, Can you please help us sir?

Error while loading font_px2pt_923fonts.cp

Error :
PS C:\SynthTextGerman> & C:/Users/Admin/anaconda3/envs/env1/python.exe c:/SynthTextGerman/gen_more.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
getting data..
-> done
Storing the output in: results/SynthText_8000.h5
Traceback (most recent call last):
File "c:/SynthTextGerman/gen_more.py", line 146, in
main(args.viz)
File "c:/SynthTextGerman/gen_more.py", line 86, in main
RV3 = RendererV3(DATA_PATH, max_time=SECS_PER_IMG)
File "c:\SynthTextGerman\synthgen.py", line 373, in init
self.text_renderer = tu.RenderFont(data_dir)
File "c:\SynthTextGerman\text_utils.py", line 119, in init
self.font_state = FontState(data_dir)
File "c:\SynthTextGerman\text_utils.py", line 450, in init
p = u.load()
File "C:\Users\Admin\anaconda3\envs\env1\lib\pickle.py", line 1212, in load
dispatchkey[0]
File "C:\Users\Admin\anaconda3\envs\env1\lib\pickle.py", line 1337, in load_string
self.append(self._decode_string(codecs.escape_decode(data)[0]))
File "C:\Users\Admin\anaconda3\envs\env1\lib\pickle.py", line 1328, in _decode_string
return value.decode(self.encoding, self.errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9c in position 0: invalid start byte

packages : conda list
packages in environment at C:\Users\Admin\anaconda3\envs\env1:

Name ----------------Version------------Build Channel
autopep8 ------------ 1.5.7 ------------ pyhd3eb1b0_0
ca-certificates ------------2021.7.5 ------------ haa95532_1
certifi ------------ 2020.12.5 ------------ pypi_0 pypi
cycler ------------0.10.0 ------------ pypi_0 pypi
h5py ------------ 3.2.1 ------------ pypi_0 pypi
kiwisolver ------------1.3.1 ------------ pypi_0 pypi
matplotlib ------------3.4.1 ------------ pypi_0 pypi
numpy ------------1.20.2 ------------ pypi_0 pypi
opencv-contrib-python --4.5.1.48 ------------ pypi_0 pypi
openssl ------------1.1.1k ------------ h2bbff1b_0
pickle4 ------------ 0.0.1 ------------ pypi_0 pypi
pillow ------------8.2.0 ------------ pypi_0 pypi
pip ------------21.2.2 ------------ py38haa95532_0
pycodestyle ------------2.7.0 ------------ pyhd3eb1b0_0
pygame ------------1.9.6 ------------ pypi_0 pypi
pyparsing ------------ 2.4.7 ------------ pypi_0 pypi
python ------------ 3.8.11 ------------ h6244533_0_cpython
python-dateutil ------2.8.1 ------------ pypi_0 pypi
python-wget ------------3.2 ------------ py_0 conda-forge
python_abi------------3.8 ------------ 2_cp38 conda-forge
pytz ------------ 2021.1 ------------ pypi_0 pypi
scipy ------------1.6.2 ------------ pypi_0 pypi
setuptools ------------ 49.6.0 ------------ pypi_0 pypi
six ------------1.15.0 ------------ pypi_0 pypi
snakeviz ------------ 2.1.0 ------------ pypi_0 pypi
sqlite ------------ 3.36.0 ------------ h2bbff1b_0
toml ------------0.10.2 ------------ pyhd3eb1b0_0
tornado ------------6.1 ------------ pypi_0 pypi
vc ------------14.1 ------------ h0510ff6_4 anaconda
vs2015_runtime ------------14.27.29016 h5e58377_2
wheel------------0.36.2 ------------ pyhd3eb1b0_0
wincertstore ------------ 0.2 ------------ py38_0

I did the following :

  1. Run add_more_data.py
  2. Run update_freq.py
  3. gen_more.py but getting above error, I tried resolving this But couldn't,
    There is a problem with loading font_px2pt_923fonts.cp and When i cloned it there was no font_px2pt_923fonts.cp So I renamed font_px2pt.cp to font_px2pt_923fonts.cp. And Even fonts was not there so I downloaded some fonts listed online and placed in fonts folder.
    Please help us in resolving this issue

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.