-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput_data.py
72 lines (62 loc) · 2.06 KB
/
input_data.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 5 15:44:33 2017
@author: llc
"""
#%%
import numpy as np
import cv2
from genplate import *
#产生用于训练的数据
class OCRIter():
def __init__(self,batch_size,height,width):
super(OCRIter, self).__init__()
self.genplate = GenPlate("./font/platech.ttf",'./font/platechar.ttf','./NoPlates')
self.batch_size = batch_size
self.height = height
self.width = width
#print("make plate data")
# def iter(self):
# for k in range((int)(self.count / self.batch_size)):
# data = []
# label = []
# for i in range(self.batch_size):
# num, img = gen_sample(self.genplate, self.width, self.height)
# data.append(img)
# label.append(num)
# data_all = data
# label_all = label
# return data_all,label_all
def iter(self):
data = []
label = []
for i in range(self.batch_size):
num, img = gen_sample(self.genplate, self.width, self.height)
data.append(img)
label.append(num)
data_all = data
label_all = label
return data_all,label_all
def rand_range(lo,hi):
return lo+r(hi-lo);
def gen_rand():
name = ""
label=[]
label.append(rand_range(0,31)) #产生车牌开头32个省的标签
label.append(rand_range(41,65)) #产生车牌第二个字母的标签
for i in range(5):
label.append(rand_range(31,65)) #产生车牌后续5个字母的标签
name+=chars[label[0]]
name+=chars[label[1]]
for i in range(5):
name+=chars[label[i+2]]
return name,label
def gen_sample(genplate, width, height):
num,label =gen_rand()
img = genplate.generate(num)
img = cv2.resize(img,(width,height))
img = np.multiply(img,1/255.0) #[height,width,channel]
#img = img.transpose(2,0,1)
#img = img.transpose(1,0,2)
return label,img #返回的label为标签,img为深度为3的图像像素