개정판 93295502
issue #663: fixed line detection error(too large line thickness)
Change-Id: If5e70931f2f381d9d730dbbff3114f79c6329408
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
3326 | 3326 |
cursor.execute(sql) |
3327 | 3327 |
|
3328 | 3328 |
# delete LineNoAttributes |
3329 |
sql = "delete from LineNoAttributes where Components_UID in (select UID from Components where Drawings_UID='{}')".format(
|
|
3330 |
drawing_uid)
|
|
3329 |
sql = f"delete from LineNoAttributes where Components_UID in " \
|
|
3330 |
f"(select UID from Components where Drawings_UID='{drawing_uid}')"
|
|
3331 | 3331 |
cursor.execute(sql) |
3332 | 3332 |
|
3333 | 3333 |
# delete Attributes |
3334 |
sql = "delete from Attributes where Components_UID in (select UID from Components where Drawings_UID='{}')".format(
|
|
3335 |
drawing_uid)
|
|
3334 |
sql = f"delete from Attributes where Components_UID in " \
|
|
3335 |
f"(select UID from Components where Drawings_UID='{drawing_uid}')"
|
|
3336 | 3336 |
cursor.execute(sql) |
3337 | 3337 |
|
3338 | 3338 |
# delete Associations |
3339 |
sql = "delete from Associations where Components_UID in (select UID from Components where Drawings_UID='{}')".format(
|
|
3340 |
drawing_uid)
|
|
3339 |
sql = f"delete from Associations where Components_UID in " \
|
|
3340 |
f"(select UID from Components where Drawings_UID='{drawing_uid}')"
|
|
3341 | 3341 |
cursor.execute(sql) |
3342 | 3342 |
|
3343 | 3343 |
# delete Points |
3344 |
sql = "delete from Points where Components_UID in (select UID from Components where Drawings_UID='{}')".format(
|
|
3345 |
drawing_uid)
|
|
3344 |
sql = f"delete from Points where Components_UID in " \
|
|
3345 |
f"(select UID from Components where Drawings_UID='{drawing_uid}')"
|
|
3346 | 3346 |
cursor.execute(sql) |
3347 | 3347 |
|
3348 | 3348 |
# delete PipeRunItems |
3349 |
sql = "delete from PipeRunItems where PipeRuns_UID in (select UID from PipeRuns where Drawings_UID='{}')".format(
|
|
3350 |
drawing_uid)
|
|
3349 |
sql = f"delete from PipeRunItems where PipeRuns_UID in " \
|
|
3350 |
f"(select UID from PipeRuns where Drawings_UID='{drawing_uid}')"
|
|
3351 | 3351 |
cursor.execute(sql) |
3352 | 3352 |
|
3353 | 3353 |
# delete PipeRuns |
3354 |
sql = "delete from PipeRuns where Drawings_UID='{}'".format(drawing_uid)
|
|
3354 |
sql = f"delete from PipeRuns where Drawings_UID='{drawing_uid}'"
|
|
3355 | 3355 |
cursor.execute(sql) |
3356 | 3356 |
|
3357 | 3357 |
# delete Components |
DTI_PID/DTI_PID/ConfigurationAreaDialog.py | ||
---|---|---|
4 | 4 |
""" |
5 | 5 |
import os |
6 | 6 |
import sys |
7 |
|
|
7 | 8 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Commands') |
8 | 9 |
import FenceCommand |
9 | 10 |
from PyQt5.QtCore import * |
... | ... | |
20 | 21 |
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
21 | 22 |
import Configuration_Area_UI |
22 | 23 |
|
24 |
|
|
23 | 25 |
class QConfigurationAreaDialog(QDialog): |
24 | 26 |
def __init__(self, parent): |
25 | 27 |
import re |
... | ... | |
33 | 35 |
self.ui.tableWidgetEquipmentDescArea.setHorizontalHeaderLabels(['Drawing Name', 'Area']) |
34 | 36 |
for index in range(self.ui.tableWidgetEquipmentDescArea.columnCount()): |
35 | 37 |
self.ui.tableWidgetEquipmentDescArea.horizontalHeaderItem(0).setSizeHint(QSize(25, 25)) |
36 |
self.ui.tableWidgetEquipmentDescArea.setColumnWidth(index, len(self.ui.tableWidgetEquipmentDescArea.horizontalHeaderItem(index).text()) * 8 + 10) |
|
38 |
self.ui.tableWidgetEquipmentDescArea.setColumnWidth(index, len( |
|
39 |
self.ui.tableWidgetEquipmentDescArea.horizontalHeaderItem(index).text()) * 8 + 10) |
|
37 | 40 |
self.ui.tableWidgetTitleBlockArea.setColumnCount(4) |
38 | 41 |
self.ui.tableWidgetTitleBlockArea.setHorizontalHeaderLabels(['UID', 'Name', 'Area', 'defualt text']) |
39 | 42 |
for index in range(self.ui.tableWidgetTitleBlockArea.columnCount()): |
40 | 43 |
self.ui.tableWidgetTitleBlockArea.horizontalHeaderItem(0).setSizeHint(QSize(25, 25)) |
41 |
self.ui.tableWidgetTitleBlockArea.setColumnWidth(index, len(self.ui.tableWidgetTitleBlockArea.horizontalHeaderItem(index).text()) * 8 + 10) |
|
44 |
self.ui.tableWidgetTitleBlockArea.setColumnWidth(index, len( |
|
45 |
self.ui.tableWidgetTitleBlockArea.horizontalHeaderItem(index).text()) * 8 + 10) |
|
42 | 46 |
self.ui.tableWidgetTitleBlockArea.hideColumn(0) |
43 | 47 |
self.isAccepted = False |
44 | 48 |
self._cmd = FenceCommand.FenceCommand(self.parent().graphicsView) |
... | ... | |
48 | 52 |
areas = docData.getAreaList() |
49 | 53 |
|
50 | 54 |
# load area of drawing |
51 |
matches = [x for x in areas if x.name=='Drawing'] |
|
52 |
self.ui.lineEditDrawing.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, matches[0].height) if len(matches) == 1 else None |
|
55 |
matches = [x for x in areas if x.name == 'Drawing'] |
|
56 |
self.ui.lineEditDrawing.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, |
|
57 |
matches[0].height) if len(matches) == 1 else None |
|
53 | 58 |
if self.ui.lineEditDrawing.tag is not None: |
54 | 59 |
self.ui.lineEditDrawing.tag.transfer.onSizeChanged.connect(self.onBoundingBoxChanged) |
55 |
self.ui.lineEditDrawing.setText('({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), round(matches[0].height))) |
|
60 |
self.ui.lineEditDrawing.setText( |
|
61 |
'({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), |
|
62 |
round(matches[0].height))) |
|
56 | 63 |
self.ui.lineEditDrawing.tag.setPen(QPen(Qt.red, THICKNESS, Qt.SolidLine)) |
57 | 64 |
self.parent().graphicsView.scene.addItem(self.ui.lineEditDrawing.tag) |
58 | 65 |
self.ui.pushButtonDrawingArea.setStyleSheet('background-color: red') |
59 | 66 |
|
60 |
matches = [x for x in areas if x.name=='Note'] |
|
61 |
self.ui.lineEditNote.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, matches[0].height) if len(matches) == 1 else None |
|
67 |
matches = [x for x in areas if x.name == 'Note'] |
|
68 |
self.ui.lineEditNote.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, |
|
69 |
matches[0].height) if len(matches) == 1 else None |
|
62 | 70 |
if self.ui.lineEditNote.tag is not None: |
63 | 71 |
self.ui.lineEditNote.tag.transfer.onSizeChanged.connect(self.onBoundingBoxChanged) |
64 |
self.ui.lineEditNote.setText('({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), round(matches[0].height))) |
|
72 |
self.ui.lineEditNote.setText( |
|
73 |
'({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), |
|
74 |
round(matches[0].height))) |
|
65 | 75 |
self.ui.lineEditNote.tag.setPen(QPen(Qt.blue, THICKNESS, Qt.SolidLine)) |
66 | 76 |
self.parent().graphicsView.scene.addItem(self.ui.lineEditNote.tag) |
67 | 77 |
self.ui.pushButtonNoteArea.setStyleSheet('background-color: blue') |
68 | 78 |
|
69 |
matches = [x for x in areas if x.name=='History Data'] |
|
70 |
self.ui.lineEditHistoryData.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, matches[0].height) if len(matches) == 1 else None |
|
79 |
matches = [x for x in areas if x.name == 'History Data'] |
|
80 |
self.ui.lineEditHistoryData.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, |
|
81 |
matches[0].height) if len(matches) == 1 else None |
|
71 | 82 |
if self.ui.lineEditHistoryData.tag is not None: |
72 | 83 |
self.ui.lineEditHistoryData.tag.transfer.onSizeChanged.connect(self.onBoundingBoxChanged) |
73 |
self.ui.lineEditHistoryData.setText('({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), round(matches[0].height))) |
|
84 |
self.ui.lineEditHistoryData.setText( |
|
85 |
'({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), |
|
86 |
round(matches[0].height))) |
|
74 | 87 |
self.ui.lineEditHistoryData.tag.setPen(QPen(Qt.magenta, THICKNESS, Qt.SolidLine)) |
75 | 88 |
self.parent().graphicsView.scene.addItem(self.ui.lineEditHistoryData.tag) |
76 | 89 |
self.ui.pushButtonHistoryDataArea.setStyleSheet('background-color: magenta') |
77 | 90 |
|
78 |
matches = [x for x in areas if x.name=='Drawing No'] |
|
79 |
self.ui.lineEditDrawingNo.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, matches[0].height) if len(matches) == 1 else None |
|
91 |
matches = [x for x in areas if x.name == 'Drawing No'] |
|
92 |
self.ui.lineEditDrawingNo.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, |
|
93 |
matches[0].height) if len(matches) == 1 else None |
|
80 | 94 |
if self.ui.lineEditDrawingNo.tag is not None: |
81 | 95 |
self.ui.lineEditDrawingNo.tag.transfer.onSizeChanged.connect(self.onBoundingBoxChanged) |
82 |
self.ui.lineEditDrawingNo.setText('({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), round(matches[0].height))) |
|
96 |
self.ui.lineEditDrawingNo.setText( |
|
97 |
'({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), |
|
98 |
round(matches[0].height))) |
|
83 | 99 |
self.ui.lineEditDrawingNo.tag.setPen(QPen(Qt.cyan, THICKNESS, Qt.SolidLine)) |
84 | 100 |
self.parent().graphicsView.scene.addItem(self.ui.lineEditDrawingNo.tag) |
85 | 101 |
self.ui.pushButtonDrawingNoArea.setStyleSheet('background-color: cyan') |
86 | 102 |
|
87 |
matches = [x for x in areas if x.name=='Rev No'] |
|
88 |
self.ui.lineEditRevNo.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, matches[0].height) if len(matches) == 1 else None |
|
103 |
matches = [x for x in areas if x.name == 'Rev No'] |
|
104 |
self.ui.lineEditRevNo.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, |
|
105 |
matches[0].height) if len(matches) == 1 else None |
|
89 | 106 |
if self.ui.lineEditRevNo.tag is not None: |
90 | 107 |
self.ui.lineEditRevNo.tag.transfer.onSizeChanged.connect(self.onBoundingBoxChanged) |
91 |
self.ui.lineEditRevNo.setText('({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), round(matches[0].height))) |
|
108 |
self.ui.lineEditRevNo.setText( |
|
109 |
'({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), |
|
110 |
round(matches[0].height))) |
|
92 | 111 |
self.ui.lineEditRevNo.tag.setPen(QPen(Qt.yellow, THICKNESS, Qt.SolidLine)) |
93 | 112 |
self.parent().graphicsView.scene.addItem(self.ui.lineEditRevNo.tag) |
94 | 113 |
self.ui.pushButtonRevNoArea.setStyleSheet('background-color: yellow') |
95 |
|
|
96 |
matches = [x for x in areas if x.name=='Unit'] |
|
97 |
self.ui.lineEditUnitArea.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, matches[0].height) if len(matches) == 1 else None |
|
114 |
|
|
115 |
matches = [x for x in areas if x.name == 'Unit'] |
|
116 |
self.ui.lineEditUnitArea.tag = QGraphicsBoundingBoxItem(matches[0].x, matches[0].y, matches[0].width, |
|
117 |
matches[0].height) if len(matches) == 1 else None |
|
98 | 118 |
if self.ui.lineEditUnitArea.tag is not None: |
99 | 119 |
self.ui.lineEditUnitArea.tag.transfer.onSizeChanged.connect(self.onBoundingBoxChanged) |
100 |
self.ui.lineEditUnitArea.setText('({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), round(matches[0].height))) |
|
120 |
self.ui.lineEditUnitArea.setText( |
|
121 |
'({},{}),({},{})'.format(round(matches[0].x), round(matches[0].y), round(matches[0].width), |
|
122 |
round(matches[0].height))) |
|
101 | 123 |
self.ui.lineEditUnitArea.tag.setPen(QPen(Qt.green, THICKNESS, Qt.SolidLine)) |
102 | 124 |
self.parent().graphicsView.scene.addItem(self.ui.lineEditUnitArea.tag) |
103 | 125 |
self.ui.pushButtonUnitArea.setStyleSheet('background-color: green') |
... | ... | |
105 | 127 |
# up to here |
106 | 128 |
|
107 | 129 |
titleBlockProps = docData.getTitleBlockProperties() |
108 |
self.ui.tableWidgetTitleBlockArea.setRowCount(len(titleBlockProps)) |
|
109 |
row = 0 |
|
110 |
for titleBlockProp in titleBlockProps: |
|
111 |
area = Area(titleBlockProp[0]) |
|
112 |
area.parse(titleBlockProp[2]) |
|
113 |
|
|
114 |
boundingBox = QGraphicsBoundingBoxItem(area.x, area.y, area.width, area.height) |
|
115 |
boundingBox.transfer.onSizeChanged.connect(self.onBoundingBoxChanged) |
|
116 |
boundingBox.setPen(QPen(Qt.darkCyan, THICKNESS, Qt.SolidLine)) |
|
117 |
self.parent().graphicsView.scene.addItem(boundingBox) |
|
118 |
|
|
119 |
item = QTableWidgetItem(titleBlockProp[0]) |
|
120 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 0, item) |
|
121 |
item = QTableWidgetItem(titleBlockProp[1]) |
|
122 |
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable) |
|
123 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 1, item) |
|
124 |
item = QTableWidgetItem('({},{}),({},{})'.format(area.x, area.y, area.width, area.height)) |
|
125 |
item.setFlags(Qt.ItemIsEnabled) |
|
126 |
item.tag = boundingBox |
|
127 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 2, item) |
|
128 |
item = QTableWidgetItem(titleBlockProp[3]) |
|
129 |
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable) |
|
130 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 3, item) |
|
131 |
row += 1 |
|
130 |
if titleBlockProps: |
|
131 |
self.ui.tableWidgetTitleBlockArea.setRowCount(len(titleBlockProps)) |
|
132 |
row = 0 |
|
133 |
for titleBlockProp in titleBlockProps: |
|
134 |
area = Area(titleBlockProp[0]) |
|
135 |
area.parse(titleBlockProp[2]) |
|
136 |
|
|
137 |
boundingBox = QGraphicsBoundingBoxItem(area.x, area.y, area.width, area.height) |
|
138 |
boundingBox.transfer.onSizeChanged.connect(self.onBoundingBoxChanged) |
|
139 |
boundingBox.setPen(QPen(Qt.darkCyan, THICKNESS, Qt.SolidLine)) |
|
140 |
self.parent().graphicsView.scene.addItem(boundingBox) |
|
141 |
|
|
142 |
item = QTableWidgetItem(titleBlockProp[0]) |
|
143 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 0, item) |
|
144 |
item = QTableWidgetItem(titleBlockProp[1]) |
|
145 |
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable) |
|
146 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 1, item) |
|
147 |
item = QTableWidgetItem('({},{}),({},{})'.format(area.x, area.y, area.width, area.height)) |
|
148 |
item.setFlags(Qt.ItemIsEnabled) |
|
149 |
item.tag = boundingBox |
|
150 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 2, item) |
|
151 |
item = QTableWidgetItem(titleBlockProp[3]) |
|
152 |
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable) |
|
153 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 3, item) |
|
154 |
row += 1 |
|
132 | 155 |
|
133 | 156 |
section = '{} Equipment Desc Area'.format(docData.imgName) |
134 | 157 |
configs = docData.getConfigs(section) |
... | ... | |
152 | 175 |
self.ui.tableWidgetEquipmentDescArea.setItem(row, 1, item) |
153 | 176 |
|
154 | 177 |
row += 1 |
155 |
|
|
178 |
|
|
156 | 179 |
# load typical area |
157 | 180 |
self.ui.tableWidgetTypicalArea.setHorizontalHeaderLabels(['Drawing Name', 'Name', 'Area']) |
158 | 181 |
self.ui.tableWidgetTypicalArea.hideColumn(0) |
... | ... | |
182 | 205 |
|
183 | 206 |
row += 1 |
184 | 207 |
|
185 |
if self.ui.tableWidgetEquipmentDescArea.rowCount() is not 0:
|
|
208 |
if self.ui.tableWidgetEquipmentDescArea.rowCount() is not 0: |
|
186 | 209 |
self.ui.tableWidgetEquipmentDescArea.resizeColumnsToContents() |
187 |
if self.ui.tableWidgetTitleBlockArea.rowCount() is not 0:
|
|
210 |
if self.ui.tableWidgetTitleBlockArea.rowCount() is not 0: |
|
188 | 211 |
self.ui.tableWidgetTitleBlockArea.resizeColumnsToContents() |
189 |
if self.ui.tableWidgetTypicalArea.rowCount() is not 0:
|
|
212 |
if self.ui.tableWidgetTypicalArea.rowCount() is not 0: |
|
190 | 213 |
self.ui.tableWidgetTypicalArea.resizeColumnsToContents() |
191 | 214 |
|
192 | 215 |
self.ui.pushButtonDrawingArea.clicked.connect(self.selectDrawingArea) |
... | ... | |
274 | 297 |
if self.ui.lineEditUnitArea.tag is not None: |
275 | 298 |
self.ui.lineEditUnitArea.setText('(0,0),(0,0)') |
276 | 299 |
self.ui.lineEditUnitArea.tag.setRect(0, 0, 0, 0) |
277 |
|
|
300 |
|
|
278 | 301 |
def selectDrawingArea(self): |
279 | 302 |
self._cmd.tag = self.ui.lineEditDrawing |
280 | 303 |
self.parent().graphicsView.command = self._cmd |
... | ... | |
321 | 344 |
self.removeArea(self.ui.tableWidgetTitleBlockArea.item(row, 2).tag) |
322 | 345 |
self.ui.tableWidgetTitleBlockArea.removeRow(row) |
323 | 346 |
except Exception as ex: |
324 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
347 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
348 |
sys.exc_info()[-1].tb_lineno)) |
|
325 | 349 |
|
326 | 350 |
''' |
327 | 351 |
@brief select equipment desc area |
328 | 352 |
@author humkyung |
329 | 353 |
@date 2018.06.29 |
330 | 354 |
''' |
355 |
|
|
331 | 356 |
def onSelectEquipmentDescArea(self): |
332 | 357 |
self._cmd.tag = self.ui.lineEditEquipmentDescArea |
333 | 358 |
self.parent().graphicsView.command = self._cmd |
... | ... | |
349 | 374 |
change remove process |
350 | 375 |
2018.11.20 euisung change brief remove equipment desc. area from graphicsview -> |
351 | 376 |
''' |
377 |
|
|
352 | 378 |
def removeArea(self, box): |
353 | 379 |
import re |
354 | 380 |
try: |
355 | 381 |
self.parent().graphicsView.scene.removeItem(box) |
356 | 382 |
except Exception as ex: |
357 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
383 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
384 |
sys.exc_info()[-1].tb_lineno)) |
|
358 | 385 |
|
359 | 386 |
''' |
360 | 387 |
@brief delete selected equipment desc area |
361 | 388 |
@author humkyung |
362 | 389 |
@date 2018.06.29 |
363 | 390 |
''' |
391 |
|
|
364 | 392 |
def onDeleteEquipmentDescArea(self): |
365 | 393 |
try: |
366 | 394 |
row = self.ui.tableWidgetEquipmentDescArea.currentRow() |
... | ... | |
372 | 400 |
from App import App |
373 | 401 |
from AppDocData import MessageType |
374 | 402 |
|
375 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
403 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
404 |
sys.exc_info()[-1].tb_lineno) |
|
376 | 405 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
377 | 406 |
|
378 | 407 |
def onDeleteTypicalArea(self): |
... | ... | |
391 | 420 |
from App import App |
392 | 421 |
from AppDocData import MessageType |
393 | 422 |
|
394 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
423 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
424 |
sys.exc_info()[-1].tb_lineno) |
|
395 | 425 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
396 | 426 |
|
397 | 427 |
''' |
398 | 428 |
@brief called when area is created |
399 | 429 |
@history humkyung 2018.06.29 add equipment desc. area |
400 | 430 |
''' |
401 |
def onAreaCreated(self, x, y , width, height): |
|
431 |
|
|
432 |
def onAreaCreated(self, x, y, width, height): |
|
402 | 433 |
import uuid |
403 | 434 |
THICKNESS = 5 |
404 | 435 |
|
... | ... | |
434 | 465 |
else: |
435 | 466 |
self.ui.lineEditHistoryData.tag.setRect(x, y, width, height) |
436 | 467 |
|
437 |
self.ui.lineEditHistoryData.setText('({},{}),({},{})'.format(round(x), round(y), round(width), round(height))) |
|
468 |
self.ui.lineEditHistoryData.setText( |
|
469 |
'({},{}),({},{})'.format(round(x), round(y), round(width), round(height))) |
|
438 | 470 |
elif self._cmd.tag is self.ui.lineEditUnitArea: |
439 | 471 |
if self.ui.lineEditUnitArea.tag is None: |
440 | 472 |
item = QGraphicsBoundingBoxItem(x, y, width, height) |
... | ... | |
510 | 542 |
item = QTableWidgetItem(str(uuid.uuid4())) |
511 | 543 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 0, item) |
512 | 544 |
item = QTableWidgetItem() |
513 |
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable)
|
|
545 |
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable)
|
|
514 | 546 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 1, item) |
515 | 547 |
item = QTableWidgetItem(strArea) |
516 | 548 |
item.setFlags(Qt.ItemIsEnabled) |
517 | 549 |
item.tag = boundingBox |
518 | 550 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 2, item) |
519 | 551 |
item = QTableWidgetItem() |
520 |
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable)
|
|
552 |
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable)
|
|
521 | 553 |
self.ui.tableWidgetTitleBlockArea.setItem(row, 3, item) |
522 | 554 |
self.ui.tableWidgetTitleBlockArea.resizeColumnsToContents() |
523 | 555 |
|
... | ... | |
538 | 570 |
item = QTableWidgetItem(docData.imgName) |
539 | 571 |
self.ui.tableWidgetTypicalArea.setItem(row, 0, item) |
540 | 572 |
item = QTableWidgetItem(str(uuid.uuid4())) |
541 |
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable)
|
|
573 |
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable)
|
|
542 | 574 |
self.ui.tableWidgetTypicalArea.setItem(row, 1, item) |
543 | 575 |
strArea = '({},{}),({},{})'.format(x, y, width, height) |
544 | 576 |
item = QTableWidgetItem(strArea) |
... | ... | |
555 | 587 |
@author humkyung |
556 | 588 |
@date 2018.08.30 |
557 | 589 |
''' |
590 |
|
|
558 | 591 |
def onBoundingBoxChanged(self, boundingBox): |
559 | 592 |
x = boundingBox.rect().left() |
560 | 593 |
y = boundingBox.rect().top() |
... | ... | |
565 | 598 |
elif boundingBox is self.ui.lineEditNote.tag: |
566 | 599 |
self.ui.lineEditNote.setText('({},{}),({},{})'.format(round(x), round(y), round(width), round(height))) |
567 | 600 |
elif boundingBox is self.ui.lineEditHistoryData.tag: |
568 |
self.ui.lineEditHistoryData.setText('({},{}),({},{})'.format(round(x), round(y), round(width), round(height))) |
|
601 |
self.ui.lineEditHistoryData.setText( |
|
602 |
'({},{}),({},{})'.format(round(x), round(y), round(width), round(height))) |
|
569 | 603 |
elif boundingBox is self.ui.lineEditUnitArea.tag: |
570 | 604 |
self.ui.lineEditUnitArea.setText('({},{}),({},{})'.format(round(x), round(y), round(width), round(height))) |
571 | 605 |
elif boundingBox is self.ui.lineEditDrawingNo.tag: |
... | ... | |
595 | 629 |
''' |
596 | 630 |
@brief accept dialog |
597 | 631 |
''' |
632 |
|
|
598 | 633 |
def accept(self): |
599 | 634 |
try: |
600 | 635 |
areas = [] |
... | ... | |
602 | 637 |
if self.ui.lineEditDrawing.tag is not None: |
603 | 638 |
area = Area('Drawing') |
604 | 639 |
area.x = self.ui.lineEditDrawing.tag.rect().left() |
605 |
area.y = self.ui.lineEditDrawing.tag.rect().top()
|
|
640 |
area.y = self.ui.lineEditDrawing.tag.rect().top() |
|
606 | 641 |
area.width = self.ui.lineEditDrawing.tag.rect().width() |
607 | 642 |
area.height = self.ui.lineEditDrawing.tag.rect().height() |
608 | 643 |
areas.append(area) |
609 | 644 |
self.parent().graphicsView.scene.removeItem(self.ui.lineEditDrawing.tag) |
610 |
|
|
645 |
|
|
611 | 646 |
if self.ui.lineEditNote.tag is not None: |
612 | 647 |
area = Area('Note') |
613 | 648 |
area.x = self.ui.lineEditNote.tag.rect().left() |
614 |
area.y = self.ui.lineEditNote.tag.rect().top()
|
|
649 |
area.y = self.ui.lineEditNote.tag.rect().top() |
|
615 | 650 |
area.width = self.ui.lineEditNote.tag.rect().width() |
616 | 651 |
area.height = self.ui.lineEditNote.tag.rect().height() |
617 | 652 |
areas.append(area) |
... | ... | |
620 | 655 |
if self.ui.lineEditHistoryData.tag is not None: |
621 | 656 |
area = Area('History Data') |
622 | 657 |
area.x = self.ui.lineEditHistoryData.tag.rect().left() |
623 |
area.y = self.ui.lineEditHistoryData.tag.rect().top()
|
|
658 |
area.y = self.ui.lineEditHistoryData.tag.rect().top() |
|
624 | 659 |
area.width = self.ui.lineEditHistoryData.tag.rect().width() |
625 | 660 |
area.height = self.ui.lineEditHistoryData.tag.rect().height() |
626 | 661 |
areas.append(area) |
... | ... | |
629 | 664 |
if self.ui.lineEditDrawingNo.tag is not None: |
630 | 665 |
area = Area('Drawing No') |
631 | 666 |
area.x = self.ui.lineEditDrawingNo.tag.rect().left() |
632 |
area.y = self.ui.lineEditDrawingNo.tag.rect().top()
|
|
667 |
area.y = self.ui.lineEditDrawingNo.tag.rect().top() |
|
633 | 668 |
area.width = self.ui.lineEditDrawingNo.tag.rect().width() |
634 | 669 |
area.height = self.ui.lineEditDrawingNo.tag.rect().height() |
635 | 670 |
areas.append(area) |
... | ... | |
638 | 673 |
if self.ui.lineEditUnitArea.tag is not None: |
639 | 674 |
area = Area('Unit') |
640 | 675 |
area.x = self.ui.lineEditUnitArea.tag.rect().left() |
641 |
area.y = self.ui.lineEditUnitArea.tag.rect().top()
|
|
676 |
area.y = self.ui.lineEditUnitArea.tag.rect().top() |
|
642 | 677 |
area.width = self.ui.lineEditUnitArea.tag.rect().width() |
643 | 678 |
area.height = self.ui.lineEditUnitArea.tag.rect().height() |
644 | 679 |
areas.append(area) |
... | ... | |
647 | 682 |
if self.ui.lineEditRevNo.tag is not None: |
648 | 683 |
area = Area('Rev No') |
649 | 684 |
area.x = self.ui.lineEditRevNo.tag.rect().left() |
650 |
area.y = self.ui.lineEditRevNo.tag.rect().top()
|
|
685 |
area.y = self.ui.lineEditRevNo.tag.rect().top() |
|
651 | 686 |
area.width = self.ui.lineEditRevNo.tag.rect().width() |
652 | 687 |
area.height = self.ui.lineEditRevNo.tag.rect().height() |
653 | 688 |
areas.append(area) |
... | ... | |
673 | 708 |
titleBlockProps = [] |
674 | 709 |
for row in range(self.ui.tableWidgetTitleBlockArea.rowCount()): |
675 | 710 |
if self.ui.tableWidgetTitleBlockArea.item(row, 1).text() != '': |
676 |
titleBlockProps.append([self.ui.tableWidgetTitleBlockArea.item(row, 0).text(), self.ui.tableWidgetTitleBlockArea.item(row, 1).text(), self.ui.tableWidgetTitleBlockArea.item(row, 2).text(), self.ui.tableWidgetTitleBlockArea.item(row, 3).text()]) |
|
711 |
titleBlockProps.append([self.ui.tableWidgetTitleBlockArea.item(row, 0).text(), |
|
712 |
self.ui.tableWidgetTitleBlockArea.item(row, 1).text(), |
|
713 |
self.ui.tableWidgetTitleBlockArea.item(row, 2).text(), |
|
714 |
self.ui.tableWidgetTitleBlockArea.item(row, 3).text()]) |
|
677 | 715 |
|
678 | 716 |
self.removeArea(self.ui.tableWidgetTitleBlockArea.item(row, 2).tag) |
679 | 717 |
docData.updateTitleBlockProperties(titleBlockProps) |
... | ... | |
710 | 748 |
''' |
711 | 749 |
@brief reject dialog |
712 | 750 |
''' |
751 |
|
|
713 | 752 |
def reject(self): |
714 | 753 |
if self.ui.lineEditDrawing.tag is not None: |
715 | 754 |
self.parent().graphicsView.scene.removeItem(self.ui.lineEditDrawing.tag) |
716 |
|
|
755 |
|
|
717 | 756 |
if self.ui.lineEditNote.tag is not None: |
718 | 757 |
self.parent().graphicsView.scene.removeItem(self.ui.lineEditNote.tag) |
719 | 758 |
|
DTI_PID/DTI_PID/LineDetector.py | ||
---|---|---|
4 | 4 |
import math |
5 | 5 |
import shapely |
6 | 6 |
|
7 |
__author__ = "humkyung <humkyung.doftech.co.kr>" |
|
8 |
__version__ = '1.0.0' |
|
7 | 9 |
|
8 |
class LineDetector(): |
|
10 |
|
|
11 |
class LineDetector: |
|
9 | 12 |
def __init__(self, image): |
10 | 13 |
try: |
11 | 14 |
thresh = 127 |
... | ... | |
74 | 77 |
qy = origin[1] + math.sin(angle) * dx + math.cos(angle) * dy |
75 | 78 |
return [qx, qy] |
76 | 79 |
|
77 |
''' |
|
78 |
@brief check if given two lines are connected |
|
79 |
@author humkyung |
|
80 |
@date 2018.04.11 |
|
81 |
''' |
|
82 |
|
|
83 |
def isConnected(self, lhs, rhs, toler=0): |
|
80 |
def is_connected(self, lhs, rhs, toler=0): |
|
81 |
"""check if given two lines are connected""" |
|
84 | 82 |
length = [] |
85 | 83 |
|
86 | 84 |
try: |
... | ... | |
100 | 98 |
matches = [len for len in length if len < toler] |
101 | 99 |
# up to here |
102 | 100 |
|
103 |
return (len(matches) == 1)
|
|
101 |
return len(matches) == 1
|
|
104 | 102 |
except Exception as ex: |
105 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
106 |
sys.exc_info()[-1].tb_lineno))
|
|
103 |
from App import App
|
|
104 |
from AppDocData import MessageType
|
|
107 | 105 |
|
108 |
return False |
|
106 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
107 |
sys.exc_info()[-1].tb_lineno) |
|
108 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
109 | 109 |
|
110 |
""" |
|
111 |
@brief check if given two lines lie on one line and share one point |
|
112 |
@author humkyung |
|
113 |
@date 2018.04.11 |
|
114 |
""" |
|
110 |
return False |
|
115 | 111 |
|
116 |
def isCollinear(self, lhs, rhs, toler): |
|
112 |
def is_collinear(self, lhs, rhs, toler): |
|
113 |
"""check if given two lines are connected and collinear""" |
|
117 | 114 |
try: |
118 |
# print(lhs) |
|
119 |
# print(rhs) |
|
120 |
if self.isConnected(lhs, rhs, toler): |
|
121 |
dx1 = lhs[1][0] - lhs[0][0] |
|
122 |
dy1 = lhs[1][1] - lhs[0][1] |
|
123 |
length = math.sqrt(dx1 * dx1 + dy1 * dy1) |
|
124 |
dx1 /= length |
|
125 |
dy1 /= length |
|
126 |
dx2 = rhs[1][0] - rhs[0][0] |
|
127 |
dy2 = rhs[1][1] - rhs[0][1] |
|
128 |
length = math.sqrt(dx2 * dx2 + dy2 * dy2) |
|
129 |
dx2 /= length |
|
130 |
dy2 /= length |
|
131 |
|
|
132 |
dx = math.fabs(dx1) - math.fabs(dx2) |
|
133 |
dy = math.fabs(dy1) - math.fabs(dy2) |
|
134 |
|
|
135 |
return (math.sqrt(dx * dx + dy * dy) < 0.00001) |
|
115 |
if self.is_connected(lhs, rhs, toler): |
|
116 |
dx = lhs[1][0] - lhs[0][0] |
|
117 |
dy = lhs[1][1] - lhs[0][1] |
|
118 |
length = math.sqrt(dx * dx + dy * dy) |
|
119 |
vec1 = np.array([(lhs[1][0] - lhs[0][0]) / length, (lhs[1][1] - lhs[0][1]) / length, 0]) |
|
120 |
|
|
121 |
dx = rhs[1][0] - rhs[0][0] |
|
122 |
dy = rhs[1][1] - rhs[0][1] |
|
123 |
length = math.sqrt(dx * dx + dy * dy) |
|
124 |
vec2 = np.array([(rhs[1][0] - rhs[0][0]) / length, (rhs[1][1] - rhs[0][1]) / length, 0]) |
|
125 |
|
|
126 |
area = np.cross(vec1, vec2) |
|
127 |
magnitude = math.sqrt(area[0] * area[0] + area[1] * area[1] + area[2] * area[2]) |
|
128 |
return magnitude < 0.00001 |
|
136 | 129 |
except Exception as ex: |
137 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
138 |
sys.exc_info()[-1].tb_lineno)) |
|
130 |
from App import App |
|
131 |
from AppDocData import MessageType |
|
132 |
|
|
133 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
134 |
sys.exc_info()[-1].tb_lineno) |
|
135 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
139 | 136 |
|
140 | 137 |
return False |
141 | 138 |
|
... | ... | |
146 | 143 |
@history 2018.05.16 Jeongwoo Connect Lines with long distance points |
147 | 144 |
''' |
148 | 145 |
|
149 |
def connectLines(self, lines, toler):
|
|
146 |
def connect_lines(self, lines, toler):
|
|
150 | 147 |
res = [] |
151 | 148 |
|
152 | 149 |
pts = [] |
153 |
# print(lines) |
|
154 |
maxthickness = 0 |
|
150 |
max_thickness = 0 |
|
155 | 151 |
for line in lines: |
156 | 152 |
pts.append(line[0]) |
157 | 153 |
pts.append(line[1]) |
158 |
maxthickness = line[2] if maxthickness < line[2] else maxthickness
|
|
154 |
max_thickness = line[2] if max_thickness < line[2] else max_thickness
|
|
159 | 155 |
|
160 | 156 |
maxLength = None |
161 | 157 |
for lpt in pts: |
... | ... | |
169 | 165 |
res.clear() |
170 | 166 |
res.append(lpt) |
171 | 167 |
res.append(rpt) |
172 |
res.append(maxthickness) |
|
173 |
# print(res) |
|
174 |
return res |
|
168 |
res.append(max_thickness) |
|
175 | 169 |
|
176 |
''' |
|
177 |
@brief adjust start point |
|
178 |
@author humkyung |
|
179 |
@date 2018.06.21 |
|
180 |
@history humkyung 2018.07.31 return -1 thickness tuple if near point is not black |
|
181 |
''' |
|
170 |
return res |
|
182 | 171 |
|
183 |
def adjustStartPoint(self, pt, dir): |
|
172 |
def adjust_start_point(self, pt, dir): |
|
173 |
"""adjust start point of line and then return start point and thickness of line |
|
174 |
return -1 for thickness if fail to calculate thickness |
|
175 |
""" |
|
184 | 176 |
from AppDocData import AppDocData |
185 | 177 |
docData = AppDocData.instance() |
186 | 178 |
windowSize = docData.getSlidingWindowSize() |
... | ... | |
195 | 187 |
else: |
196 | 188 |
found = False |
197 | 189 |
for step in [1, 2, -1, -2]: |
198 |
if black == self._image[pt[1] + round(dir[1] * windowSize[1] + norm[1] * step), pt[0] + round(
|
|
199 |
dir[0] * windowSize[1] + norm[0] * step)]: |
|
190 |
if black == self._image[pt[1] + round(dir[1] * windowSize[1] + norm[1] * step), |
|
191 |
pt[0] + round(dir[0] * windowSize[1] + norm[0] * step)]:
|
|
200 | 192 |
_pt = [pt[0] + round(dir[0] * windowSize[1] + norm[0] * step), |
201 | 193 |
pt[1] + round(dir[1] * windowSize[1] + norm[1] * step)] |
202 | 194 |
found = True |
203 | 195 |
break |
204 | 196 |
|
205 |
if not found: return (pt, -1)
|
|
197 |
if not found: return pt, -1
|
|
206 | 198 |
|
207 | 199 |
color = black |
208 | 200 |
lhs = [_pt[0], _pt[1]] |
... | ... | |
224 | 216 |
|
225 | 217 |
size = lhscount + rhscount |
226 | 218 |
offset = round((lhscount - rhscount) * 0.5) if size < windowSize[1] else 0 |
227 |
# print(size) |
|
228 | 219 |
return ( |
229 | 220 |
[pt[0] + norm[0] * offset, pt[1] + norm[1] * offset], |
230 |
size) # if size > windowSize[1] else windowSize[1]) |
|
221 |
size if size < windowSize[1] else windowSize[1]) # if size > windowSize[1] else windowSize[1])
|
|
231 | 222 |
except Exception as ex: |
232 | 223 |
from App import App |
233 | 224 |
from AppDocData import MessageType |
... | ... | |
235 | 226 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
236 | 227 |
sys.exc_info()[-1].tb_lineno) |
237 | 228 |
App.mainWnd().addMessage.emit(MessageType.Error, message) if not 'is out of bounds' in message else '' |
238 |
return (pt, -1)
|
|
229 |
return pt, -1
|
|
239 | 230 |
|
240 |
return (pt, windowSize[1])
|
|
231 |
return pt, windowSize[1]
|
|
241 | 232 |
|
242 | 233 |
''' |
243 | 234 |
@brief symbol을 기준으로 양쪽으로 이미지에서 직선을 검출한다. |
... | ... | |
256 | 247 |
pool = [] |
257 | 248 |
if (0 == symbol.angle) or (1.57 == symbol.angle) or (3.14 == symbol.angle) or (4.71 == symbol.angle): |
258 | 249 |
for connector in symbol.connectors: |
259 |
## get direction of connector
|
|
250 |
# get direction of connector |
|
260 | 251 |
direction = connector.dir() |
261 | 252 |
if direction is None: |
262 | 253 |
dx = connector.sceneConnectPoint[0] - symbol.origin[0] |
263 | 254 |
dy = connector.sceneConnectPoint[1] - symbol.origin[1] |
264 | 255 |
else: |
265 | 256 |
dx, dy = direction[0], direction[1] |
266 |
# print('dx : ' + str(dx) + ', dy : ' + str(dy)) |
|
267 |
## up to here |
|
257 |
# up to here |
|
268 | 258 |
|
269 | 259 |
length = math.sqrt(dx * dx + dy * dy) |
270 | 260 |
if length > 0: |
... | ... | |
275 | 265 |
dir = [0, 1 if dy > 0 else -1] |
276 | 266 |
pt = [round(connector.sceneConnectPoint[0] - offsetX), |
277 | 267 |
round(connector.sceneConnectPoint[1] - offsetY)] |
278 |
pt, thickness = self.adjustStartPoint(pt, dir) |
|
279 |
if thickness != -1: pool.append([dir, pt, thickness, True if not pool else False]) |
|
268 |
pt, thickness = self.adjust_start_point(pt, dir) |
|
269 |
if thickness != -1: |
|
270 |
pool.append([dir, pt, thickness, True if not pool else False]) |
|
280 | 271 |
# print("v") |
281 | 272 |
elif abs(dy) < 0.1: # horizontal line |
282 | 273 |
dir = [1 if dx > 0 else -1, 0] |
283 | 274 |
pt = [round(connector.sceneConnectPoint[0] - offsetX), |
284 | 275 |
round(connector.sceneConnectPoint[1] - offsetY)] |
285 |
pt, thickness = self.adjustStartPoint(pt, dir) |
|
286 |
if thickness != -1: pool.append([dir, pt, thickness, True if not pool else False]) |
|
287 |
# print("h") |
|
288 |
# print(thickness) |
|
289 |
# print(pool) |
|
276 |
pt, thickness = self.adjust_start_point(pt, dir) |
|
277 |
if thickness != -1: |
|
278 |
pool.append([dir, pt, thickness, True if not pool else False]) |
|
290 | 279 |
|
291 |
# print(len(pool)) |
|
292 | 280 |
while len(pool) > 0: |
293 | 281 |
dir, pt, thickness, forward = pool.pop() |
294 | 282 |
line = self.detectLine(pt, dir, thickness, forward) |
... | ... | |
298 | 286 |
res.append(line if forward else [line[1], line[0], thickness]) |
299 | 287 |
if ([1, 0] == dir) or ([-1, 0] == dir): # turn up/down |
300 | 288 |
connectedPt = [line[1][0], pt[1]] |
301 |
pt, thickness = self.adjustStartPoint(connectedPt, [0, 1]) |
|
302 |
if thickness != -1: pool.append([[0, 1], pt, thickness, forward]) |
|
303 |
pt, thickness = self.adjustStartPoint(connectedPt, [0, -1]) |
|
304 |
if thickness != -1: pool.append([[0, -1], pt, thickness, not forward]) |
|
289 |
pt, thickness = self.adjust_start_point(connectedPt, [0, 1]) |
|
290 |
if thickness != -1: |
|
291 |
pool.append([[0, 1], pt, thickness, forward]) |
|
292 |
pt, thickness = self.adjust_start_point(connectedPt, [0, -1]) |
|
293 |
if thickness != -1: |
|
294 |
pool.append([[0, -1], pt, thickness, not forward]) |
|
305 | 295 |
elif ([0, 1] == dir) or ([0, -1] == dir): # turn left/right |
306 | 296 |
connectedPt = [pt[0], line[1][1]] |
307 |
pt, thickness = self.adjustStartPoint(connectedPt, [1, 0]) |
|
308 |
if thickness != -1: pool.append([[1, 0], pt, thickness, forward]) |
|
309 |
pt, thickness = self.adjustStartPoint(connectedPt, [-1, 0]) |
|
310 |
if thickness != -1: pool.append([[-1, 0], pt, thickness, not forward]) |
|
311 |
# print(res) |
|
297 |
pt, thickness = self.adjust_start_point(connectedPt, [1, 0]) |
|
298 |
if thickness != -1: |
|
299 |
pool.append([[1, 0], pt, thickness, forward]) |
|
300 |
pt, thickness = self.adjust_start_point(connectedPt, [-1, 0]) |
|
301 |
if thickness != -1: |
|
302 |
pool.append([[-1, 0], pt, thickness, not forward]) |
|
303 |
|
|
312 | 304 |
return res |
313 | 305 |
except Exception as ex: |
314 | 306 |
from App import App |
... | ... | |
318 | 310 |
sys.exc_info()[-1].tb_lineno) |
319 | 311 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
320 | 312 |
|
321 |
''' |
|
322 |
@breif merge lines(1.connect collinear lines 2.connect lines) |
|
323 |
@author humkyung |
|
324 |
@date 2018.04.11 |
|
325 |
@history humkyung 2018.04.12 continue loop if line is not in connectedLines |
|
326 |
Jeongwoo 2018.05.16 Make comments if-statement |
|
327 |
''' |
|
328 |
|
|
329 | 313 |
def mergeLines(self, connectedLines, toler): |
314 |
"""merge lines(1.connect collinear lines 2.connect lines)""" |
|
330 | 315 |
try: |
331 |
for line in connectedLines[:]: |
|
332 |
if line not in connectedLines: continue |
|
333 |
matches = [param for param in connectedLines if |
|
334 |
(line != param) and self.isCollinear(line, param, toler)] |
|
316 |
for line in connectedLines: |
|
317 |
matches = [param for param in connectedLines |
|
318 |
if (line != param) and self.is_collinear(line, param, toler)] |
|
335 | 319 |
if len(matches) > 0: |
336 |
# print(len(matches)) |
|
337 | 320 |
matches.append(line) |
338 |
# if len(matches) > 2: matches = matches[0:2] # pick last two objects |
|
339 |
mergedLine = self.connectLines(matches, toler) |
|
321 |
mergedLine = self.connect_lines(matches, toler) |
|
340 | 322 |
if mergedLine is not None and len(mergedLine) > 0: |
341 | 323 |
connectedLines.append(mergedLine) |
342 |
for match in matches: connectedLines.remove(match) |
|
324 |
for match in matches: |
|
325 |
connectedLines.remove(match) |
|
343 | 326 |
except Exception as ex: |
344 | 327 |
from App import App |
345 | 328 |
from AppDocData import MessageType |
346 | 329 |
|
347 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
330 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
348 | 331 |
sys.exc_info()[-1].tb_lineno) |
349 | 332 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
350 | 333 |
|
... | ... | |
533 | 516 |
xHalf = round(windowSize[0] * 0.5) |
534 | 517 |
yHalf = round(windowSize[1] * 0.5) |
535 | 518 |
|
536 |
if ([1, 0] == dir):
|
|
519 |
if [1, 0] == dir:
|
|
537 | 520 |
image = self._image[(pt[1] - yHalf):(pt[1] + yHalf), pt[0]:self.width] |
538 | 521 |
imgWidth, imgHeight = image.shape[::-1] |
539 | 522 |
index = 0 |
... | ... | |
545 | 528 |
# self._image[(pt[1]-yHalf):(pt[1]+yHalf), pt[0]:(pt[0]+i)] = white |
546 | 529 |
cv2.line(self._image, (pt[0], pt[1]), (pt[0] + i, pt[1]), 255, thickness) |
547 | 530 |
return [[pt[0], pt[1]], [pt[0] + i - round(thickness * 0.5), pt[1]]] |
548 |
elif ([-1, 0] == dir):
|
|
531 |
elif [-1, 0] == dir:
|
|
549 | 532 |
image = self._image[(pt[1] - yHalf):(pt[1] + yHalf), 0:pt[0]] |
550 | 533 |
imgWidth, imgHeight = image.shape[::-1] |
551 | 534 |
index = 0 |
... | ... | |
557 | 540 |
# self._image[int(pt[1]-yHalf):int(pt[1]+yHalf), (i+windowSize[0]+yHalf):pt[0]] = white |
558 | 541 |
cv2.line(self._image, (i + windowSize[0], pt[1]), (pt[0], pt[1]), 255, thickness) |
559 | 542 |
return [[pt[0], pt[1]], [i + windowSize[0] + round(thickness * 0.5), pt[1]]] |
560 |
elif ([0, 1] == dir):
|
|
543 |
elif [0, 1] == dir:
|
|
561 | 544 |
windowSize.reverse() |
562 | 545 |
xHalf = round(windowSize[0] * 0.5) |
563 | 546 |
yHalf = round(windowSize[1] * 0.5) |
... | ... | |
573 | 556 |
# self._image[(pt[1]):(pt[1]+i), (pt[0]-xHalf):(pt[0]+xHalf)] = white |
574 | 557 |
cv2.line(self._image, (pt[0], pt[1]), (pt[0], pt[1] + i), 255, thickness) |
575 | 558 |
return [[pt[0], pt[1]], [pt[0], pt[1] + i - round(thickness * 0.5)]] |
576 |
elif ([0, -1] == dir):
|
|
559 |
elif [0, -1] == dir:
|
|
577 | 560 |
windowSize.reverse() |
578 | 561 |
xHalf = round(windowSize[0] * 0.5) |
579 | 562 |
yHalf = round(windowSize[1] * 0.5) |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
2436 | 2436 |
|
2437 | 2437 |
diffFilePath = os.path.join(project.getTempPath(), "DIFF_" + os.path.basename(path)) |
2438 | 2438 |
if os.path.isfile(diffFilePath): |
2439 |
imgDiff = cv2.threshold(cv2.cvtColor(cv2.imread(diffFilePath, 1), cv2.COLOR_BGR2GRAY), 127, 255,
|
|
2440 |
cv2.THRESH_BINARY)[1] |
|
2439 |
imgDiff = cv2.threshold(cv2.cvtColor(cv2.imread(diffFilePath, 1), cv2.COLOR_BGR2GRAY), 0, 255,
|
|
2440 |
cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
|
|
2441 | 2441 |
|
2442 |
## remove line
|
|
2442 |
# remove line from image
|
|
2443 | 2443 |
lines = docData.lines |
2444 | 2444 |
for line in lines: |
2445 |
line.drawToImage(imgDiff, 255, thickness) if line.thickness is None else line.drawToImage(imgDiff, |
|
2446 |
255, |
|
2447 |
line.thickness) |
|
2445 |
line.drawToImage(imgDiff, 255, thickness) if line.thickness is None else \ |
|
2446 |
line.drawToImage(imgDiff, 255, line.thickness) |
|
2448 | 2447 |
cv2.imwrite(diffFilePath, imgDiff) |
2449 |
## up to here
|
|
2448 |
# up to here |
|
2450 | 2449 |
|
2451 | 2450 |
imgNot = np.ones(imgDiff.shape, np.uint8) |
2452 | 2451 |
cv2.bitwise_not(imgDiff, imgNot) |
DTI_PID/DTI_PID/QtImageViewerScene.py | ||
---|---|---|
20 | 20 |
__version__ = '1.0.0' |
21 | 21 |
|
22 | 22 |
|
23 |
class QtImageViewerScene(QGraphicsScene, SingletonInstance):
|
|
23 |
class QtImageViewerScene(QGraphicsScene): |
|
24 | 24 |
""" This is image viewer scene class """ |
25 | 25 |
contents_changed = pyqtSignal() |
26 | 26 |
|
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
116 | 116 |
''' |
117 | 117 |
|
118 | 118 |
@staticmethod |
119 |
def removeSmallObjects(image):
|
|
119 |
def remove_small_objects(image):
|
|
120 | 120 |
try: |
121 |
appDocData = AppDocData.instance()
|
|
122 |
configs = appDocData.getConfigs('Small Object Size', 'Min Area')
|
|
121 |
app_doc_data = AppDocData.instance()
|
|
122 |
configs = app_doc_data.getConfigs('Small Object Size', 'Min Area')
|
|
123 | 123 |
minArea = int(configs[0].value) if 1 == len(configs) else 20 |
124 |
configs = appDocData.getConfigs('Small Object Size', 'Max Area')
|
|
124 |
configs = app_doc_data.getConfigs('Small Object Size', 'Max Area')
|
|
125 | 125 |
maxArea = int(configs[0].value) if 1 == len(configs) else 50 |
126 | 126 |
|
127 | 127 |
contours, _ = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
128 | 128 |
selectedContours = [] |
129 | 129 |
for contour in contours: |
130 | 130 |
area = cv2.contourArea(contour) |
131 |
if area > minArea and area < maxArea: selectedContours.append(contour) |
|
132 |
contourImage = cv2.drawContours(image, selectedContours, -1, (255, 255, 255), |
|
133 |
-1); # draw contour with white color |
|
131 |
if minArea < area < maxArea: |
|
132 |
selectedContours.append(contour) |
|
133 |
|
|
134 |
# draw contour with white color |
|
135 |
contourImage = cv2.drawContours(image, selectedContours, -1, (255, 255, 255), -1) |
|
134 | 136 |
except Exception as ex: |
135 | 137 |
from App import App |
136 | 138 |
|
... | ... | |
541 | 543 |
if isLineChecked: |
542 | 544 |
Worker.recognizeLine(mainRes, listWidget, worker.graphicsView, worker, batch) |
543 | 545 |
else: |
544 |
lineItems = [item for item in worker.graphicsView.scene.items() if
|
|
545 |
issubclass(type(item), QEngineeringLineItem)] |
|
546 |
lineItems = [item for item in worker.graphicsView.scene.items() |
|
547 |
if issubclass(type(item), QEngineeringLineItem)]
|
|
546 | 548 |
app_doc_data.lines.extend(lineItems) |
547 | 549 |
app_doc_data.allItems.extend(lineItems) |
548 | 550 |
|
... | ... | |
651 | 653 |
from LineDetector import LineDetector |
652 | 654 |
|
653 | 655 |
try: |
654 |
listWidget.addItem('Starting line recognization')
|
|
656 |
listWidget.addItem('Starting line recognition') |
|
655 | 657 |
worker.displayTitle.emit(worker.tr('Detecting lines...')) |
656 | 658 |
|
657 | 659 |
app_doc_data = AppDocData.instance() |
660 |
project = app_doc_data.getCurrentProject() |
|
658 | 661 |
# remove already existing line and flow arrow item |
659 | 662 |
if not batch: |
660 | 663 |
items = [item for item in worker.graphicsView.scene.items() if (type(item) is QEngineeringLineItem)] |
... | ... | |
667 | 670 |
connectedLines = [] |
668 | 671 |
|
669 | 672 |
area = app_doc_data.getArea('Drawing') |
670 |
area.img = worker.removeSmallObjects(area.img)
|
|
673 |
area.img = worker.remove_small_objects(area.img)
|
|
671 | 674 |
detector = LineDetector(area.img) |
672 | 675 |
|
673 | 676 |
symbols = [] |
... | ... | |
693 | 696 |
detector.mergeLines(connectedLines, toler=toler) |
694 | 697 |
|
695 | 698 |
for pts in connectedLines: |
696 |
processLine = QEngineeringLineItem(
|
|
699 |
line = QEngineeringLineItem(
|
|
697 | 700 |
vertices=[(area.x + param[0], area.y + param[1]) for param in pts[:-1]], thickness=pts[2]) |
698 |
processLine.area = 'Drawing' |
|
699 |
|
|
700 |
app_doc_data.lines.append(processLine) |
|
701 |
app_doc_data.allItems.append(processLine) |
|
702 |
|
|
703 |
""" |
|
704 |
for pts in connectedLines: |
|
705 |
processLine = QEngineeringLineItem(vertices=[(area.x + param[0], area.y + param[1]) for param in pts[:-1]], thickness=pts[2]) |
|
706 |
processLine.area = 'Drawing' |
|
707 |
|
|
708 |
appDocData.lines.append(processLine) |
|
709 |
appDocData.allItems.append(processLine) |
|
701 |
line.area = 'Drawing' |
|
710 | 702 |
|
711 |
if processLine.length() > 100: # TODO: check critical length |
|
712 |
processLine.addFlowArrow() |
|
713 |
""" |
|
703 |
app_doc_data.lines.append(line) |
|
704 |
app_doc_data.allItems.append(line) |
|
714 | 705 |
except Exception as ex: |
715 | 706 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
716 | 707 |
sys.exc_info()[-1].tb_lineno) |
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py | ||
---|---|---|
1295 | 1295 |
if self.isSelected(): |
1296 | 1296 |
self.drawFocusRect(painter) |
1297 | 1297 |
|
1298 |
''' |
|
1299 |
@brief draw self to given image |
|
1300 |
@author humkyung |
|
1301 |
@date 2018.06.21 |
|
1302 |
''' |
|
1303 |
|
|
1304 | 1298 |
def drawToImage(self, img, color, thickness): |
1299 |
"""write recognized lines to image""" |
|
1305 | 1300 |
try: |
1306 |
# write recognized lines to image |
|
1307 | 1301 |
ptStart = self.startPoint() |
1308 | 1302 |
ptEnd = self.endPoint() |
1309 | 1303 |
cv2.line(img, (round(ptStart[0]), round(ptStart[1])), (round(ptEnd[0]), round(ptEnd[1])), color, thickness) |
1310 | 1304 |
# up to here |
1311 |
|
|
1312 |
# if self.flowMark is not None: |
|
1313 |
# x, y, w, h = self.flowMark[0] |
|
1314 |
# img[y:(y+h), x:(x+w)] = color |
|
1315 | 1305 |
except Exception as ex: |
1316 | 1306 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1317 | 1307 |
sys.exc_info()[-1].tb_lineno)) |
DTI_PID/DTI_PID/tesseract_ocr_module.py | ||
---|---|---|
154 | 154 |
for merged_box in merged_boxes: |
155 | 155 |
bottom = merged_box.bottom() |
156 | 156 |
top = merged_box.top() |
157 |
if (abs(miny - top) <= 4 or abs(maxy - bottom) <= 4) or (miny <= top and maxy >= bottom) or (
|
|
158 |
miny >= top and maxy <= bottom): |
|
157 |
if (abs(miny - top) <= 4 or abs(maxy - bottom) <= 4) or (miny <= top and maxy >= bottom) or \
|
|
158 |
(miny >= top and maxy <= bottom):
|
|
159 | 159 |
find_box = merged_box |
160 | 160 |
|
161 | 161 |
if find_box: |
... | ... | |
216 | 216 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
217 | 217 |
return None |
218 | 218 |
|
219 |
|
|
220 |
def removeTextFromNpArray(img, flag=FLAG_IMAGE_TO_BOXES, conf=DEFAULT_CONF): |
|
221 |
retImg = img.copy() |
|
222 |
|
|
223 |
for i in range(4): |
|
224 |
if flag == FLAG_IMAGE_TO_BOXES: |
|
225 |
retImg = imageToBoxes(retImg, conf) |
|
226 |
elif flag == FLAG_IMAGE_TO_DATA: |
|
227 |
retImg = imageToData(retImg, conf) |
|
228 |
elif flag == FLAG_IMAGE_TO_STRING: |
|
229 |
retImg = imageToString(retImg, conf) |
|
230 |
retImg = cv2.rotate(retImg, cv2.ROTATE_90_CLOCKWISE) |
|
231 |
|
|
232 |
return retImg |
|
233 |
|
|
234 |
|
|
235 |
''' |
|
236 |
@history 2018.06.14 Jeongwoo Add try-except. If exception occurred, return None |
|
237 |
''' |
|
238 |
|
|
239 |
|
|
240 |
def imageToBoxes(img, conf): |
|
241 |
docData = AppDocData.instance() |
|
242 |
configs = docData.getConfigs('Text Size', 'Min Text Size') |
|
243 |
minSize = int(configs[0].value) if 1 == len(configs) else self.ui.minTextSizeSpinBox.setValue(30) |
|
244 |
configs = docData.getConfigs('Text Size', 'Max Text Size') |
|
245 |
maxSize = int(configs[0].value) if 1 == len(configs) else self.ui.maxTextSizeSpinBox.setValue(60) |
|
246 |
|
|
247 |
im = Image.fromarray(img) |
|
248 |
ocrData = pytesseract.image_to_boxes(im, config=conf) |
|
249 |
|
|
250 |
count = 0 |
|
251 |
if ocrData: |
|
252 |
splitOcrData = ocrData.split('\n') |
|
253 |
for data in splitOcrData: |
|
254 |
print('TOCR RESULT : ' + data) |
|
255 |
strData = data.split(' ') |
|
256 |
text = strData[0] |
|
257 |
tsx = int(strData[1]) |
|
258 |
tsy = int(strData[2]) |
|
259 |
tex = int(strData[3]) |
|
260 |
tey = int(strData[4]) |
|
261 |
tw = tex - tsx |
|
262 |
th = tey - tsy |
|
263 |
|
|
264 |
if th >= minSize and th <= maxSize: |
|
265 |
roi = img[tsy:tsy + th, tsx:tsx + tw] |
|
266 |
temp = roi.copy() |
|
267 |
tempBin = cv2.bitwise_not(temp) |
|
268 |
roi = cv2.bitwise_xor(roi, tempBin, roi) |
|
269 |
|
|
270 |
count = count + 1 |
|
271 |
|
|
272 |
print("############################# OCR Result COUNT : " + str(count)) |
|
273 |
|
|
274 |
return img |
|
275 |
|
|
276 |
|
|
277 |
''' |
|
278 |
@history 2018.06.14 Jeongwoo Add try-except. If exception occurred, return None |
|
279 |
''' |
|
280 |
|
|
281 |
|
|
282 |
def imageToData(img, conf): |
|
283 |
docData = AppDocData.instance() |
|
284 |
configs = docData.getConfigs('Text Size', 'Min Text Size') |
|
285 |
minSize = int(configs[0].value) if 1 == len(configs) else self.ui.minTextSizeSpinBox.setValue(30) |
|
286 |
configs = docData.getConfigs('Text Size', 'Max Text Size') |
|
287 |
maxSize = int(configs[0].value) if 1 == len(configs) else self.ui.maxTextSizeSpinBox.setValue(60) |
|
288 |
|
|
289 |
im = Image.fromarray(img) |
|
290 |
ocrData = pytesseract.image_to_data(im, config=conf) |
|
291 |
|
|
292 |
if ocrData: |
|
293 |
splitOcrData = ocrData.split('\n') |
|
294 |
size = len(splitOcrData) |
|
295 |
i = 1 |
|
296 |
while i < size: |
|
297 |
data = splitOcrData[i] |
|
298 |
sData = data.split('\t') |
|
299 |
if len(sData) == 12: |
|
300 |
text = sData[11] |
|
301 |
tx = int(sData[6]) |
|
302 |
ty = int(sData[7]) |
|
303 |
tw = int(sData[8]) |
|
304 |
th = int(sData[9]) |
|
305 |
print('TOCR RESULT : ' + text + ' , (' + str(tx) + ',' + str(ty) + '), ' + str(tw) + ' ' + str(th)) |
|
306 |
|
|
307 |
if th >= minSize and th <= maxSize: |
|
308 |
roi = img[ty:ty + th, tx:tx + tw] |
|
309 |
temp = roi.copy() |
|
310 |
tempBin = cv2.bitwise_not(temp) |
|
311 |
roi = cv2.bitwise_xor(roi, tempBin, roi) |
|
312 |
cv2.imshow('temp', temp) |
|
313 |
cv2.imshow('tempBin', tempBin) |
|
314 |
cv2.waitKey(0) |
|
315 |
cv2.destroyAllWindows() |
|
316 |
i = i + 1 |
|
317 |
|
|
318 |
cv2.imshow('image_To_Data', img) |
|
319 |
cv2.waitKey(0) |
|
320 |
return img |
|
321 |
|
|
322 |
|
|
323 |
def imageToString(img, conf): |
|
324 |
im = Image.fromarray(img) |
|
325 |
conf = 'hocr' |
|
326 |
ocrData = pytesseract.image_to_string(im, config=conf) |
|
327 |
|
|
328 |
if ocrData: |
|
329 |
print(ocrData) |
|
330 |
|
|
331 |
return img |
내보내기 Unified diff