개정판 6547b5f1
issue #000:
- fixed some bugs
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
95 | 95 |
self.imgName = None |
96 | 96 |
self.imgWidth = 0 |
97 | 97 |
self.imgHeight = 0 |
98 |
self._OCRData = None |
|
98 | 99 |
self._imgSrc = None |
99 | 100 | |
100 | 101 |
self._areas = [] |
... | ... | |
2885 | 2886 |
conn.close() |
2886 | 2887 | |
2887 | 2888 |
return res |
2889 | ||
2890 |
''' |
|
2891 |
@brief getter of OCRData |
|
2892 |
@author humkyung |
|
2893 |
@date 2018.11.19 |
|
2894 |
''' |
|
2895 |
@property |
|
2896 |
def OCRData(self): |
|
2897 |
if self._OCRData is None: |
|
2898 |
configs = self.getConfigs('Text Recognition', 'OCR Data') |
|
2899 |
self._OCRData = configs[0].value if 1 == len(configs) else 'eng' |
|
2900 | ||
2901 |
return self._OCRData |
|
2902 | ||
2903 |
''' |
|
2904 |
@brief setter of OCRData |
|
2905 |
@author humkyung |
|
2906 |
@date 2018.11.19 |
|
2907 |
''' |
|
2908 |
@OCRData.setter |
|
2909 |
def OCRData(self, value): |
|
2910 |
self._OCRData = value |
DTI_PID/DTI_PID/ConfigurationDialog.py | ||
---|---|---|
56 | 56 |
configs = docData.getConfigs('Text Recognition', 'OCR Data') |
57 | 57 |
value = configs[0].value if 1 == len(configs) else '' |
58 | 58 |
if value: |
59 |
self.ui.comboBoxOCRData.setText(value) |
|
59 |
at = self.ui.comboBoxOCRData.findText(value) |
|
60 |
self.ui.comboBoxOCRData.setCurrentIndex(at) |
|
60 | 61 |
else: |
61 | 62 |
self.ui.comboBoxOCRData.selectedIndex = 0 |
62 | 63 | |
... | ... | |
459 | 460 |
self.isAccepted = True |
460 | 461 | |
461 | 462 |
configs = [] |
462 |
configs.append(Config('Text Recognition', 'OCR Data', self.ui.comboBoxOCRData.currentText() if self.ui.comboBoxOCRData.currentText() else '')) |
|
463 |
docData.OCRData = self.ui.comboBoxOCRData.currentText() if self.ui.comboBoxOCRData.currentText() else 'eng' |
|
464 |
configs.append(Config('Text Recognition', 'OCR Data', docData.OCRData)) |
|
463 | 465 |
configs.append(Config('Text Recognition', 'Expand Size', self.ui.spinBoxExpandSize.value())) |
464 | 466 |
configs.append(Config('Text Recognition', 'Shrink Size', self.ui.spinBoxShrinkSize.value())) |
465 | 467 |
configs.append(Config('Text Recognition', 'Merge Size', self.ui.spinBoxMergeSize.value())) |
DTI_PID/DTI_PID/Configuration_Area_UI.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 | |
3 |
# Form implementation generated from reading ui file './UI/Configuration_Area.ui'
|
|
3 |
# Form implementation generated from reading ui file '.\UI\Configuration_Area.ui'
|
|
4 | 4 |
# |
5 |
# Created by: PyQt5 UI code generator 5.11.2
|
|
5 |
# Created by: PyQt5 UI code generator 5.11.3
|
|
6 | 6 |
# |
7 | 7 |
# WARNING! All changes made in this file will be lost! |
8 | 8 | |
... | ... | |
11 | 11 |
class Ui_AreaDialog(object): |
12 | 12 |
def setupUi(self, AreaDialog): |
13 | 13 |
AreaDialog.setObjectName("AreaDialog") |
14 |
AreaDialog.resize(497, 544)
|
|
14 |
AreaDialog.resize(598, 544)
|
|
15 | 15 |
font = QtGui.QFont() |
16 | 16 |
font.setFamily("맑은 고딕") |
17 | 17 |
AreaDialog.setFont(font) |
... | ... | |
24 | 24 |
self.groupBox.setObjectName("groupBox") |
25 | 25 |
self.gridLayout_2 = QtWidgets.QGridLayout(self.groupBox) |
26 | 26 |
self.gridLayout_2.setObjectName("gridLayout_2") |
27 |
self.lineEditUnitArea = QtWidgets.QLineEdit(self.groupBox)
|
|
28 |
self.lineEditUnitArea.setObjectName("lineEditUnitArea")
|
|
29 |
self.gridLayout_2.addWidget(self.lineEditUnitArea, 5, 1, 1, 1)
|
|
27 |
self.label_3 = QtWidgets.QLabel(self.groupBox)
|
|
28 |
self.label_3.setObjectName("label_3")
|
|
29 |
self.gridLayout_2.addWidget(self.label_3, 3, 0, 1, 1)
|
|
30 | 30 |
self.pushButtonUnitArea = QtWidgets.QPushButton(self.groupBox) |
31 | 31 |
self.pushButtonUnitArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
32 | 32 |
self.pushButtonUnitArea.setObjectName("pushButtonUnitArea") |
33 | 33 |
self.gridLayout_2.addWidget(self.pushButtonUnitArea, 5, 4, 1, 1) |
34 |
self.label_7 = QtWidgets.QLabel(self.groupBox) |
|
35 |
self.label_7.setObjectName("label_7") |
|
36 |
self.gridLayout_2.addWidget(self.label_7, 5, 0, 1, 1) |
|
37 | 34 |
self.lineEditRevNo = QtWidgets.QLineEdit(self.groupBox) |
38 | 35 |
self.lineEditRevNo.setObjectName("lineEditRevNo") |
39 | 36 |
self.gridLayout_2.addWidget(self.lineEditRevNo, 3, 1, 1, 1) |
37 |
self.pushButtonHistoryDataArea = QtWidgets.QPushButton(self.groupBox) |
|
38 |
self.pushButtonHistoryDataArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
|
39 |
self.pushButtonHistoryDataArea.setObjectName("pushButtonHistoryDataArea") |
|
40 |
self.gridLayout_2.addWidget(self.pushButtonHistoryDataArea, 2, 4, 1, 1) |
|
40 | 41 |
self.lineEditNote = QtWidgets.QLineEdit(self.groupBox) |
41 | 42 |
self.lineEditNote.setObjectName("lineEditNote") |
42 | 43 |
self.gridLayout_2.addWidget(self.lineEditNote, 1, 1, 1, 1) |
44 |
self.lineEditHistoryData = QtWidgets.QLineEdit(self.groupBox) |
|
45 |
self.lineEditHistoryData.setObjectName("lineEditHistoryData") |
|
46 |
self.gridLayout_2.addWidget(self.lineEditHistoryData, 2, 1, 1, 1) |
|
43 | 47 |
self.pushButtonRevNoArea = QtWidgets.QPushButton(self.groupBox) |
44 | 48 |
self.pushButtonRevNoArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
45 | 49 |
self.pushButtonRevNoArea.setObjectName("pushButtonRevNoArea") |
46 | 50 |
self.gridLayout_2.addWidget(self.pushButtonRevNoArea, 3, 4, 1, 1) |
51 |
self.label_6 = QtWidgets.QLabel(self.groupBox) |
|
52 |
font = QtGui.QFont() |
|
53 |
font.setBold(True) |
|
54 |
font.setWeight(75) |
|
55 |
self.label_6.setFont(font) |
|
56 |
self.label_6.setObjectName("label_6") |
|
57 |
self.gridLayout_2.addWidget(self.label_6, 0, 0, 1, 1) |
|
58 |
self.lineEditDrawing = QtWidgets.QLineEdit(self.groupBox) |
|
59 |
self.lineEditDrawing.setObjectName("lineEditDrawing") |
|
60 |
self.gridLayout_2.addWidget(self.lineEditDrawing, 0, 1, 1, 1) |
|
61 |
self.label_7 = QtWidgets.QLabel(self.groupBox) |
|
62 |
self.label_7.setObjectName("label_7") |
|
63 |
self.gridLayout_2.addWidget(self.label_7, 5, 0, 1, 1) |
|
47 | 64 |
self.label_4 = QtWidgets.QLabel(self.groupBox) |
48 | 65 |
self.label_4.setObjectName("label_4") |
49 | 66 |
self.gridLayout_2.addWidget(self.label_4, 4, 0, 1, 1) |
50 |
self.label = QtWidgets.QLabel(self.groupBox) |
|
51 |
self.label.setObjectName("label") |
|
52 |
self.gridLayout_2.addWidget(self.label, 1, 0, 1, 1) |
|
53 | 67 |
self.pushButtonNoteArea = QtWidgets.QPushButton(self.groupBox) |
54 | 68 |
self.pushButtonNoteArea.setMinimumSize(QtCore.QSize(20, 0)) |
55 | 69 |
self.pushButtonNoteArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
56 | 70 |
self.pushButtonNoteArea.setObjectName("pushButtonNoteArea") |
57 | 71 |
self.gridLayout_2.addWidget(self.pushButtonNoteArea, 1, 4, 1, 1) |
58 |
self.pushButtonHistoryDataArea = QtWidgets.QPushButton(self.groupBox) |
|
59 |
self.pushButtonHistoryDataArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
|
60 |
self.pushButtonHistoryDataArea.setObjectName("pushButtonHistoryDataArea") |
|
61 |
self.gridLayout_2.addWidget(self.pushButtonHistoryDataArea, 2, 4, 1, 1) |
|
72 |
self.label_2 = QtWidgets.QLabel(self.groupBox) |
|
73 |
self.label_2.setObjectName("label_2") |
|
74 |
self.gridLayout_2.addWidget(self.label_2, 2, 0, 1, 1) |
|
75 |
self.lineEditUnitArea = QtWidgets.QLineEdit(self.groupBox) |
|
76 |
self.lineEditUnitArea.setObjectName("lineEditUnitArea") |
|
77 |
self.gridLayout_2.addWidget(self.lineEditUnitArea, 5, 1, 1, 1) |
|
78 |
self.label = QtWidgets.QLabel(self.groupBox) |
|
79 |
self.label.setObjectName("label") |
|
80 |
self.gridLayout_2.addWidget(self.label, 1, 0, 1, 1) |
|
62 | 81 |
self.lineEditDrawingNo = QtWidgets.QLineEdit(self.groupBox) |
63 | 82 |
self.lineEditDrawingNo.setObjectName("lineEditDrawingNo") |
64 | 83 |
self.gridLayout_2.addWidget(self.lineEditDrawingNo, 4, 1, 1, 1) |
... | ... | |
66 | 85 |
self.pushButtonDrawingNoArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
67 | 86 |
self.pushButtonDrawingNoArea.setObjectName("pushButtonDrawingNoArea") |
68 | 87 |
self.gridLayout_2.addWidget(self.pushButtonDrawingNoArea, 4, 4, 1, 1) |
69 |
self.label_3 = QtWidgets.QLabel(self.groupBox) |
|
70 |
self.label_3.setObjectName("label_3") |
|
71 |
self.gridLayout_2.addWidget(self.label_3, 3, 0, 1, 1) |
|
72 |
self.label_2 = QtWidgets.QLabel(self.groupBox) |
|
73 |
self.label_2.setObjectName("label_2") |
|
74 |
self.gridLayout_2.addWidget(self.label_2, 2, 0, 1, 1) |
|
75 |
self.lineEditHistoryData = QtWidgets.QLineEdit(self.groupBox) |
|
76 |
self.lineEditHistoryData.setObjectName("lineEditHistoryData") |
|
77 |
self.gridLayout_2.addWidget(self.lineEditHistoryData, 2, 1, 1, 1) |
|
78 |
self.label_6 = QtWidgets.QLabel(self.groupBox) |
|
79 |
font = QtGui.QFont() |
|
80 |
font.setBold(True) |
|
81 |
font.setWeight(75) |
|
82 |
self.label_6.setFont(font) |
|
83 |
self.label_6.setObjectName("label_6") |
|
84 |
self.gridLayout_2.addWidget(self.label_6, 0, 0, 1, 1) |
|
85 |
self.lineEditDrawing = QtWidgets.QLineEdit(self.groupBox) |
|
86 |
self.lineEditDrawing.setObjectName("lineEditDrawing") |
|
87 |
self.gridLayout_2.addWidget(self.lineEditDrawing, 0, 1, 1, 1) |
|
88 | 88 |
self.pushButtonDrawingArea = QtWidgets.QPushButton(self.groupBox) |
89 | 89 |
self.pushButtonDrawingArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
90 | 90 |
self.pushButtonDrawingArea.setObjectName("pushButtonDrawingArea") |
91 | 91 |
self.gridLayout_2.addWidget(self.pushButtonDrawingArea, 0, 4, 1, 1) |
92 |
self.pushButtonDelDrawingArea = QtWidgets.QPushButton(self.groupBox) |
|
93 |
self.pushButtonDelDrawingArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
|
94 |
self.pushButtonDelDrawingArea.setObjectName("pushButtonDelDrawingArea") |
|
95 |
self.gridLayout_2.addWidget(self.pushButtonDelDrawingArea, 0, 5, 1, 1) |
|
96 |
self.pushButtonDelNoteArea = QtWidgets.QPushButton(self.groupBox) |
|
97 |
self.pushButtonDelNoteArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
|
98 |
self.pushButtonDelNoteArea.setObjectName("pushButtonDelNoteArea") |
|
99 |
self.gridLayout_2.addWidget(self.pushButtonDelNoteArea, 1, 5, 1, 1) |
|
100 |
self.pushButtonDelHistoryDataArea = QtWidgets.QPushButton(self.groupBox) |
|
101 |
self.pushButtonDelHistoryDataArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
|
102 |
self.pushButtonDelHistoryDataArea.setObjectName("pushButtonDelHistoryDataArea") |
|
103 |
self.gridLayout_2.addWidget(self.pushButtonDelHistoryDataArea, 2, 5, 1, 1) |
|
104 |
self.pushButtonDelRevNoArea = QtWidgets.QPushButton(self.groupBox) |
|
105 |
self.pushButtonDelRevNoArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
|
106 |
self.pushButtonDelRevNoArea.setObjectName("pushButtonDelRevNoArea") |
|
107 |
self.gridLayout_2.addWidget(self.pushButtonDelRevNoArea, 3, 5, 1, 1) |
|
108 |
self.pushButtonDelDrawingNoArea = QtWidgets.QPushButton(self.groupBox) |
|
109 |
self.pushButtonDelDrawingNoArea.setMaximumSize(QtCore.QSize(25, 16777215)) |
|
110 |
self.pushButtonDelDrawingNoArea.setObjectName("pushButtonDelDrawingNoArea") |
|
111 |
self.gridLayout_2.addWidget(self.pushButtonDelDrawingNoArea, 4, 5, 1, 1) |
|
112 |
self.pushButtonDelUnitArea = QtWidgets.QPushButton(self.groupBox) |
|
113 |
self.pushButtonDelUnitArea.setMaximumSize(QtCore.QSize(24, 16777215)) |
|
114 |
self.pushButtonDelUnitArea.setObjectName("pushButtonDelUnitArea") |
|
115 |
self.gridLayout_2.addWidget(self.pushButtonDelUnitArea, 5, 5, 1, 1) |
|
92 | 116 |
self.gridLayout.addWidget(self.groupBox, 1, 0, 1, 1) |
93 | 117 |
self.groupBoxEquipmentDesc = QtWidgets.QGroupBox(AreaDialog) |
94 | 118 |
self.groupBoxEquipmentDesc.setObjectName("groupBoxEquipmentDesc") |
... | ... | |
168 | 192 |
_translate = QtCore.QCoreApplication.translate |
169 | 193 |
AreaDialog.setWindowTitle(_translate("AreaDialog", "Area")) |
170 | 194 |
self.groupBox.setTitle(_translate("AreaDialog", "영역")) |
195 |
self.label_3.setText(_translate("AreaDialog", "Rev. No : ")) |
|
171 | 196 |
self.pushButtonUnitArea.setText(_translate("AreaDialog", "...")) |
172 |
self.label_7.setText(_translate("AreaDialog", "Unit : "))
|
|
197 |
self.pushButtonHistoryDataArea.setText(_translate("AreaDialog", "..."))
|
|
173 | 198 |
self.pushButtonRevNoArea.setText(_translate("AreaDialog", "...")) |
199 |
self.label_6.setText(_translate("AreaDialog", "Drawing")) |
|
200 |
self.label_7.setText(_translate("AreaDialog", "Unit : ")) |
|
174 | 201 |
self.label_4.setText(_translate("AreaDialog", "Drawing No : ")) |
175 |
self.label.setText(_translate("AreaDialog", "Note : ")) |
|
176 | 202 |
self.pushButtonNoteArea.setText(_translate("AreaDialog", "...")) |
177 |
self.pushButtonHistoryDataArea.setText(_translate("AreaDialog", "...")) |
|
178 |
self.pushButtonDrawingNoArea.setText(_translate("AreaDialog", "...")) |
|
179 |
self.label_3.setText(_translate("AreaDialog", "Rev. No : ")) |
|
180 | 203 |
self.label_2.setText(_translate("AreaDialog", "History Data : ")) |
181 |
self.label_6.setText(_translate("AreaDialog", "Drawing")) |
|
204 |
self.label.setText(_translate("AreaDialog", "Note : ")) |
|
205 |
self.pushButtonDrawingNoArea.setText(_translate("AreaDialog", "...")) |
|
182 | 206 |
self.pushButtonDrawingArea.setText(_translate("AreaDialog", "...")) |
207 |
self.pushButtonDelDrawingArea.setText(_translate("AreaDialog", "-")) |
|
208 |
self.pushButtonDelNoteArea.setText(_translate("AreaDialog", "-")) |
|
209 |
self.pushButtonDelHistoryDataArea.setText(_translate("AreaDialog", "-")) |
|
210 |
self.pushButtonDelRevNoArea.setText(_translate("AreaDialog", "-")) |
|
211 |
self.pushButtonDelDrawingNoArea.setText(_translate("AreaDialog", "-")) |
|
212 |
self.pushButtonDelUnitArea.setText(_translate("AreaDialog", "-")) |
|
183 | 213 |
self.groupBoxEquipmentDesc.setTitle(_translate("AreaDialog", "Equipment Desc. 영역")) |
184 | 214 |
self.pushButtonAdd.setText(_translate("AreaDialog", "+")) |
185 | 215 |
self.pushButtonDel.setText(_translate("AreaDialog", "-")) |
... | ... | |
188 | 218 |
self.pushButtonDelTitleBlockProp.setText(_translate("AreaDialog", "-")) |
189 | 219 | |
190 | 220 |
import MainWindow_rc |
191 | ||
192 |
if __name__ == "__main__": |
|
193 |
import sys |
|
194 |
app = QtWidgets.QApplication(sys.argv) |
|
195 |
AreaDialog = QtWidgets.QDialog() |
|
196 |
ui = Ui_AreaDialog() |
|
197 |
ui.setupUi(AreaDialog) |
|
198 |
AreaDialog.show() |
|
199 |
sys.exit(app.exec_()) |
|
200 |
DTI_PID/DTI_PID/ProjectDialog.py | ||
---|---|---|
54 | 54 |
QDialog.reject(self) |
55 | 55 | |
56 | 56 |
def addProjectClick(self): |
57 |
print("Add project path") |
|
58 | 57 |
options = QFileDialog.Options() |
59 | 58 |
options |= QFileDialog.DontUseNativeDialog |
60 | 59 |
options |= QFileDialog.ShowDirsOnly |
DTI_PID/DTI_PID/TrainingImageListDialog.py | ||
---|---|---|
237 | 237 |
dataList = appDocData.getTrainingFileList() |
238 | 238 |
listHasBox = [] |
239 | 239 | |
240 |
self.ui.progressBar.setValue(0) |
|
241 |
self.ui.progressBar.setMaximum(7 + QTrainingImageListDialog.TRAINING_DATA_COUNT) |
|
242 | ||
240 | 243 |
images = {} |
241 | 244 |
boxes = [] |
242 | 245 |
self.charList = [] |
... | ... | |
252 | 255 |
images[os.path.splitext(os.path.basename(drawingPath))[0]] = drawing # save image and file name |
253 | 256 | |
254 | 257 |
boxPath = os.path.join(project.getTrainingFilePath(), data) |
258 |
box_file_name = os.path.splitext(os.path.basename(boxPath))[0] |
|
255 | 259 |
fw = open(boxPath, 'r', encoding='utf8') |
256 | 260 |
boxContent = fw.read() |
257 | 261 |
lines = boxContent.split('\n') |
258 | 262 |
for line in lines: |
259 | 263 |
if not line: continue |
260 | 264 |
char,min_x,min_y,max_x,max_y = line.split(' ') |
261 |
boxes.append([char,int(min_x),int(min_y),int(max_x)-int(min_x),int(max_y)-int(min_y),os.path.splitext(os.path.basename(boxPath))[0]])
|
|
265 |
boxes.append([char,int(min_x),int(min_y),int(max_x)-int(min_x),int(max_y)-int(min_y), box_file_name])
|
|
262 | 266 |
|
263 | 267 |
matches = [_char for _char in self.charList if _char[0] == char] |
264 | 268 |
if matches: |
... | ... | |
283 | 287 |
dimension[1] = (len(boxes) // dimension[0] + 1) if (len(boxes) % dimension[0]) > 0 else len(boxes) // dimension[0] |
284 | 288 | |
285 | 289 |
for sample in range(QTrainingImageListDialog.TRAINING_DATA_COUNT): |
290 |
shuffle(boxes) |
|
291 | ||
286 | 292 |
out_boxes = [] |
287 | 293 |
train_image = Image.new("RGB", (dimension[0]*(grid_size[0]), dimension[1]*(grid_size[1])), (256,256,256)) |
288 | 294 |
for j in range(dimension[1]): |
... | ... | |
299 | 305 |
str(loc[0] + space + box_image.width), str(train_image.height - loc[1] - space)]) |
300 | 306 |
else: |
301 | 307 |
""" |
302 |
x = loc[0] + space |
|
303 |
y = loc[1] + grid_size[1] - (space + box_image.height) |
|
308 |
x = loc[0] + int((grid_size[0] - box_image.width)*0.5)#space
|
|
309 |
y = loc[1] + int((grid_size[1] - box_image.height)*0.5)#grid_size[1] - (space + box_image.height)
|
|
304 | 310 |
train_image.paste(box_image, (x, y, x + box_image.width, y + box_image.height)) |
305 | 311 |
out_boxes.append([boxes[index][0], |
306 |
str(x), str(train_image.height - y - box_image.height),
|
|
307 |
str(x + box_image.width), str(train_image.height - y)])
|
|
312 |
str(x - 1), str(train_image.height - y - box_image.height - 1),
|
|
313 |
str(x + box_image.width + 1), str(train_image.height - y + 1)])
|
|
308 | 314 | |
309 | 315 |
train_image_path = os.path.join(project.getTrainingFilePath(), 'eng.' + self.oCRLang + 'F.exp{}.tif'.format(sample)) |
310 | 316 |
train_image.save(train_image_path, compression='tiff_lzw', dpi=(70,70)) |
... | ... | |
314 | 320 |
for out_box in out_boxes: |
315 | 321 |
fw.write(' '.join(out_box) + ' 0\n') |
316 | 322 |
fw.close() |
317 | ||
318 |
shuffle(boxes) |
|
319 | ||
320 |
""" |
|
321 |
areasNumber = len(listHasBoxImage) |
|
322 |
maxW, maxH, sumW, sumH = 0, 0, 0, 0 |
|
323 |
for imageArea in listHasBoxImage: |
|
324 |
areaW = imageArea.width |
|
325 |
areaH = imageArea.height |
|
326 |
sumW += areaW |
|
327 |
sumH += areaH |
|
328 |
if maxW < areaW: |
|
329 |
maxW = areaW |
|
330 |
if maxH < areaH: |
|
331 |
maxH = areaH |
|
332 |
|
|
333 |
#print('count : ' + str(areasNumber)) |
|
334 |
#print('max width : ' + str(maxW) + ', max height : ' + str(maxH)) |
|
335 |
argW = sumW / areasNumber |
|
336 |
argH = sumH / areasNumber |
|
337 |
#print('arg width : ' + str(argW) + ', arg height : ' + str(argH)) |
|
338 |
totalArea = math.ceil(argW * argH * areasNumber) |
|
339 |
totalBaseWidth = math.ceil(math.sqrt(totalArea)) |
|
340 |
#print('total area theory : ' + str(totalArea) + ', total width : ' + str(totalBaseWidth)) |
|
341 | ||
342 |
for imageArea in listHasBoxImage: |
|
343 |
areaW = imageArea.width |
|
344 |
areaH = imageArea.height |
|
345 |
if totalBaseWidth < areaW: |
|
346 |
totalBaseWidth = areaW + 1 |
|
347 | ||
348 |
maxLineH, lineW, totalHeight = 0, 0, 0 |
|
349 |
for imageArea in listHasBoxImage: |
|
350 |
areaW = imageArea.width |
|
351 |
areaH = imageArea.height |
|
352 |
preMaxLineH = maxLineH |
|
353 | ||
354 |
if maxLineH < areaH: |
|
355 |
maxLineH = areaH |
|
356 |
if lineW + areaW < totalBaseWidth: |
|
357 |
lineW += areaW |
|
358 |
else: |
|
359 |
maxLineH = preMaxLineH |
|
360 |
lineW = areaW |
|
361 |
totalHeight += maxLineH |
|
362 |
maxLineH = areaH |
|
363 |
totalHeight += maxLineH |
|
364 |
totalSeedHeight = totalHeight |
|
365 |
#print('total area real : ' + str(totalBaseWidth * totalSeedHeight) +', total width : ' + str(totalBaseWidth) + ', total height : ' + str(totalHeight) + ', ratio : ' + str(totalHeight / totalBaseWidth)) |
|
366 | ||
367 |
trainingTextImg = Image.new("RGB", (totalBaseWidth, totalSeedHeight), (256,256,256)) |
|
368 |
seedHeight, seedWidth = trainingTextImg.height, trainingTextImg.width |
|
369 |
maxLineH, lineW, totalHeight, currentX, currentY = 0, 0, 0, 0, 0 |
|
370 |
outBox = "" |
|
371 |
for index in range(0, len(listHasBoxImage)): |
|
372 |
areaW = listHasBoxImage[index].width |
|
373 |
areaH = listHasBoxImage[index].height |
|
374 |
|
|
375 |
boxes = listBoxes[index].split('\n') |
|
376 |
preMaxLineH = maxLineH |
|
377 | ||
378 |
if maxLineH < areaH: |
|
379 |
maxLineH = areaH |
|
380 |
if lineW + areaW < totalBaseWidth: |
|
381 |
lineW += areaW |
|
382 |
trainingTextImg.paste(listHasBoxImage[index], (currentX, currentY, currentX + areaW, currentY + areaH)) |
|
383 |
for box in boxes: |
|
384 |
if box == '': continue |
|
385 |
boxComponent = box.split(' ') |
|
386 |
boxComponent[1] = int(boxComponent[1]) + currentX |
|
387 |
boxComponent[2] = seedHeight - currentY - areaH + int(boxComponent[2]) |
|
388 |
boxComponent[3] = int(boxComponent[3]) + currentX |
|
389 |
boxComponent[4] = seedHeight - currentY - areaH + int(boxComponent[4]) |
|
390 |
outBox += boxComponent[0] + " " + str(boxComponent[1]) + " " + str(boxComponent[2]) + " " + str(boxComponent[3]) + " " + str(boxComponent[4]) + ' 0\n' |
|
391 |
currentX = lineW |
|
392 | ||
393 |
else: |
|
394 |
maxLineH = preMaxLineH |
|
395 |
lineW = areaW |
|
396 |
totalHeight += maxLineH |
|
397 |
currentX = 0 |
|
398 |
currentY = totalHeight |
|
399 |
trainingTextImg.paste(listHasBoxImage[index], (currentX, currentY, currentX + areaW, currentY + areaH)) |
|
400 |
for box in boxes: |
|
401 |
if box == '': continue |
|
402 |
boxComponent = box.split(' ') |
|
403 |
boxComponent[1] = int(boxComponent[1]) + currentX |
|
404 |
boxComponent[2] = seedHeight - currentY - areaH + int(boxComponent[2]) |
|
405 |
boxComponent[3] = int(boxComponent[3]) + currentX |
|
406 |
boxComponent[4] = seedHeight - currentY - areaH + int(boxComponent[4]) |
|
407 |
outBox += boxComponent[0] + " " + str(boxComponent[1]) + " " + str(boxComponent[2]) + " " + str(boxComponent[3]) + " " + str(boxComponent[4]) + ' 0\n' |
|
408 |
currentX = areaW |
|
409 |
maxLineH = areaH |
|
410 | ||
411 |
trainingImgPath = os.path.join(project.getTrainingFilePath(), self.oCRLang + '.' + self.oCRLang + 'F.exp0.tif') |
|
412 |
trainingBoxPath = os.path.join(project.getTrainingFilePath(), self.oCRLang + '.' + self.oCRLang + 'F.exp0.box') |
|
413 |
#trainingTextImg.save(trainingImgPath, compression='tiff_lzw') |
|
414 |
#fw = open(trainingBoxPath, 'w', encoding='utf8') |
|
415 |
#fw.write(outBox) |
|
416 |
#fw.close() |
|
417 | ||
418 |
boxes = outBox.split('\n') |
|
419 |
boxes = boxes[:-1] |
|
420 |
maxBoxWidth, maxBoxHeight = 0, 0 |
|
421 |
self.charList = [['0',0],['1',0],['2',0],['3',0],['4',0],['5',0],['6',0],['7',0],['8',0],['9',0],['a',0],['b',0],['c',0],['d',0],['e',0],['f',0],['g',0],['h',0],['i',0],['j',0],['k',0],['l',0],['m',0],['n',0],['o',0],['p',0],['q',0],['r',0],['s',0],['t',0],['u',0],['w',0],['x',0],['y',0],['z',0],['A',0],['B',0],['C',0],['D',0],['E',0],['F',0],['G',0],['H',0],['I',0],['J',0],['K',0],['L',0],['M',0],['N',0],['O',0],['P',0],['Q',0],['R',0],['S',0],['T',0],['U',0],['V',0],['W',0],['X',0],['Y',0],['Z',0]] |
|
422 |
for box in boxes: |
|
423 |
boxComponent = box.split(' ') |
|
424 |
boxWidth = abs(int(boxComponent[3]) - int(boxComponent[1])) |
|
425 |
boxHeight = abs(int(boxComponent[4]) - int(boxComponent[2])) |
|
426 |
if boxWidth > maxBoxWidth: |
|
427 |
maxBoxWidth = boxWidth |
|
428 |
if boxHeight > maxBoxHeight: |
|
429 |
maxBoxHeight = boxHeight |
|
430 | ||
431 |
for index in range(len(self.charList)): |
|
432 |
if self.charList[index][0] == boxComponent[0]: |
|
433 |
self.charList[index][1] += 1 |
|
434 |
break |
|
435 |
elif index is len(self.charList) - 1: |
|
436 |
self.charList.append([boxComponent[0], 1]) |
|
437 |
for index in range(len(self.charList)): |
|
438 |
self.charList[index][1] = int(self.charList[index][1] / 4) |
|
439 |
|
|
440 |
maxBoxWidth += 1 |
|
441 |
maxBoxHeight += 3 |
|
442 | ||
443 |
countOfOneSide = math.ceil(math.sqrt(len(boxes))) |
|
444 |
totalGridWidth = maxBoxWidth * countOfOneSide |
|
445 |
totalGridHeight = maxBoxHeight * countOfOneSide |
|
446 |
trainingGridImg = Image.new("RGB", (totalGridWidth, totalGridHeight), (256,256,256)) |
|
447 | ||
448 |
boxCount = 0 |
|
449 |
outBox = "" |
|
450 |
for rowCount in range(countOfOneSide): |
|
451 |
for colCount in range(countOfOneSide): |
|
452 |
boxComponent = boxes[boxCount].split(' ') |
|
453 |
gridX = int(boxComponent[1]) |
|
454 |
gridY = totalSeedHeight - int(boxComponent[4]) |
|
455 |
gridW = abs(int(boxComponent[3]) - int(boxComponent[1])) |
|
456 |
gridH = abs(int(boxComponent[4]) - int(boxComponent[2])) |
|
457 |
gridBoxImg = trainingTextImg.crop((gridX, gridY, gridX + gridW, gridY + gridH)) |
|
458 |
imagX1 = colCount * maxBoxWidth |
|
459 |
imagY1 = rowCount * maxBoxHeight |
|
460 |
imagX2 = colCount * maxBoxWidth + gridW |
|
461 |
imagY2 = rowCount * maxBoxHeight + gridH |
|
462 |
trainingGridImg.paste(gridBoxImg, (imagX1, imagY1, imagX2, imagY2)) |
|
463 | ||
464 |
boxX1 = imagX1 |
|
465 |
boxY1 = totalGridHeight - imagY2 |
|
466 |
boxX2 = imagX2 |
|
467 |
boxY2 = totalGridHeight - imagY1 |
|
468 |
outBox += boxComponent[0] + " " + str(boxX1) + " " + str(boxY1) + " " + str(boxX2) + " " + str(boxY2) + ' 0\n' |
|
469 |
boxCount += 1 |
|
470 |
if boxCount == len(boxes): |
|
471 |
break |
|
472 |
rowCount += 1 |
|
473 |
if boxCount == len(boxes): |
|
474 |
break |
|
475 |
trainingGridImg.save(trainingImgPath, compression='tiff_lzw') |
|
476 |
fw = open(trainingBoxPath, 'w', encoding='utf8') |
|
477 |
fw.write(outBox) |
|
478 |
fw.close() |
|
479 |
""" |
|
480 | 323 |
except Exception as ex: |
481 | 324 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
482 | 325 |
from App import App |
... | ... | |
490 | 333 |
originPath = os.getcwd() |
491 | 334 |
os.chdir(dataPath) |
492 | 335 |
|
493 |
self.ui.progressBar.setValue(0)
|
|
494 |
self.ui.progressBar.setMaximum(7)
|
|
336 |
self.ui.progressBar.setValue(self.ui.progressBar.value() + 1)
|
|
337 |
QApplication.processEvents()
|
|
495 | 338 | |
496 | 339 |
# 1 |
497 | 340 |
for sample in range(QTrainingImageListDialog.TRAINING_DATA_COUNT): |
... | ... | |
509 | 352 |
self.process.start('\"' + tesseract_cmd + '\"', [train_image_path, train_box_path, 'box.train']) |
510 | 353 |
""" |
511 | 354 |
subprocess.call(trainCmd, shell = True) |
512 |
self.ui.progressBar.setValue(self.ui.progressBar.value() + 1) |
|
513 |
QApplication.processEvents() |
|
355 | ||
356 |
self.ui.progressBar.setValue(self.ui.progressBar.value() + 1) |
|
357 |
QApplication.processEvents() |
|
514 | 358 | |
515 | 359 |
# 2 |
516 | 360 |
train_boxes = [] |
... | ... | |
543 | 387 |
# 4 |
544 | 388 |
font_properties = os.path.join(project.getTrainingFilePath(), 'font_properties') |
545 | 389 |
fw = open(font_properties, 'w', encoding='utf8') |
546 |
fw.write('{}F 0 0 1 0 0\n'.format(self.oCRLang))
|
|
390 |
fw.write('{}F 0 1 1 0 0\n'.format(self.oCRLang))
|
|
547 | 391 |
fw.close() |
548 | 392 |
self.ui.progressBar.setValue(self.ui.progressBar.value() + 1) |
549 | 393 |
QApplication.processEvents() |
... | ... | |
552 | 396 |
if ' ' in font_properties: |
553 | 397 |
font_properties = self.get_short_path_name(font_properties) |
554 | 398 |
train_data_files = [] |
555 |
for sample in range(5):
|
|
399 |
for sample in range(QTrainingImageListDialog.TRAINING_DATA_COUNT):
|
|
556 | 400 |
train_data_path = os.path.join(project.getTrainingFilePath(), 'eng.' + self.oCRLang + 'F.exp{}.tr'.format(sample)) |
557 | 401 |
if os.path.isfile(train_data_path): |
558 | 402 |
if ' ' in train_data_path: |
DTI_PID/DTI_PID/UI/Configuration_Area.ui | ||
---|---|---|
6 | 6 |
<rect> |
7 | 7 |
<x>0</x> |
8 | 8 |
<y>0</y> |
9 |
<width>497</width>
|
|
9 |
<width>598</width>
|
|
10 | 10 |
<height>544</height> |
11 | 11 |
</rect> |
12 | 12 |
</property> |
... | ... | |
29 | 29 |
<string>영역</string> |
30 | 30 |
</property> |
31 | 31 |
<layout class="QGridLayout" name="gridLayout_2"> |
32 |
<item row="5" column="1"> |
|
33 |
<widget class="QLineEdit" name="lineEditUnitArea"/> |
|
32 |
<item row="3" column="0"> |
|
33 |
<widget class="QLabel" name="label_3"> |
|
34 |
<property name="text"> |
|
35 |
<string>Rev. No : </string> |
|
36 |
</property> |
|
37 |
</widget> |
|
34 | 38 |
</item> |
35 | 39 |
<item row="5" column="4"> |
36 | 40 |
<widget class="QPushButton" name="pushButtonUnitArea"> |
... | ... | |
45 | 49 |
</property> |
46 | 50 |
</widget> |
47 | 51 |
</item> |
48 |
<item row="5" column="0"> |
|
49 |
<widget class="QLabel" name="label_7"> |
|
52 |
<item row="3" column="1"> |
|
53 |
<widget class="QLineEdit" name="lineEditRevNo"/> |
|
54 |
</item> |
|
55 |
<item row="2" column="4"> |
|
56 |
<widget class="QPushButton" name="pushButtonHistoryDataArea"> |
|
57 |
<property name="maximumSize"> |
|
58 |
<size> |
|
59 |
<width>24</width> |
|
60 |
<height>16777215</height> |
|
61 |
</size> |
|
62 |
</property> |
|
50 | 63 |
<property name="text"> |
51 |
<string>Unit : </string>
|
|
64 |
<string>...</string>
|
|
52 | 65 |
</property> |
53 | 66 |
</widget> |
54 | 67 |
</item> |
55 |
<item row="3" column="1"> |
|
56 |
<widget class="QLineEdit" name="lineEditRevNo"/> |
|
57 |
</item> |
|
58 | 68 |
<item row="1" column="1"> |
59 | 69 |
<widget class="QLineEdit" name="lineEditNote"/> |
60 | 70 |
</item> |
71 |
<item row="2" column="1"> |
|
72 |
<widget class="QLineEdit" name="lineEditHistoryData"/> |
|
73 |
</item> |
|
61 | 74 |
<item row="3" column="4"> |
62 | 75 |
<widget class="QPushButton" name="pushButtonRevNoArea"> |
63 | 76 |
<property name="maximumSize"> |
... | ... | |
71 | 84 |
</property> |
72 | 85 |
</widget> |
73 | 86 |
</item> |
74 |
<item row="4" column="0"> |
|
75 |
<widget class="QLabel" name="label_4"> |
|
87 |
<item row="0" column="0"> |
|
88 |
<widget class="QLabel" name="label_6"> |
|
89 |
<property name="font"> |
|
90 |
<font> |
|
91 |
<weight>75</weight> |
|
92 |
<bold>true</bold> |
|
93 |
</font> |
|
94 |
</property> |
|
76 | 95 |
<property name="text"> |
77 |
<string>Drawing No : </string>
|
|
96 |
<string>Drawing</string> |
|
78 | 97 |
</property> |
79 | 98 |
</widget> |
80 | 99 |
</item> |
81 |
<item row="1" column="0"> |
|
82 |
<widget class="QLabel" name="label"> |
|
100 |
<item row="0" column="1"> |
|
101 |
<widget class="QLineEdit" name="lineEditDrawing"/> |
|
102 |
</item> |
|
103 |
<item row="5" column="0"> |
|
104 |
<widget class="QLabel" name="label_7"> |
|
83 | 105 |
<property name="text"> |
84 |
<string>Note : </string> |
|
106 |
<string>Unit : </string> |
|
107 |
</property> |
|
108 |
</widget> |
|
109 |
</item> |
|
110 |
<item row="4" column="0"> |
|
111 |
<widget class="QLabel" name="label_4"> |
|
112 |
<property name="text"> |
|
113 |
<string>Drawing No : </string> |
|
85 | 114 |
</property> |
86 | 115 |
</widget> |
87 | 116 |
</item> |
... | ... | |
104 | 133 |
</property> |
105 | 134 |
</widget> |
106 | 135 |
</item> |
107 |
<item row="2" column="4"> |
|
108 |
<widget class="QPushButton" name="pushButtonHistoryDataArea"> |
|
136 |
<item row="2" column="0"> |
|
137 |
<widget class="QLabel" name="label_2"> |
|
138 |
<property name="text"> |
|
139 |
<string>History Data : </string> |
|
140 |
</property> |
|
141 |
</widget> |
|
142 |
</item> |
|
143 |
<item row="5" column="1"> |
|
144 |
<widget class="QLineEdit" name="lineEditUnitArea"/> |
|
145 |
</item> |
|
146 |
<item row="1" column="0"> |
|
147 |
<widget class="QLabel" name="label"> |
|
148 |
<property name="text"> |
|
149 |
<string>Note : </string> |
|
150 |
</property> |
|
151 |
</widget> |
|
152 |
</item> |
|
153 |
<item row="4" column="1"> |
|
154 |
<widget class="QLineEdit" name="lineEditDrawingNo"/> |
|
155 |
</item> |
|
156 |
<item row="4" column="4"> |
|
157 |
<widget class="QPushButton" name="pushButtonDrawingNoArea"> |
|
109 | 158 |
<property name="maximumSize"> |
110 | 159 |
<size> |
111 | 160 |
<width>24</width> |
... | ... | |
117 | 166 |
</property> |
118 | 167 |
</widget> |
119 | 168 |
</item> |
120 |
<item row="4" column="1"> |
|
121 |
<widget class="QLineEdit" name="lineEditDrawingNo"/> |
|
122 |
</item> |
|
123 |
<item row="4" column="4"> |
|
124 |
<widget class="QPushButton" name="pushButtonDrawingNoArea"> |
|
169 |
<item row="0" column="4"> |
|
170 |
<widget class="QPushButton" name="pushButtonDrawingArea"> |
|
125 | 171 |
<property name="maximumSize"> |
126 | 172 |
<size> |
127 | 173 |
<width>24</width> |
... | ... | |
133 | 179 |
</property> |
134 | 180 |
</widget> |
135 | 181 |
</item> |
136 |
<item row="3" column="0"> |
|
137 |
<widget class="QLabel" name="label_3"> |
|
182 |
<item row="0" column="5"> |
|
183 |
<widget class="QPushButton" name="pushButtonDelDrawingArea"> |
|
184 |
<property name="maximumSize"> |
|
185 |
<size> |
|
186 |
<width>24</width> |
|
187 |
<height>16777215</height> |
|
188 |
</size> |
|
189 |
</property> |
|
138 | 190 |
<property name="text"> |
139 |
<string>Rev. No : </string>
|
|
191 |
<string>-</string>
|
|
140 | 192 |
</property> |
141 | 193 |
</widget> |
142 | 194 |
</item> |
143 |
<item row="2" column="0"> |
|
144 |
<widget class="QLabel" name="label_2"> |
|
195 |
<item row="1" column="5"> |
|
196 |
<widget class="QPushButton" name="pushButtonDelNoteArea"> |
|
197 |
<property name="maximumSize"> |
|
198 |
<size> |
|
199 |
<width>24</width> |
|
200 |
<height>16777215</height> |
|
201 |
</size> |
|
202 |
</property> |
|
145 | 203 |
<property name="text"> |
146 |
<string>History Data : </string>
|
|
204 |
<string>-</string>
|
|
147 | 205 |
</property> |
148 | 206 |
</widget> |
149 | 207 |
</item> |
150 |
<item row="2" column="1"> |
|
151 |
<widget class="QLineEdit" name="lineEditHistoryData"/> |
|
208 |
<item row="2" column="5"> |
|
209 |
<widget class="QPushButton" name="pushButtonDelHistoryDataArea"> |
|
210 |
<property name="maximumSize"> |
|
211 |
<size> |
|
212 |
<width>24</width> |
|
213 |
<height>16777215</height> |
|
214 |
</size> |
|
215 |
</property> |
|
216 |
<property name="text"> |
|
217 |
<string>-</string> |
|
218 |
</property> |
|
219 |
</widget> |
|
152 | 220 |
</item> |
153 |
<item row="0" column="0">
|
|
154 |
<widget class="QLabel" name="label_6">
|
|
155 |
<property name="font">
|
|
156 |
<font>
|
|
157 |
<weight>75</weight>
|
|
158 |
<bold>true</bold>
|
|
159 |
</font>
|
|
221 |
<item row="3" column="5">
|
|
222 |
<widget class="QPushButton" name="pushButtonDelRevNoArea">
|
|
223 |
<property name="maximumSize">
|
|
224 |
<size>
|
|
225 |
<width>24</width>
|
|
226 |
<height>16777215</height>
|
|
227 |
</size>
|
|
160 | 228 |
</property> |
161 | 229 |
<property name="text"> |
162 |
<string>Drawing</string>
|
|
230 |
<string>-</string>
|
|
163 | 231 |
</property> |
164 | 232 |
</widget> |
165 | 233 |
</item> |
166 |
<item row="0" column="1"> |
|
167 |
<widget class="QLineEdit" name="lineEditDrawing"/> |
|
234 |
<item row="4" column="5"> |
|
235 |
<widget class="QPushButton" name="pushButtonDelDrawingNoArea"> |
|
236 |
<property name="maximumSize"> |
|
237 |
<size> |
|
238 |
<width>25</width> |
|
239 |
<height>16777215</height> |
|
240 |
</size> |
|
241 |
</property> |
|
242 |
<property name="text"> |
|
243 |
<string>-</string> |
|
244 |
</property> |
|
245 |
</widget> |
|
168 | 246 |
</item> |
169 |
<item row="0" column="4">
|
|
170 |
<widget class="QPushButton" name="pushButtonDrawingArea">
|
|
247 |
<item row="5" column="5">
|
|
248 |
<widget class="QPushButton" name="pushButtonDelUnitArea">
|
|
171 | 249 |
<property name="maximumSize"> |
172 | 250 |
<size> |
173 | 251 |
<width>24</width> |
... | ... | |
175 | 253 |
</size> |
176 | 254 |
</property> |
177 | 255 |
<property name="text"> |
178 |
<string>...</string>
|
|
256 |
<string>-</string>
|
|
179 | 257 |
</property> |
180 | 258 |
</widget> |
181 | 259 |
</item> |
DTI_PID/DTI_PID/tesseract_ocr_module.py | ||
---|---|---|
78 | 78 |
conf = '--psm 6 -c tessedit_char_whitelist=' + conf |
79 | 79 | |
80 | 80 |
docData = AppDocData.instance() |
81 |
oCRLang = docData.getCurrentProject().getName() if existTrainedData() else 'eng' |
|
81 |
oCRLang = docData.OCRData#docData.getCurrentProject().getName() if existTrainedData() else 'eng'
|
|
82 | 82 | |
83 | 83 |
configs = docData.getConfigs('Text Size', 'Min Text Size') |
84 | 84 |
minSize = int(configs[0].value) if 1 == len(configs) else 30 |
... | ... | |
254 | 254 |
if ocrData: |
255 | 255 |
print(ocrData) |
256 | 256 | |
257 |
return img |
|
258 | ||
259 |
''' |
|
260 |
@brief Get Text info in Symbol (Instrumentation, OPC, etc...) |
|
261 |
@author Jeongwoo |
|
262 |
@date 2018.05.04 |
|
263 |
@history 2018.05.09 Jeongwoo Check split text' length |
|
264 |
2018.06.14 Jeongwoo Add try-except. If exception occured, return None |
|
265 |
2018.06.19 Jeongwoo Move text size check if-statement |
|
266 |
2018.06.20 Jeongwoo Remove variable [lastCharHeight] / Change variable [cey], [ch] / Change method to calculate text line height |
|
267 |
2018.10.19 euisung verifing doesn't used |
|
268 |
''' |
|
269 |
''' |
|
270 |
def getTextInfoInSymbol(img, startPoint, flag = FLAG_IMAGE_TO_BOXES, conf = DEFAULT_CONF): |
|
271 |
try: |
|
272 |
docData = AppDocData.instance() |
|
273 |
configs = docData.getConfigs('Text Size', 'Min Text Size') |
|
274 |
minSize = int(configs[0].value) if 1 == len(configs) else self.ui.minTextSizeSpinBox.setValue(30) |
|
275 |
configs = docData.getConfigs('Text Size', 'Max Text Size') |
|
276 |
maxSize = int(configs[0].value) if 1 == len(configs) else self.ui.maxTextSizeSpinBox.setValue(60) |
|
277 | ||
278 |
im = Image.fromarray(img) |
|
279 |
imgWidth = im.width |
|
280 |
imgHeight = im.height |
|
281 |
textInfoList = [] |
|
282 | ||
283 |
WHITE_LIST_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-" |
|
284 |
MIN_TEXT_SIZE = 10 |
|
285 | ||
286 |
boundaryOcrData = pytesseract.image_to_boxes(im, config=conf, lang='eng') |
|
287 |
textGroupIndex = 0 |
|
288 | ||
289 |
lastRT = (-1, -1) |
|
290 |
tempText = '' |
|
291 |
charWidth = -1 |
|
292 |
charHeight = -1 |
|
293 |
lineSp = (-1, -1) |
|
294 |
lineRect = None |
|
295 |
for index in range(len(boundaryOcrData.split('\n'))): |
|
296 |
data = boundaryOcrData.split('\n')[index] |
|
297 |
sData = data.split(' ') |
|
298 |
if len(sData) >= 5: |
|
299 |
char = sData[0] |
|
300 | ||
301 |
if WHITE_LIST_CHARS.find(char) >= 0: |
|
302 |
csx = int(sData[1]) |
|
303 |
csy = imgHeight - int(sData[4]) |
|
304 |
cex = int(sData[3]) |
|
305 |
cey = imgHeight - int(sData[2]) |
|
306 |
cw = cex - csx |
|
307 |
ch = abs(cey - csy) |
|
308 | ||
309 |
charWidth = max(charWidth, cw) |
|
310 |
charHeight = max(charHeight, ch) |
|
311 |
currentRect = None |
|
312 |
if lastRT != (-1, -1): |
|
313 |
currentRect = QRect(csx, csy, csx + cw, csy + ch) |
|
314 |
if lastRT == (-1, -1) and lineRect is None: |
|
315 |
tempText = tempText + char |
|
316 |
lastRT = (csx+cw, csy) |
|
317 |
lineSp = (csx, csy) |
|
318 |
lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], charHeight) |
|
319 |
elif (lineRect is not None and currentRect is not None) and lineRect.intersects(currentRect): |
|
320 |
tempText = tempText + char |
|
321 |
lastRT = (csx+cw, min(lineSp[1], csy)) |
|
322 |
lineSp = (lineSp[0], min(lineSp[1], csy)) |
|
323 |
lineHeight = max(max(lineRect.height(), abs(cey - lineSp[1])), abs((lineRect.y()+lineRect.height()) - lineSp[1])) |
|
324 |
lineRect.setX(lineSp[0]) |
|
325 |
lineRect.setY(lineSp[1]) |
|
326 |
lineRect.setHeight(lineHeight) |
|
327 |
else: |
|
328 |
# Save previous line |
|
329 |
if lineRect.height() >= minSize and lineRect.height() <= maxSize: |
|
330 |
prevLineText = ti.TextInfo(tempText, startPoint[0]+lineSp[0], startPoint[1]+lineSp[1], lastRT[0] - lineSp[0], lineRect.height(), 0) |
|
331 |
textInfoList.append(prevLineText) |
|
332 |
textGroupIndex = textGroupIndex + 1 |
|
333 | ||
334 |
# Start new line |
|
335 |
tempText = char |
|
336 |
charWidth = cw |
|
337 |
charHeight = ch |
|
338 |
lastRT = (csx + cw, csy) |
|
339 |
lineSp = (csx, csy) |
|
340 |
lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], ch) |
|
341 | ||
342 |
if not (len(textInfoList) > textGroupIndex) and (tempText is not None and len(tempText) > 0): |
|
343 |
if lineRect.height() >= minSize and lineRect.height() <= maxSize: |
|
344 |
textInfo = ti.TextInfo(tempText, startPoint[0]+lineSp[0], startPoint[1]+lineSp[1], lastRT[0] - lineSp[0], lineRect.height(), 0) |
|
345 |
if textInfo not in textInfoList: |
|
346 |
textInfoList.append(textInfo) |
|
347 |
else: |
|
348 |
return None |
|
349 | ||
350 |
return textInfoList |
|
351 |
except Exception as ex: |
|
352 |
return None |
|
353 |
''' |
|
354 |
''' |
|
355 |
@brief Get info about each character |
|
356 |
@author Jeongwoo |
|
357 |
@date 2018.05.03 |
|
358 |
@history 2018.05.09 Jeongwoo Check split text' length |
|
359 |
2018.06.20 Jeongwoo Remove variable [lastCharHeight] / Change variable [cey], [ch] |
|
360 |
2018.10.19 euisung verifing doesn't used |
|
361 |
''' |
|
362 |
''' |
|
363 |
def getCharactersInfo(img, startPoint, flag = FLAG_IMAGE_TO_BOXES, conf = DEFAULT_CONF): |
|
364 |
docData = AppDocData.instance() |
|
365 |
configs = docData.getConfigs('Text Size', 'Min Text Size') |
|
366 |
minSize = int(configs[0].value) if 1 == len(configs) else self.ui.minTextSizeSpinBox.setValue(30) |
|
367 |
configs = docData.getConfigs('Text Size', 'Max Text Size') |
|
368 |
maxSize = int(configs[0].value) if 1 == len(configs) else self.ui.maxTextSizeSpinBox.setValue(60) |
|
369 | ||
370 |
im = Image.fromarray(img) |
|
371 |
imgWidth = im.width |
|
372 |
imgHeight = im.height |
|
373 |
textInfoList = [] |
|
374 |
boundaryOcrData = pytesseract.image_to_boxes(im, config=conf, lang='eng') |
|
375 | ||
376 |
for index in range(len(boundaryOcrData.split('\n'))): |
|
377 |
data = boundaryOcrData.split('\n')[index] |
|
378 |
sData = data.split(' ') |
|
379 |
if len(sData) >= 5: |
|
380 |
char = sData[0] |
|
381 |
csx = int(sData[1]) |
|
382 |
csy = imgHeight - int(sData[4]) |
|
383 |
cex = int(sData[3]) |
|
384 |
cey = imgHeight - int(sData[2]) |
|
385 |
cw = cex - csx |
|
386 |
ch = abs(cey - csy) |
|
387 | ||
388 |
if not(ch >= minSize and ch <= maxSize): |
|
389 |
continue |
|
390 | ||
391 |
textInfoList.append(ti.TextInfo(char, startPoint[0]+csx, startPoint[1]+csy, cw, ch, 0)) |
|
392 | ||
393 |
return textInfoList |
|
394 |
''' |
|
257 |
return img |
DTI_PID/PDF_TO_IMAGE/ConvertImage.cs | ||
---|---|---|
26 | 26 | |
27 | 27 |
private void Btn_LoadPDF_Click(object sender, EventArgs e) |
28 | 28 |
{ |
29 |
OpenFileDialog OFD = new OpenFileDialog(); |
|
30 |
OFD.Filter = "PDF Files (.PDF)|*.PDF"; |
|
29 |
OpenFileDialog OFD = new OpenFileDialog() { Filter = "PDF Files (.PDF)|*.PDF" }; |
|
31 | 30 |
if (OFD.ShowDialog() == DialogResult.OK) |
32 | 31 |
{ |
33 | 32 |
string pdfpath = OFD.FileName; |
... | ... | |
129 | 128 | |
130 | 129 |
private void Btn_Convert_Click(object sender, EventArgs e) |
131 | 130 |
{ |
132 | ||
133 | 131 |
int iDpi = 0; |
134 | 132 |
if(Txt_PDFPath.Text != "" && int.TryParse(Combo_DPI.Text,out iDpi) == true) |
135 | 133 |
{ |
... | ... | |
145 | 143 |
pdftron.PDFNet.Initialize("daelim.co.kr(Doftech Corp):CPU:2::W:AMC(20120315):EF6E886F25A414FFB5F8C1F2999CF2DA33DC6C5164315BAF7011B87AF0FA"); |
146 | 144 |
using (PDFDoc doc = new PDFDoc(Txt_PDFPath.Text)) |
147 | 145 |
{ |
148 | ||
149 | 146 |
ImageCodecInfo DefaultImageCodecInfo = GetEncoderInfo("image/png"); |
150 | 147 |
EncoderParameters DefaultEncoderParameters = new EncoderParameters(2); |
151 | 148 |
System.Drawing.Imaging.Encoder QualityEncoder = System.Drawing.Imaging.Encoder.Quality; |
... | ... | |
192 | 189 |
|
193 | 190 |
var rotation = doc.GetPage(i).GetRotation(); |
194 | 191 |
draw.SetImageSize(widthData, heightData, true); |
195 |
sFileName = pagePath + "_" + widthData + "_" + heightData + ".jpeg";
|
|
192 |
sFileName = pagePath + "_" + widthData + "_" + heightData + ".png";
|
|
196 | 193 |
} |
197 | 194 |
draw.SetAntiAliasing(false); |
198 | 195 |
draw.SetImageSmoothing(false); |
... | ... | |
206 | 203 |
using (Bitmap bmpImage = new Bitmap(_savestream)) |
207 | 204 |
{ |
208 | 205 |
ObjSet objset = new ObjSet(); |
209 |
Obj jbig2_hint = objset.CreateName("jpeg");
|
|
210 |
bmpImage.Save(sFileName); |
|
206 |
Obj jbig2_hint = objset.CreateName("png");
|
|
207 |
bmpImage.Save(sFileName, ImageFormat.Png);
|
|
211 | 208 |
bmpImage.Dispose(); |
212 | 209 |
// Do something with the Bitmap object |
213 | 210 |
} |
214 |
// newBmp_ = new Bitmap(_savestream); |
|
215 |
|
|
216 | 211 |
} |
217 | 212 |
catch (Exception ex) |
218 | 213 |
{ |
... | ... | |
236 | 231 |
} |
237 | 232 |
#endregion |
238 | 233 |
} |
239 | ||
240 | ||
241 | 234 |
} |
242 | 235 |
else |
243 | 236 |
{ |
DTI_PID/PDF_TO_IMAGE/PDF_TO_IMAGE.csproj | ||
---|---|---|
25 | 25 |
<Prefer32Bit>false</Prefer32Bit> |
26 | 26 |
</PropertyGroup> |
27 | 27 |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
28 |
<PlatformTarget>AnyCPU</PlatformTarget>
|
|
28 |
<PlatformTarget>x86</PlatformTarget>
|
|
29 | 29 |
<DebugType>pdbonly</DebugType> |
30 | 30 |
<Optimize>true</Optimize> |
31 | 31 |
<OutputPath>..\DTI_PID\bin64\</OutputPath> |
32 | 32 |
<DefineConstants>TRACE</DefineConstants> |
33 | 33 |
<ErrorReport>prompt</ErrorReport> |
34 | 34 |
<WarningLevel>4</WarningLevel> |
35 |
<Prefer32Bit>false</Prefer32Bit>
|
|
35 |
<Prefer32Bit>true</Prefer32Bit>
|
|
36 | 36 |
</PropertyGroup> |
37 | 37 |
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> |
38 | 38 |
<DebugSymbols>true</DebugSymbols> |
내보내기 Unified diff