-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword_list_frame.py
178 lines (147 loc) · 5.61 KB
/
word_list_frame.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#coding=utf8
__author__ = 'song'
import wx
from wx import xrc
import frame_xrc
import ImageTool
import ocr_normalize
import ocr_segmentation
import thinning
from PIL import ImageDraw
import ocr_feature_extraction
import ocr_match
class WordListFrame(frame_xrc.xrcWordList):
def BindEvent(self):
self.Bind(wx.EVT_MENU, self.OnGetSide0, id=xrc.XRCID("menu_find_side0"))
self.Bind(wx.EVT_MENU, self.OnGetSide1, id=xrc.XRCID("menu_find_side1"))
self.Bind(wx.EVT_MENU, self.OnGetSide2, id=xrc.XRCID("menu_find_side2"))
self.Bind(wx.EVT_MENU, self.OnResize, id=xrc.XRCID("menu_resize"))
self.Bind(wx.EVT_MENU, self.OnThinning, id=xrc.XRCID("menu_thinning"))
self.Bind(wx.EVT_MENU, self.OnMatch1, id=xrc.XRCID("menu_match_od"))
def __init__(self, word_list):
frame_xrc.xrcWordList.__init__(self, None)
# load some images into an image list
#创建图像列表
self.word_list = word_list
self.il = wx.ImageList(200, 200, True)
for im, info in word_list:
try:
img = ImageTool.pilImage_to_wxImage(im)
except:
print im, im.size, info
continue
bmp = wx.BitmapFromImage(img)
self.il.Add(bmp)
# create the list control
#创建列表窗口部件
self.list = xrc.XRCCTRL(self, "img_list_ctrl")
# assign the image list to it
self.list.AssignImageList(self.il, wx.IMAGE_LIST_NORMAL)
# create some items for the list
#为列表创建一些项目
for x in range(len(word_list)):
img_index = x
name = str(word_list[x][1])
self.list.InsertImageStringItem(x, name, img_index)
self.BindEvent()
def OnGetSide0(self, event):
img_list = []
for im, info in self.word_list:
hist_im = im.histogram()[255]
if hist_im == 0:
continue
_x, _y, x_, y_ = ocr_normalize.GetWordSide(im)
#img = im.copy()
try:
img = ocr_segmentation.GetWord(im, _x, _y, x_-_x, y_-_y)
except:
print info, im.size, _x, _y, x_, y_
continue
#exit()
hist_img = img.histogram()[255]
percent = float(hist_img)/float(hist_im)
img_list.append((img, percent))
word_side_frame = WordListFrame(img_list)
word_side_frame.Show()
def OnGetSide1(self, event):
img_list = []
for im, info in self.word_list:
hist_im = im.histogram()[255]
if hist_im == 0:
continue
_x, _y, x_, y_ = ocr_normalize.GetWordSide1(im)
#img = im.copy()
try:
img = ocr_segmentation.GetWord(im, _x, _y, x_-_x, y_-_y)
except:
print info, im.size, _x, _y, x_, y_
continue
#exit()
hist_img = img.histogram()[255]
percent = float(hist_img)/float(hist_im)
img_list.append((img, percent))
print "new"
word_side_frame = WordListFrame(img_list)
word_side_frame.Show()
def OnGetSide2(self, event):
img_list = []
for im, info in self.word_list:
hist_im = im.histogram()[255]
if hist_im == 0:
continue
_x, _y, x_, y_ = ocr_normalize.GetWordSide1(im)
#img = im.copy()
try:
img = ocr_segmentation.GetWord(im, _x, _y, x_-_x, y_-_y)
except:
print info, im.size, _x, _y, x_, y_
continue
#exit()
hist_img = img.histogram()[255]
percent = float(hist_img)/float(hist_im)
print percent
if percent < 0.93:
_nx, _ny, nx_, ny_ = ocr_normalize.ModifyWordSide(im, _x, _y, x_, y_)
print "_x,_y,x_,y_",_x, _y, x_, y_
print "new_x,_y,x_,y_",_nx, _ny, nx_, ny_
print "im size:", im.size
try:
img = ocr_segmentation.GetWord(im, _nx, _ny, nx_-_nx, ny_-_ny)
except:
continue
hist_img = img.histogram()[255]
percent = float(hist_img)/float(hist_im)
if percent < 0.93:
print "percent2", percent
_x, _y, x_, y_ = _nx, _ny, nx_, ny_
_nx, _ny, nx_, ny_ = ocr_normalize.ModifyWordSide(im, _x, _y, x_, y_)
try:
img = ocr_segmentation.GetWord(im, _nx, _ny, nx_-_nx, ny_-_ny)
except:
continue
hist_img = img.histogram()[255]
percent = float(hist_img)/float(hist_im)
img_list.append((img, percent))
print "new"
word_side_frame = WordListFrame(img_list)
word_side_frame.Show()
def OnResize(self, event):
img_list = []
for im, info in self.word_list:
img = im.resize((48, 48))
img_list.append((img, info))
word_side_frame = WordListFrame(img_list)
word_side_frame.Show()
def OnThinning(self, event):
img_list = []
for im, info in self.word_list:
img = thinning.ThinningImage(im)
img_list.append((img, info))
word_side_frame = WordListFrame(img_list)
word_side_frame.Show()
def OnMatch1(self, event):
i = 0
for im, info in self.word_list:
i += 1
im.save("test/"+str(i)+".png")
print "save over!"