-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool.py
94 lines (77 loc) · 2.05 KB
/
tool.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
from PIL import Image, ImageOps
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
def get_template1():
def img_to_img2(img):
img2 = np.average(img, axis=-1)
img2 = (img2 > 230) * 255
return img2
img = np.array(Image.open('images4/16440712339.bmp'))
height = 35
width = 29
x0 = 10
y0 = 455
stride = 72.8
for i in range(14):
x = x0 + int(i * stride)
y = y0
rect = img[y:y+height, x: x+width]
rect = img_to_img2(rect)
char_img = Image.fromarray(rect)
char_img = char_img.convert('1')
char_img.save(str(i) + '.bmp')
def get_template2():
img = np.array(Image.open('images4/16440712339.bmp'))
height = 35
width = 29
x0 = 10
y0 = 455
stride = 72.8
for i in range(14):
x = x0 + int(i * stride)
y = y0
rect = img[y:y + height, x: x + width]
char_img = Image.fromarray(rect)
char_img.save(str(i) + '.bmp')
def get_template3():
img = np.array(Image.open('images3/16440623144.bmp'))
height = 35
width = 29
x0 = 59
y0 = 419
stride = 81.9
for i in range(12):
x = x0 + int(i * stride)
y = y0
rect = img[y:y + height, x: x + width]
char_img = Image.fromarray(rect)
char_img.save(str(i) + '.bmp')
def get_template4():
img = np.array(Image.open('images2/16440608578.bmp'))
height = 27
width = 22
x0 = 889
y0 = 180
stride = 33.25
for i in range(2):
x = x0 + int(i * stride)
y = y0
rect = img[y:y + height, x: x + width]
char_img = Image.fromarray(rect)
char_img.save(str(i) + '.bmp')
def get_template5():
img = np.array(Image.open('images2/16440608578.bmp'))
height = 27
width = 22
x0 = 89
y0 = 180
stride = 33.25
for i in range(6):
x = x0 + int(i * stride)
y = y0
rect = img[y:y + height, x: x + width]
char_img = Image.fromarray(rect)
char_img.save(str(i) + '.bmp')
get_template4()
# get_template5()