Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ ENV/

# Rope project settings
.ropeproject
data/
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
# SynthText
This a modified version of [Ankush's code](https://github.com/ankush-me/SynthText) for generating synthetic text images which support right-to-left languages such as Persian and Arabic.

As in Persian and Arabic, words are made using connected letters, this code only outputs the word level bounding boxes.

**A sample output of the code**
![Persian Synthetic Scene-Text Samples](sample_fa.png "Persian Synthetic Samples")

## Install the necessary libs and create a conda environment
First install the `fribidi` library

```
sudo apt install libfribidi-dev
```

Then create a conda environment from the `environment.yml` file:

```
conda env create -f environment.yml
```

Activate the environment with the following command:

```
conda activate gentext
```

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](http://www.robots.ox.ac.uk/~vgg/data/scenetext/).


Expand Down
21 changes: 21 additions & 0 deletions colorize3_poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def sample_weighted(p_dict):
ps = p_dict.keys()
return ps[np.random.choice(len(ps),p=p_dict.values())]

def rgb_color_diff_in_gray(col1, col2):
gray1 = col1[0]*0.299 + col1[1]*0.587 + col1[2]*0.114
gray2 = col2[0]*0.299 + col2[1]*0.587 + col2[2]*0.114
return abs(gray1 - gray2)

class Layer(object):

def __init__(self,alpha,color):
Expand Down Expand Up @@ -45,6 +50,7 @@ def __init__(self,alpha,color):
class FontColor(object):

def __init__(self, col_file):
self.gray_diff_threshold = 25
with open(col_file,'rb') as f:
#self.colorsRGB = cp.load(f)
u = pickle._Unpickler(f)
Expand Down Expand Up @@ -90,10 +96,25 @@ def sample_from_data(self, bg_mat):
col1 = self.sample_normal(data_col[:3],data_col[3:6])
col2 = self.sample_normal(data_col[6:9],data_col[9:12])

## fix as follows
true_bg_col = np.mean(np.mean(bg_orig, axis=0), axis=0)
if nn < self.ncol:
fg_col = col2
diff = rgb_color_diff_in_gray(fg_col, true_bg_col)
while diff < self.gray_diff_threshold:
#print 'change color'
fg_col = np.random.choice(256, 3).astype('uint8')
diff = rgb_color_diff_in_gray(fg_col, true_bg_col)
col2 = fg_col
return (col2, col1)
else:
# need to swap to make the second color close to the input backgroun color
fg_col = col1
diff = rgb_color_diff_in_gray(fg_col, true_bg_col)
while diff < self.gray_diff_threshold:
fg_col = np.random.choice(256, 3).astype('uint8')
diff = rgb_color_diff_in_gray(fg_col, true_bg_col)
col1 = fg_col
return (col1, col2)

def mean_color(self, arr):
Expand Down
69 changes: 69 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: gentext
channels:
- defaults
dependencies:
- _libgcc_mutex=0.1=main
- blas=1.0=mkl
- bzip2=1.0.6=h14c3975_5
- ca-certificates=2019.5.15=0
- cairo=1.14.12=h8948797_3
- certifi=2019.6.16=py36_0
- ffmpeg=4.0=hcdf2ecd_0
- fontconfig=2.13.0=h9420a91_0
- freeglut=3.0.0=hf484d3e_5
- freetype=2.9.1=h8a8886c_1
- glib=2.56.2=hd408876_0
- graphite2=1.3.13=h23475e2_0
- harfbuzz=1.8.8=hffaf4a1_0
- hdf5=1.10.2=hba1933b_1
- icu=58.2=h9c2bf20_1
- intel-openmp=2019.4=243
- jasper=2.0.14=h07fcdf6_1
- jpeg=9b=h024ee3a_2
- libedit=3.1.20181209=hc058e9b_0
- libffi=3.2.1=hd88cf55_4
- libgcc-ng=8.2.0=hdf63c60_1
- libgfortran-ng=7.3.0=hdf63c60_0
- libglu=9.0.0=hf484d3e_1
- libopencv=3.4.2=hb342d67_1
- libopus=1.3=h7b6447c_0
- libpng=1.6.37=hbc83047_0
- libstdcxx-ng=8.2.0=hdf63c60_1
- libtiff=4.0.10=h2733197_2
- libuuid=1.0.3=h1bed415_2
- libvpx=1.7.0=h439df22_0
- libxcb=1.13=h1bed415_1
- libxml2=2.9.9=hea5a465_1
- mkl=2019.4=243
- mkl_fft=1.0.12=py36ha843d7b_0
- mkl_random=1.0.2=py36hd81dba3_0
- ncurses=6.1=he6710b0_1
- opencv=3.4.2=py36h6fd60c2_1
- openssl=1.0.2s=h7b6447c_0
- pcre=8.43=he6710b0_0
- pip=19.0.3=py36_0
- pixman=0.38.0=h7b6447c_0
- py-opencv=3.4.2=py36hb342d67_1
- python=3.6.5=hc3d631a_2
- readline=7.0=h7b6447c_5
- setuptools=40.8.0=py36_0
- sqlite=3.26.0=h7b6447c_0
- tk=8.6.8=hbc83047_0
- wheel=0.33.1=py36_0
- xz=5.2.4=h14c3975_4
- zlib=1.2.11=h7b6447c_3
- zstd=1.3.7=h0b5b093_0
- pip:
- cycler==0.10.0
- h5py==2.7.1
- matplotlib==2.1.1
- numpy==1.16.4
- pillow==5.0.0
- pygame==1.9.3
- pyparsing==2.2.0
- python-dateutil==2.6.1
- pytz==2017.3
- scapy==2.4.2
- scipy==1.0.0
- wget==3.2

Loading