개정판 d06ac7b3
issue #49: fix legend read and add webserver connection test and fix ocr
Change-Id: I0c77d0111cba0f02d95bb98c13ac0fd2c9525d17
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
936 | 936 |
rows = cursor.fetchall() |
937 | 937 |
for row in rows: |
938 | 938 |
attr = [] |
939 |
attr.append('UID') # uid
|
|
940 |
attr.append('Name') # name
|
|
941 |
attr.append('AREA') # area
|
|
942 |
attr.append('TEXT') # text
|
|
939 |
attr.append(row['UID']) # uid
|
|
940 |
attr.append(row['Name']) # name
|
|
941 |
attr.append(row['AREA']) # area
|
|
942 |
attr.append(row['TEXT']) # text
|
|
943 | 943 |
self._titleBlockProperties.append(attr) |
944 | 944 |
|
945 | 945 |
res = self._titleBlockProperties |
DTI_PID/DTI_PID/AppWebService.py | ||
---|---|---|
14 | 14 |
class AppWebService: |
15 | 15 |
""" This is AppDatabase class """ |
16 | 16 |
|
17 |
def __init__(self): |
|
18 |
configs = AppDocData.instance().getConfigs('Engine', 'Address') |
|
19 |
self._url = configs[0].value if configs else None |
|
17 |
def __init__(self, url=None): |
|
18 |
if not url: |
|
19 |
configs = AppDocData.instance().getConfigs('Engine', 'Address') |
|
20 |
self._url = configs[0].value if configs else None |
|
21 |
else: |
|
22 |
self._url = url |
|
20 | 23 |
#self._url = 'http://192.168.0.21:80' |
21 | 24 |
|
22 |
def text_connection(self):
|
|
25 |
def test_connection(self):
|
|
23 | 26 |
try: |
24 | 27 |
if not self._url: |
25 | 28 |
return False |
... | ... | |
35 | 38 |
def request_text_box(self, img, img_path, score_path): |
36 | 39 |
# send uncroped image |
37 | 40 |
try: |
38 |
if not self.text_connection():
|
|
41 |
if not self.test_connection():
|
|
39 | 42 |
return [] |
40 | 43 |
|
41 | 44 |
text_box = '/text_box' |
... | ... | |
56 | 59 |
|
57 | 60 |
def request_text_box_tile(self, img_infos, img_path, score_path): |
58 | 61 |
try: |
59 |
if not self.text_connection():
|
|
62 |
if not self.test_connection():
|
|
60 | 63 |
return [] |
61 | 64 |
|
62 | 65 |
text_box = '/stream_text_box' |
DTI_PID/DTI_PID/CodeTableDialog.py | ||
---|---|---|
88 | 88 |
self.ui.pushButtonRead.setText('Draw Code Area') |
89 | 89 |
elif self.ui.pushButtonRead.text() == 'Read' and self.code_area and self.code_area.scene() and self.desc_area and self.desc_area.scene(): |
90 | 90 |
# read ocr |
91 |
app_doc_data = AppDocData.instance() |
|
91 | 92 |
code_rect = self.code_area.sceneBoundingRect() |
92 | 93 |
desc_rect = self.desc_area.sceneBoundingRect() |
93 |
code_img = self.graphicsView.image().copy(code_rect.x(), code_rect.y(), code_rect.width(), code_rect.height()) |
|
94 |
desc_img = self.graphicsView.image().copy(desc_rect.x(), desc_rect.y(), desc_rect.width(), desc_rect.height()) |
|
94 |
#code_img = self.graphicsView.image().copy(code_rect.x(), code_rect.y(), code_rect.width(), code_rect.height()) |
|
95 |
#desc_img = self.graphicsView.image().copy(desc_rect.x(), desc_rect.y(), desc_rect.width(), desc_rect.height()) |
|
96 |
code_img = app_doc_data.activeDrawing.image.copy() |
|
97 |
code_img = code_img[int(code_rect.y()):int(code_rect.y() + code_rect.height()), \ |
|
98 |
int(code_rect.x()):int(code_rect.x() + code_rect.width())] |
|
99 |
desc_img = app_doc_data.activeDrawing.image.copy() |
|
100 |
desc_img = desc_img[int(desc_rect.y()):int(desc_rect.y() + desc_rect.height()), \ |
|
101 |
int(desc_rect.x()):int(desc_rect.x() + desc_rect.width())] |
|
95 | 102 |
code_texts = self.detectText(code_img, code_rect) |
96 | 103 |
desc_texts = self.detectText(desc_img, desc_rect) |
97 | 104 |
|
... | ... | |
203 | 210 |
def detectText(self, image, rect): |
204 | 211 |
""" detect text from image, come from OcrResultDialog and modified """ |
205 | 212 |
try: |
213 |
''' |
|
206 | 214 |
buffer = QBuffer() |
207 | 215 |
buffer.open(QBuffer.ReadWrite) |
208 | 216 |
image.save(buffer, "PNG") |
209 | 217 |
pyImage = Image.open(io.BytesIO(buffer.data())) |
210 | 218 |
img = np.array(pyImage) |
219 |
''' |
|
211 | 220 |
|
212 | 221 |
docData = AppDocData.instance() |
213 | 222 |
configs = docData.getConfigs('Text Recognition', 'OCR Data') |
... | ... | |
215 | 224 |
|
216 | 225 |
whiteCharList = docData.getConfigs('Text Recognition', 'White Character List') |
217 | 226 |
if len(whiteCharList) is 0: |
218 |
textInfoList = TOCR.getTextInfo(img, (round(rect.x()), round(rect.y())), 0, language=ocr_data)
|
|
227 |
textInfoList = TOCR.getTextInfo(image, (round(rect.x()), round(rect.y())), 0, language=ocr_data)
|
|
219 | 228 |
else: |
220 |
textInfoList = TOCR.getTextInfo(img, (round(rect.x()), round(rect.y())), 0, language=ocr_data, conf = whiteCharList[0].value)
|
|
229 |
textInfoList = TOCR.getTextInfo(image, (round(rect.x()), round(rect.y())), 0, language=ocr_data, conf = whiteCharList[0].value)
|
|
221 | 230 |
|
222 | 231 |
if textInfoList is not None and len(textInfoList) > 0: |
223 | 232 |
return textInfoList |
DTI_PID/DTI_PID/ConfigurationDialog.py | ||
---|---|---|
461 | 461 |
self.ui.listWidgetLineNo.itemDoubleClicked.connect(self.lineNoItemDoubleCliced) |
462 | 462 |
self.ui.listWidgetTagNo.itemDoubleClicked.connect(self.tagNoItemDoubleCliced) |
463 | 463 |
self.ui.pushButtonClearAccessInfo.clicked.connect(self.clear_drawing_access_info_clicked) |
464 |
self.ui.pushButtonServerTest.clicked.connect(self.on_test_connection_clicked) |
|
464 | 465 |
|
465 | 466 |
# close when user press escape key |
466 | 467 |
shortcut = QShortcut(QKeySequence(Qt.Key_Escape), self) |
... | ... | |
473 | 474 |
self.ui.radioButtonOCRServer.hide() |
474 | 475 |
# up to here |
475 | 476 |
|
477 |
def on_test_connection_clicked(self): |
|
478 |
""" web server connection test """ |
|
479 |
from AppWebService import AppWebService |
|
480 |
|
|
481 |
app_web_service = AppWebService(self.ui.lineEditServerAddress.text()) |
|
482 |
if app_web_service.test_connection(): |
|
483 |
QMessageBox.information(self, self.tr('Information'), self.tr('Test connection is success')) |
|
484 |
else: |
|
485 |
QMessageBox.information(self, self.tr('Information'), self.tr('Test connection is fail')) |
|
486 |
|
|
476 | 487 |
def set_page_segmentation_modes(self): |
477 | 488 |
"""show page segmentation modes""" |
478 | 489 |
try: |
DTI_PID/DTI_PID/Configuration_UI.py | ||
---|---|---|
757 | 757 |
self.lineEditServerAddress = QtWidgets.QLineEdit(self.groupBox_13) |
758 | 758 |
self.lineEditServerAddress.setObjectName("lineEditServerAddress") |
759 | 759 |
self.gridLayout_37.addWidget(self.lineEditServerAddress, 0, 1, 1, 1) |
760 |
self.pushButtonServerTest = QtWidgets.QPushButton(self.groupBox_13) |
|
761 |
self.pushButtonServerTest.setObjectName("pushButtonServerTest") |
|
762 |
self.gridLayout_37.addWidget(self.pushButtonServerTest, 0, 2, 1, 1) |
|
760 | 763 |
self.gridLayout_38.addLayout(self.gridLayout_37, 0, 0, 1, 1) |
761 | 764 |
self.gridLayout_21.addWidget(self.groupBox_13, 2, 0, 1, 1) |
762 | 765 |
self.gridLayout_22.addLayout(self.gridLayout_21, 0, 0, 1, 1) |
... | ... | |
958 | 961 |
self.label_46.setText(_translate("ConfigurationDialog", "Text Area")) |
959 | 962 |
self.label_47.setText(_translate("ConfigurationDialog", "OCR")) |
960 | 963 |
self.label_48.setText(_translate("ConfigurationDialog", "Server Address")) |
964 |
self.pushButtonServerTest.setText(_translate("ConfigurationDialog", "Test Connection")) |
|
961 | 965 |
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabETC), _translate("ConfigurationDialog", "ETC")) |
962 | 966 |
|
963 | 967 |
import MainWindow_rc |
DTI_PID/DTI_PID/OcrResultDialog.py | ||
---|---|---|
228 | 228 |
conf=white_char_list[0].value if white_char_list else '') |
229 | 229 |
|
230 | 230 |
if self.textInfoList: |
231 |
self.textInfoList = sorted(self.textInfoList, key=lambda param: param.getY()) |
|
231 |
#self.textInfoList = sorted(self.textInfoList, key=lambda param: param.getY())
|
|
232 | 232 |
self.ui.detectResultTextEdit.setText(self.getPlainText(self.textInfoList)) |
233 | 233 |
self.display_text_rect() |
234 | 234 |
|
DTI_PID/DTI_PID/Shapes/EngineeringTextItem.py | ||
---|---|---|
337 | 337 |
y = text_info.getY() |
338 | 338 |
angle = text_info.getAngle() |
339 | 339 |
text = text_info.getText() |
340 |
if not text.replace(' ', '').replace('\n', ''): |
|
341 |
return None |
|
340 | 342 |
width = text_info.getW() |
341 | 343 |
height = text_info.getH() |
342 | 344 |
item = TextItemFactory.instance().createTextItem(text_info) |
DTI_PID/DTI_PID/UI/Configuration.ui | ||
---|---|---|
1618 | 1618 |
<item row="0" column="1"> |
1619 | 1619 |
<widget class="QLineEdit" name="lineEditServerAddress"/> |
1620 | 1620 |
</item> |
1621 |
<item row="0" column="2"> |
|
1622 |
<widget class="QPushButton" name="pushButtonServerTest"> |
|
1623 |
<property name="text"> |
|
1624 |
<string>Test Connection</string> |
|
1625 |
</property> |
|
1626 |
</widget> |
|
1627 |
</item> |
|
1621 | 1628 |
</layout> |
1622 | 1629 |
</item> |
1623 | 1630 |
</layout> |
... | ... | |
1763 | 1770 |
</connection> |
1764 | 1771 |
</connections> |
1765 | 1772 |
<buttongroups> |
1766 |
<buttongroup name="buttonGroup_4"/> |
|
1767 | 1773 |
<buttongroup name="buttonGroup_2"/> |
1768 | 1774 |
<buttongroup name="buttonGroup_3"/> |
1775 |
<buttongroup name="buttonGroup_5"/> |
|
1769 | 1776 |
<buttongroup name="buttonGroup"/> |
1777 |
<buttongroup name="buttonGroup_4"/> |
|
1770 | 1778 |
<buttongroup name="buttonGroup_6"/> |
1771 |
<buttongroup name="buttonGroup_5"/> |
|
1772 | 1779 |
</buttongroups> |
1773 | 1780 |
</ui> |
DTI_PID/DTI_PID/tesseract_ocr_module.py | ||
---|---|---|
141 | 141 |
|
142 | 142 |
fit_width = maxX - minX |
143 | 143 |
fit_length = maxY - minY |
144 |
if fit_length < maxSize: |
|
144 |
if True:#fit_length < maxSize:
|
|
145 | 145 |
long_img = Image.new('RGB', ((maxX - minX)* 3, maxY - minY), (255, 255, 255)) |
146 | 146 |
fit_im = im.crop((minX + thickness, minY + thickness, minX + thickness + fit_width, minY + thickness + fit_length)) |
147 | 147 |
long_img.paste(fit_im, (0, 0)) |
... | ... | |
158 | 158 |
bounding_boxes = boundaryOcrData.split('\n') |
159 | 159 |
|
160 | 160 |
bounding_boxes = [box for box in bounding_boxes if box != ''] |
161 |
bounding_boxes = sorted(bounding_boxes, key=lambda param: int(param.split(' ')[4]) - int(param.split(' ')[2]), reverse=True) |
|
161 |
#bounding_boxes = sorted(bounding_boxes, key=lambda param: int(param.split(' ')[4]) - int(param.split(' ')[2]), reverse=True)
|
|
162 | 162 |
merged_boxes = [] |
163 | 163 |
|
164 | 164 |
for box in bounding_boxes: |
... | ... | |
189 | 189 |
maxy = int(tokens[4]) |
190 | 190 |
merged_boxes.append(QRect(minx, miny, maxx - minx, maxy - miny)) |
191 | 191 |
|
192 |
#merged_boxes = sorted(merged_boxes, key=lambda param: param.y(), reverse=True) |
|
192 | 193 |
for rect in merged_boxes: |
193 | 194 |
if not rect.isValid() or \ |
194 | 195 |
rect.left() < 0 or rect.top() < 0 or rect.right() > imgWidth or rect.bottom() > imgHeight: |
... | ... | |
196 | 197 |
if len(merged_boxes) == 1: |
197 | 198 |
cropped = im |
198 | 199 |
else: |
199 |
cropped = im.crop((rect.left(), imgHeight - rect.bottom(), rect.right(), imgHeight - rect.top())) |
|
200 |
cropped = im.crop((rect.left() - 2, imgHeight - rect.bottom(), rect.right(), imgHeight - rect.top()))
|
|
200 | 201 |
# add padding to increase text recognition |
201 | 202 |
cropped = ImageOps.expand(cropped, border=thickness, fill='white') |
202 | 203 |
|
... | ... | |
213 | 214 |
# up to here |
214 | 215 |
if minSize <= rect.height() <= maxSize: # TODO: 이 부분이 필요한가? |
215 | 216 |
if long_img: |
216 |
text_rect = QRect(rect.left() + offset_x, rect.top() + offset_y, int(rect.width()/ 3), rect.height()) |
|
217 |
#text_rect = QRect(rect.left() + offset_x, rect.top() + offset_y, int(rect.width()/ 3), rect.height()) |
|
218 |
text_rect = QRect(rect.left() + offset_x, imgHeight - rect.bottom() + offset_y, int(rect.width()/ 3), rect.height()) |
|
217 | 219 |
else: |
218 | 220 |
text_rect = QRect(rect.left(), imgHeight - rect.bottom(), rect.width(), rect.height()) |
219 | 221 |
|
... | ... | |
233 | 235 |
|
234 | 236 |
del im |
235 | 237 |
|
236 |
return textInfoList
|
|
238 |
return sorted(textInfoList, key=lambda param: param.getY())
|
|
237 | 239 |
except Exception as ex: |
238 | 240 |
from App import App |
239 | 241 |
from AppDocData import MessageType |
내보내기 Unified diff