개정판 2c6bfc15
issue #000: add unknown item ocr funct
Change-Id: Id5d66f9eaa8663fa879075fd52ebcb25c246700d
DTI_PID/DTI_PID/AppRibbon.py | ||
---|---|---|
166 | 166 |
pane.ui.toolButtonTextDataList.clicked.connect(main_wnd.showTextDataList) |
167 | 167 |
pane.ui.toolButtonSymbolReplaceInsert.clicked.connect(main_wnd.replaceInsertSymbolClicked) |
168 | 168 |
pane.ui.toolButtonConnectLineToSymbol.clicked.connect(main_wnd.on_connect_line_to_symbol) |
169 |
pane.ui.toolButtonOCRUnknown.clicked.connect(main_wnd.on_ocr_unknown_items) |
|
169 | 170 |
cSection.addCustomWidget(pane) |
170 | 171 |
except Exception as ex: |
171 | 172 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
645 | 645 |
dlg.show() |
646 | 646 |
dlg.exec_() |
647 | 647 |
|
648 |
def on_ocr_unknown_items(self): |
|
649 |
""" try to ocr for unknown items """ |
|
650 |
from OcrResultDialog import QOcrResultDialog |
|
651 |
|
|
652 |
if not self.graphicsView.hasImage(): |
|
653 |
self.showImageSelectionMessageBox() |
|
654 |
return |
|
655 |
|
|
656 |
app_doc_data = AppDocData.instance() |
|
657 |
configs = app_doc_data.getConfigs('Text Size', 'Max Text Size') |
|
658 |
maxSize = int(configs[0].value) if 1 == len(configs) else 100 |
|
659 |
configs = app_doc_data.getConfigs('Text Size', 'Min Text Size') |
|
660 |
minSize = int(configs[0].value) if 1 == len(configs) else 15 |
|
661 |
|
|
662 |
unknowns = [item for item in self.graphicsView.scene().items() if type(item) is QEngineeringUnknownItem] |
|
663 |
|
|
664 |
for unknown in unknowns: |
|
665 |
rect = unknown.sceneBoundingRect() |
|
666 |
if rect.width() < minSize or rect.height() < minSize or rect.width() > maxSize or rect.height() > maxSize: |
|
667 |
continue |
|
668 |
self.onRecognizeText(round(rect.left()), round(rect.top()), round(rect.width()), round(rect.height()), show=False) |
|
669 |
unknown.transfer.onRemoved.emit(unknown) |
|
670 |
|
|
648 | 671 |
def on_connect_line_to_symbol(self): |
649 | 672 |
"""connect line to symbol""" |
650 | 673 |
from LineDetector import LineDetector |
... | ... | |
1267 | 1290 |
else: |
1268 | 1291 |
self.graphicsView.useDefaultCommand() |
1269 | 1292 |
|
1270 |
def onRecognizeText(self, x, y, width, height): |
|
1293 |
def onRecognizeText(self, x, y, width, height, show=True):
|
|
1271 | 1294 |
"""show text recognition dialog""" |
1272 | 1295 |
from OcrResultDialog import QOcrResultDialog |
1273 | 1296 |
from Area import Area |
... | ... | |
1281 | 1304 |
format=QOcrResultDialog.Format.Table if modifiers == Qt.AltModifier else QOcrResultDialog.Format.Normal) |
1282 | 1305 |
if modifiers == Qt.ControlModifier: |
1283 | 1306 |
return |
1284 |
(res, textInfoList) = dialog.showDialog() |
|
1307 |
|
|
1308 |
if show: |
|
1309 |
(res, textInfoList) = dialog.showDialog() |
|
1310 |
else: |
|
1311 |
dialog.accept(show=False) |
|
1312 |
(res, textInfoList) = QDialog.Accepted, dialog.textInfoList |
|
1313 |
|
|
1285 | 1314 |
if QDialog.Accepted == res and textInfoList: |
1286 | 1315 |
for textInfo in textInfoList: |
1287 | 1316 |
item = QEngineeringTextItem.create_text_with(self.graphicsView.scene(), textInfo) |
... | ... | |
1304 | 1333 |
break |
1305 | 1334 |
else: |
1306 | 1335 |
self.addMessage.emit(MessageType.Normal, self.tr('Fail to create text.')) |
1307 |
elif QDialog.Accepted == res and not textInfoList: |
|
1336 |
elif QDialog.Accepted == res and not textInfoList and show:
|
|
1308 | 1337 |
QMessageBox.about(self.graphicsView, self.tr("Notice"), self.tr("Fail to recognize text")) |
1309 | 1338 |
except Exception as ex: |
1310 | 1339 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
DTI_PID/DTI_PID/OcrResultDialog.py | ||
---|---|---|
297 | 297 |
@history 18.04.20 Jeongwoo Calculate Start Point Coordinates by rotated angle |
298 | 298 |
18.04.26 Jeongwoo Scene.itemAt(textX - boundBox.x(), textY - boundBox.y()) |
299 | 299 |
''' |
300 |
|
|
301 |
def accept(self): |
|
300 |
def accept(self, show=True): |
|
302 | 301 |
from TextInfo import TextInfo |
303 | 302 |
self.isAccepted = True |
304 | 303 |
|
305 | 304 |
try: |
306 | 305 |
text = self.ui.detectResultTextEdit.toPlainText() |
307 | 306 |
if text == '' or text == 'Not Found': |
308 |
QMessageBox.about(self.ui.ocrDialogButtonBox, self.tr('Notice'), |
|
307 |
if show: |
|
308 |
QMessageBox.about(self.ui.ocrDialogButtonBox, self.tr('Notice'), |
|
309 | 309 |
self.tr('Please try again after recognition or type.')) |
310 | 310 |
return |
311 | 311 |
|
DTI_PID/DTI_PID/UI/Edit.ui | ||
---|---|---|
6 | 6 |
<rect> |
7 | 7 |
<x>0</x> |
8 | 8 |
<y>0</y> |
9 |
<width>375</width>
|
|
9 |
<width>498</width>
|
|
10 | 10 |
<height>70</height> |
11 | 11 |
</rect> |
12 | 12 |
</property> |
... | ... | |
34 | 34 |
<property name="spacing"> |
35 | 35 |
<number>0</number> |
36 | 36 |
</property> |
37 |
<item row="0" column="2"> |
|
37 |
<item row="0" column="4"> |
|
38 |
<widget class="QToolButton" name="toolButtonConnectLineToSymbol"> |
|
39 |
<property name="text"> |
|
40 |
<string>Connect |
|
41 |
Symbols and Lines</string> |
|
42 |
</property> |
|
43 |
<property name="icon"> |
|
44 |
<iconset resource="../res/MainWindow.qrc"> |
|
45 |
<normaloff>:/newPrefix/connect_symbol_line.svg</normaloff>:/newPrefix/connect_symbol_line.svg</iconset> |
|
46 |
</property> |
|
47 |
<property name="iconSize"> |
|
48 |
<size> |
|
49 |
<width>32</width> |
|
50 |
<height>32</height> |
|
51 |
</size> |
|
52 |
</property> |
|
53 |
<property name="toolButtonStyle"> |
|
54 |
<enum>Qt::ToolButtonTextUnderIcon</enum> |
|
55 |
</property> |
|
56 |
<property name="autoRaise"> |
|
57 |
<bool>true</bool> |
|
58 |
</property> |
|
59 |
</widget> |
|
60 |
</item> |
|
61 |
<item row="0" column="3"> |
|
38 | 62 |
<widget class="QToolButton" name="toolButtonSymbolReplaceInsert"> |
39 | 63 |
<property name="text"> |
40 | 64 |
<string>Symbol |
... | ... | |
58 | 82 |
</property> |
59 | 83 |
</widget> |
60 | 84 |
</item> |
61 |
<item row="0" column="0">
|
|
62 |
<widget class="QToolButton" name="toolButtonFindReplaceText">
|
|
85 |
<item row="0" column="1">
|
|
86 |
<widget class="QToolButton" name="toolButtonTextDataList">
|
|
63 | 87 |
<property name="text"> |
64 | 88 |
<string>Text |
65 |
Find/Replace</string>
|
|
89 |
Data List</string>
|
|
66 | 90 |
</property> |
67 | 91 |
<property name="icon"> |
68 | 92 |
<iconset resource="../res/MainWindow.qrc"> |
69 |
<normaloff>:/newPrefix/ReplaceText.svg</normaloff>:/newPrefix/ReplaceText.svg</iconset>
|
|
93 |
<normaloff>:/newPrefix/text_list_32px.svg</normaloff>:/newPrefix/text_list_32px.svg</iconset>
|
|
70 | 94 |
</property> |
71 | 95 |
<property name="iconSize"> |
72 | 96 |
<size> |
... | ... | |
82 | 106 |
</property> |
83 | 107 |
</widget> |
84 | 108 |
</item> |
85 |
<item row="0" column="1">
|
|
86 |
<widget class="QToolButton" name="toolButtonTextDataList">
|
|
109 |
<item row="0" column="0">
|
|
110 |
<widget class="QToolButton" name="toolButtonFindReplaceText">
|
|
87 | 111 |
<property name="text"> |
88 | 112 |
<string>Text |
89 |
Data List</string>
|
|
113 |
Find/Replace</string>
|
|
90 | 114 |
</property> |
91 | 115 |
<property name="icon"> |
92 | 116 |
<iconset resource="../res/MainWindow.qrc"> |
93 |
<normaloff>:/newPrefix/text_list_32px.svg</normaloff>:/newPrefix/text_list_32px.svg</iconset>
|
|
117 |
<normaloff>:/newPrefix/ReplaceText.svg</normaloff>:/newPrefix/ReplaceText.svg</iconset>
|
|
94 | 118 |
</property> |
95 | 119 |
<property name="iconSize"> |
96 | 120 |
<size> |
... | ... | |
106 | 130 |
</property> |
107 | 131 |
</widget> |
108 | 132 |
</item> |
109 |
<item row="0" column="3">
|
|
110 |
<widget class="QToolButton" name="toolButtonConnectLineToSymbol">
|
|
133 |
<item row="0" column="2">
|
|
134 |
<widget class="QToolButton" name="toolButtonOCRUnknown">
|
|
111 | 135 |
<property name="text"> |
112 |
<string>Connect |
|
113 |
symbols and lines</string> |
|
136 |
<string>OCR Unknown Items</string> |
|
114 | 137 |
</property> |
115 | 138 |
<property name="icon"> |
116 | 139 |
<iconset resource="../res/MainWindow.qrc"> |
117 |
<normaloff>:/newPrefix/connect_symbol_line.svg</normaloff>:/newPrefix/connect_symbol_line.svg</iconset>
|
|
140 |
<normaloff>:/newPrefix/OCR.svg</normaloff>:/newPrefix/OCR.svg</iconset>
|
|
118 | 141 |
</property> |
119 | 142 |
<property name="iconSize"> |
120 | 143 |
<size> |
내보내기 Unified diff