-
Notifications
You must be signed in to change notification settings - Fork 308
/
modify_length.py
41 lines (40 loc) · 1.11 KB
/
modify_length.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
import os.path as osp
import random, os
import cv2
import cPickle as cp
import scipy.signal as ssig
import scipy.stats as sstat
import pygame, pygame.locals
from pygame import freetype
#import Image
from PIL import Image
import math
from common import *
from random import randint
rp_path='/home/yuz/lijiahui/syntheticdata/SynthText/data/newgroup_modify/'
fn='/home/yuz/lijiahui/syntheticdata/SynthText/data/newsgroup/'
files= os.listdir(fn)
files=files[0:-1]
for filename in files:
print filename
fc=filename#.decode('utf-8')
write_path=rp_path+fc
fc=fn+fc
print fc
with open(fc,'r') as f:
f2=open(write_path,'w')
print write_path
for l in f.readlines():
line=l.strip()
#line=line.decode('utf-8')
print line
for i in range(len(line)):
tl=randint(0,9)
if i + tl<len(line):
f2.write('%s\n'%line[i:i+tl])
else:
f2.write('%s\n'%line[i:-1])