-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_examples.py
113 lines (102 loc) · 2.95 KB
/
make_examples.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
# ------------------------------------------------------------
# Copyright (C) 2020-Present, Pvening, Co.,Ltd.
#
# Licensed under the BSD 2-Clause License.
# You should have received a copy of the BSD 2-Clause License
# along with the software. If not, See,
#
# <https://opensource.org/licenses/BSD-2-Clause>
#
# ------------------------------------------------------------
import cv2
import numpy as np
from plategen import plate
from plategen.pipline import plate_generator_pipline
from plategen.plate import shuffle as ps
def make_single():
pg = plate.RandomPlateCompose([
plate.SingleBluePlate(140),
plate.SingleGreenPlateA(140),
plate.SingleGreenPlateB(140),
plate.SingleBlackPlate(140),
plate.SingleBlackPlateAo(140),
plate.SingleBlackPlateGang(140),
plate.SingleBlackPlateLing(140),
plate.SingleBlackPlateShi(140),
plate.SingleYellowPlate(140),
plate.SingleYellowPlateXue(140),
plate.SingleWhitePlateJing(140),
])
ds = plate_generator_pipline(pg)
ds.reset_state()
ds = iter(ds)
nh, nw = 10, 5
ph, pw = 140, 440
canvas = np.zeros((ph * nh, pw * nw, 3))
count = 0
x, y = 0, 0
for i in range(nh * nw):
img, txt = next(ds)
img = cv2.resize(img, (pw, ph))
if count % nw == 0 and count != 0:
x = 0
y += ph
canvas[y:y + ph, x:x + pw] = img
x += pw
count += 1
cv2.imwrite('examples/single_plate.jpg', canvas)
def make_double():
pg = plate.RandomPlateCompose([
plate.DoubleYellowPlate(220),
plate.DoubleWhitePlate(220),
plate.DoubleBluePlate(220),
])
ds = plate_generator_pipline(pg)
ds.reset_state()
ds = iter(ds)
nh, nw = 10, 5
ph, pw = 220, 440
canvas = np.zeros((ph * nh, pw * nw, 3))
count = 0
x, y = 0, 0
for i in range(nh * nw):
img, txt = next(ds)
img = cv2.resize(img, (pw, ph))
if count % nw == 0 and count != 0:
x = 0
y += ph
canvas[y:y + ph, x:x + pw] = img
x += pw
count += 1
cv2.imwrite('examples/double_plate.jpg', canvas)
def make_shuffle():
ph, pw = 140, 440
pg = plate.RandomPlateCompose([
ps.ShuffleBlue(ph),
ps.ShuffleWhite(ph),
ps.ShuffleNew(ph),
ps.ShuffleYellow(ph),
ps.ShuffleBlack(ph),
])
ds = plate_generator_pipline(pg)
ds.reset_state()
ds = iter(ds)
nh, nw = 10, 5
canvas = np.zeros((ph * nh, pw * nw, 3))
count = 0
x, y = 0, 0
for i in range(nh * nw):
img, txt = next(ds)
img = cv2.resize(img, (pw, ph))
if count % nw == 0 and count != 0:
x = 0
y += ph
canvas[y:y + ph, x:x + pw] = img
x += pw
count += 1
cv2.imwrite('examples/shuffle_plate.jpg', canvas)
if __name__ == '__main__':
# make_single()
# make_double()
make_shuffle()