개정판 30315460
dev issue #646: add progressbar
DTI_PID/DTI_PID/DetectSymbolDialog.py | ||
---|---|---|
60 | 60 |
symbolEditorDialog.showDialog() |
61 | 61 |
self.parent.dirTreeWidget.initDirTreeWidget() |
62 | 62 |
|
63 |
|
|
64 | 63 |
''' |
65 | 64 |
@brief text changed Event |
66 | 65 |
@author kyouho |
... | ... | |
80 | 79 |
if not self.ui.listWidgetDrawings.count(): |
81 | 80 |
return |
82 | 81 |
|
82 |
self.progress = QProgressDialog("잠시만 기다려주세요", "Cancel", 0, 100, self) |
|
83 |
self.progress.setWindowModality(Qt.WindowModal) |
|
84 |
self.progress.setAutoReset(True) |
|
85 |
self.progress.setAutoClose(True) |
|
86 |
self.progress.setMinimum(0) |
|
87 |
self.progress.resize(600,100) |
|
88 |
self.progress.setWindowTitle("인식 중...") |
|
89 |
self.progress.show() |
|
90 |
self.progress.setMaximum(100) |
|
91 |
self.progress.setValue(0) |
|
92 |
QApplication.processEvents() |
|
93 |
|
|
83 | 94 |
from TextDetector import TextDetector |
84 | 95 |
import numpy as np |
85 |
xml = Element('BOXES') |
|
86 | 96 |
|
87 | 97 |
appDocData = AppDocData.instance() |
88 | 98 |
## textDetector에서 사용하기 때문에 설정 |
... | ... | |
116 | 126 |
## 다시 색반전 |
117 | 127 |
areaImg = cv2.bitwise_not(areaImg) |
118 | 128 |
|
129 |
## find lines |
|
130 |
verticalLineList = [] |
|
131 |
horizontalLineList = [] |
|
132 |
self.findLines(areaImg, verticalLineList, horizontalLineList) |
|
133 |
|
|
134 |
## chage color |
|
135 |
for vLine in verticalLineList: |
|
136 |
p1 = vLine[0] |
|
137 |
p2 = vLine[1] |
|
138 |
x = p1[0] |
|
139 |
areaImg[p1[1]:p2[1], x] = 255 |
|
140 |
## chage color |
|
141 |
for vLine in horizontalLineList: |
|
142 |
p1 = vLine[0] |
|
143 |
p2 = vLine[1] |
|
144 |
y = p1[1] |
|
145 |
areaImg[y, p1[0]:p2[0]] = 255 |
|
146 |
|
|
147 |
## contours 추출을 위한 색반전 |
|
148 |
areaImg = cv2.bitwise_not(areaImg) |
|
149 |
## contours 추출 |
|
150 |
recList = self.getContours(areaImg) |
|
151 |
|
|
152 |
## to xml |
|
153 |
self.toXml(recList, offset) |
|
154 |
|
|
155 |
self.tableSetting() |
|
156 |
|
|
157 |
self.progress.setValue(self.progress.maximum()) |
|
158 |
|
|
159 |
|
|
160 |
''' |
|
161 |
@brief find lines |
|
162 |
@author kyouho |
|
163 |
@date 2018.10.01 |
|
164 |
''' |
|
165 |
def findLines(self, areaImg, verticalLineList, horizontalLineList): |
|
166 |
|
|
119 | 167 |
## for multiprocessing |
120 | 168 |
verticalProcessList = [] |
121 |
verticalLineList = [] |
|
122 | 169 |
horizontalProcessList = [] |
123 |
horizontalLineList = [] |
|
124 | 170 |
|
125 | 171 |
## Find VerticalLine using multiprocessing |
126 | 172 |
## Set Vertical Line |
... | ... | |
151 | 197 |
horizontalProcessList.append((_process, _queue)) |
152 | 198 |
value = value + jumpValue |
153 | 199 |
|
200 |
## set percent |
|
201 |
progressCount = len(verticalProcessList) + len(horizontalProcessList) + 1 |
|
202 |
percentGage = int(100 / progressCount) |
|
203 |
percent = percentGage |
|
204 |
self.progress.setValue(percent) |
|
205 |
QApplication.processEvents() |
|
206 |
|
|
154 | 207 |
## process start |
155 | 208 |
for process in verticalProcessList: |
156 | 209 |
process[0].start() |
... | ... | |
161 | 214 |
verticalProcessList[index][0].join() |
162 | 215 |
verticalProcessList[index][1].close() |
163 | 216 |
|
217 |
percent = percent + percentGage |
|
218 |
self.progress.setValue(percent) |
|
219 |
QApplication.processEvents() |
|
220 |
|
|
164 | 221 |
horizontalProcessList[index][0].start() |
165 | 222 |
|
166 | 223 |
## Wait Horizontal |
... | ... | |
169 | 226 |
process[0].join() |
170 | 227 |
process[1].close() |
171 | 228 |
|
172 |
## chage color |
|
173 |
for vLine in verticalLineList: |
|
174 |
p1 = vLine[0] |
|
175 |
p2 = vLine[1] |
|
176 |
x = p1[0] |
|
177 |
areaImg[p1[1]:p2[1], x] = 255 |
|
178 |
## chage color |
|
179 |
for vLine in horizontalLineList: |
|
180 |
p1 = vLine[0] |
|
181 |
p2 = vLine[1] |
|
182 |
y = p1[1] |
|
183 |
areaImg[y, p1[0]:p2[0]] = 255 |
|
184 |
|
|
229 |
percent = percent + percentGage |
|
230 |
self.progress.setValue(percent) |
|
231 |
QApplication.processEvents() |
|
232 |
|
|
185 | 233 |
|
186 |
## contours 추출을 위한 색반전 |
|
187 |
areaImg = cv2.bitwise_not(areaImg) |
|
188 |
## contours 추출 |
|
234 |
|
|
235 |
''' |
|
236 |
@brief get contours |
|
237 |
@author kyouho |
|
238 |
@date 2018.10.01 |
|
239 |
''' |
|
240 |
def getContours(self, areaImg): |
|
241 |
|
|
189 | 242 |
image, contours, hierarchy = cv2.findContours(areaImg, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
190 | 243 |
|
191 | 244 |
## RecList 정리 |
... | ... | |
224 | 277 |
|
225 | 278 |
tempRecList.remove(rec1) |
226 | 279 |
|
280 |
return recList |
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
''' |
|
286 |
@brief box to xml |
|
287 |
@author kyouho |
|
288 |
@date 2018.10.01 |
|
289 |
''' |
|
290 |
def toXml(self, recList, offset): |
|
291 |
xml = Element('BOXES') |
|
292 |
|
|
227 | 293 |
## to xml |
228 | 294 |
for rec in recList: |
229 | 295 |
[x1, y1, x2, y2] = rec |
... | ... | |
253 | 319 |
xml.append(boxElement) |
254 | 320 |
|
255 | 321 |
ElementTree(xml).write(self.boxDir + self.imageName + '.box') |
256 |
self.tableSetting() |
|
257 | 322 |
|
258 |
def isLine(self, x, y, img, minLineSize, matrix): |
|
259 |
maxX = img.shape[1] |
|
260 |
maxY = img.shape[0] |
|
261 |
|
|
262 |
## Horizontal |
|
263 |
for moveX in range(x + 1, maxX): |
|
264 |
if matrix[moveX][y][0]: |
|
265 |
break |
|
266 |
|
|
267 |
if img[y,moveX] != 0: |
|
268 |
if moveX - x > minLineSize: |
|
269 |
return (True, 'H', moveX) |
|
270 |
break |
|
271 |
matrix[moveX][y][0] = True |
|
272 |
|
|
273 |
## Vertical |
|
274 |
for moveY in range(y + 1, maxY): |
|
275 |
if matrix[x][moveY][1]: |
|
276 |
break |
|
277 |
|
|
278 |
if img[moveY,x] != 0: |
|
279 |
if moveY - y > minLineSize: |
|
280 |
return (True, 'V', moveY) |
|
281 |
break |
|
282 |
matrix[x][moveY][1] = True |
|
283 |
|
|
284 |
return (False,) |
|
285 |
|
|
286 |
def isCombinable(self, pointList1, pointList2): |
|
287 |
for pt1 in pointList1: |
|
288 |
for pt2 in pointList2: |
|
289 |
if Point(pt1[0],pt1[1]).distance(Point(pt2[0],pt2[1])) < 10: |
|
290 |
return True |
|
291 | 323 |
''' |
292 | 324 |
@brief text changed Event |
293 | 325 |
@author kyouho |
내보내기 Unified diff