프로젝트

일반

사용자정보

개정판 53953154

ID53953154aa836032907794c7f8779e087ffd2a47
상위 57e3d9dc
하위 92420d27

함의성이(가) 6년 이상 전에 추가함

issue #665: training data path test

차이점 보기:

DTI_PID/DTI_PID/TrainingEditorDialog.py
23 23
        self.trainingImgPath = trainingImgPath
24 24
        self.trainingBoxPath = trainingBoxPath
25 25
        self.boundaryOcrData = boundaryOcrData
26
        self.isChanged = False
26 27

  
27 28
        appDocData = AppDocData.instance()
28 29
        project = appDocData.getCurrentProject()
......
119 120
        @date       2018.10.17
120 121
    '''
121 122
    def pushButtonAddClicked(self):
123
        self.isChanged = True
122 124
        items = self.graphicsViewTrainingDrawing.scene.selectedItems()
123 125
        allItems = self.graphicsViewTrainingDrawing.scene.items()
124 126
        totalWidth = 0
......
152 154
        @date       2018.10.17
153 155
    '''
154 156
    def pushButtonDeleteClicked(self):
157
        self.isChanged = True
155 158
        items = self.graphicsViewTrainingDrawing.scene.selectedItems()
156 159
        for item in items:
157 160
            item.transfer.onRemoved.emit(item)
......
162 165
        @date       2018.10.17
163 166
    '''
164 167
    def pushButtonChangeClicked(self):
168
        self.isChanged = True
165 169
        items = self.graphicsViewTrainingDrawing.scene.selectedItems()
166 170
        if len(items) is not 1:
167 171
            return
......
173 177
        @date       2018.10.17
174 178
    '''
175 179
    def pushButtonCancelClicked(self):
176
        QDialog.reject(self)
180
        if self.isChanged:
181
            reply = QMessageBox.question(self, 'Continue?', '변경사항이 저장되지 않았을 수 있습니다.', QMessageBox.Ignore, QMessageBox.Cancel)
182
            if reply == QMessageBox.Ignore:
183
                QDialog.reject(self)
184
        else:
185
            QDialog.reject(self)
177 186

  
178 187
    '''
179 188
        @brief      save box item by button click
......
198 207
        fw = open(self.trainingBoxPath, 'w')
199 208
        fw.write(outBox)
200 209
        fw.close()
210
        self.isChanged = False
201 211

  
202 212
    '''
203 213
        @brief      chane box item's rect by button click
......
205 215
        @date       2018.10.16
206 216
    '''
207 217
    def spinBoxChangedEvent(self, event):
218
        self.isChanged = True
208 219
        items = self.graphicsViewTrainingDrawing.scene.selectedItems()
209 220
        if (len(items) is not 1) or self.spinBoxFlag:
210 221
            return
211
        
212 222
        spinBoxName = self.sender().objectName()
213 223
        rect = items[0].rect()
214 224
        bound = self.graphicsViewZoomDrawing.scene().items()[0]
DTI_PID/DTI_PID/TrainingImageListDialog.py
1 1
import sys
2
import os, time
2
import os, time, subprocess
3 3
from PyQt5.QtCore import *
4 4
from PyQt5.QtGui import *
5 5
from PyQt5.QtWidgets import *
......
11 11

  
12 12
pytesseract.pytesseract.tesseract_cmd = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Tesseract-OCR', 'tesseract.exe')
13 13
tesseract_cmd = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Tesseract-OCR', 'tesseract.exe')
14
unicharset_extractor_cmd = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Tesseract-OCR', 'unicharset_extractor.exe')
15
set_unicharset_properties_cmd = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Tesseract-OCR', 'set_unicharset_properties.exe')
14 16

  
15 17
DEFAULT_CONF = """
16 18
    --psm 6 -c tessedit_char_whitelist=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-~.,/!@#$%&*(){}[]<>:;+=?\\"\\'
17 19
"""
18 20

  
19 21
class QTrainingImageListDialog(QDialog):
20

  
21 22
    trainingDataNumber = 0
22 23

  
23 24
    def __init__(self, parent):
......
30 31
        self.ui.tableWidgetList.setSelectionMode(QAbstractItemView.SingleSelection) 
31 32
        self.ui.tableWidgetList.setColumnCount(3)
32 33

  
33
        docData = AppDocData.instance()
34
        dataList = docData.getTrainingFileList()
35
        imgCount = 0
36
        for data in dataList:
37
            if data.find('.png') is not -1:
38
                imgCount += 1            
39
        self.ui.tableWidgetList.setRowCount(imgCount)
40

  
41 34
        ## column header 명 설정
42
        headerLabel = docData.getCurrentProject().getName()
43
        self.ui.tableWidgetList.setHorizontalHeaderLabels(['No.', headerLabel, '작업 상태'])
35
        #headerLabel = docData.getCurrentProject().getName()
36
        self.ui.tableWidgetList.setHorizontalHeaderLabels(['No.', '이미지 목록', '박스 작업 상태'])
44 37
        self.ui.tableWidgetList.horizontalHeaderItem(1).setToolTip('도면 이름') # header tooltip
45 38
        self.ui.tableWidgetList.horizontalHeaderItem(2).setToolTip('작업 상태') # header tooltip
46 39
        self.ui.tableWidgetList.horizontalHeaderItem(1).setSizeHint(QSize(30, 30))
......
49 42
        self.ui.tableWidgetList.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)
50 43
        self.ui.tableWidgetList.setEditTriggers(QAbstractItemView.NoEditTriggers)
51 44
        
45
        self.listUpdate()
46

  
47
        # connect signals and slots
48
        self.ui.tableWidgetList.cellDoubleClicked.connect(self.listCellDoubleClicked)
49
        self.ui.pushButtonBox.clicked.connect(self.pushButtonBoxClicked)
50
        self.ui.pushButtonMakeTrainingData.clicked.connect(self.makeTrainingDataClicked)
51
        self.ui.pushButtonImageDelete.clicked.connect(self.pushButtonImageDeleteClicked)
52
        self.ui.pushButtonBoxDelete.clicked.connect(self.pushButtonBoxDeleteClicked)
53
        self.ui.pushButtonClose.clicked.connect(self.pushButtonCloseClicked)
54

  
55
    '''
56
        @brief      close dialog by button click
57
        @author     euisung
58
        @date       2018.10.18
59
    '''
60
    def pushButtonCloseClicked(self):
61
        QDialog.reject(self)
62

  
63
    '''
64
        @brief      update image list
65
        @author     euisung
66
        @date       2018.10.18
67
    '''
68
    def listUpdate(self):
69
        appDocData = AppDocData.instance()
70
        project = appDocData.getCurrentProject()
71
        dataList = appDocData.getTrainingFileList()
72
        imgCount = 0
73
        for data in dataList:
74
            if data.find('.png') is not -1:
75
                imgCount += 1            
76
        self.ui.tableWidgetList.setRowCount(imgCount)
77
        
52 78
        row = 0
53 79
        for data in dataList:
54 80
            if data.find('.png') is not -1:
55 81
                self.ui.tableWidgetList.setItem(row, 0, QTableWidgetItem(str(row + 1)))
56 82
                self.ui.tableWidgetList.setItem(row, 1, QTableWidgetItem(data))
57
                allDataList = docData.getTrainingFileList()
83
                allDataList = appDocData.getTrainingFileList()
58 84
                for adata in allDataList:
59 85
                    boxName = data.replace('.png', '.boxS')
60 86
                    if adata.find(boxName) is not -1:
61
                        appDocData = AppDocData.instance()
62
                        project = appDocData.getCurrentProject()
63 87
                        boxPath = os.path.join(project.getTrainingFilePath(), boxName)
64 88
                        modifiedTime = time.ctime(os.path.getmtime(boxPath))
65 89
                        self.ui.tableWidgetList.setItem(row, 2, QTableWidgetItem(modifiedTime))
90
                        break
91
                    else:
92
                        self.ui.tableWidgetList.setItem(row, 2, QTableWidgetItem(''))
66 93
                row += 1
67 94

  
68
        # connect signals and slots
69
        self.ui.tableWidgetList.cellDoubleClicked.connect(self.listCellDoubleClicked)
70
        self.ui.pushButtonBox.clicked.connect(self.pushButtonBoxClicked)
71
        self.ui.pushButtonMakeTrainingData.clicked.connect(self.makeTrainingDataClicked)
95
    '''
96
        @brief      delete training box only by button click
97
        @author     euisung
98
        @date       2018.10.18
99
    '''
100
    def pushButtonBoxDeleteClicked(self):
101
        try:
102
            row = self.ui.tableWidgetList.selectedIndexes()[0].row()
103
            col = self.ui.tableWidgetList.selectedIndexes()[0].column()
104
            drawingName = self.ui.tableWidgetList.item(row, 1).text()
105
            boxDate = self.ui.tableWidgetList.item(row, 2).text()
106
            if boxDate == '':
107
                return
108
        except Exception as ex:
109
            pass
110
        try:
111
            reply = QMessageBox.question(self, 'Continue?', '박스 작업을 삭제하시겠습니까? ', QMessageBox.Yes, QMessageBox.Cancel)
112
            if reply == QMessageBox.Yes:
113
                appDocData = AppDocData.instance()
114
                project = appDocData.getCurrentProject()
115

  
116
                drawingPath = os.path.join(project.getTrainingFilePath(), drawingName)
117
                boxName = drawingPath.replace('.png', '.boxS')
118
                if os.path.isfile(boxName):
119
                    os.remove(boxName)
120
                self.listUpdate()
121
        except Exception as ex:
122
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
123

  
124
    '''
125
        @brief      delete training image and box by button click
126
        @author     euisung
127
        @date       2018.10.18
128
    '''
129
    def pushButtonImageDeleteClicked(self):
130
        try:
131
            row = self.ui.tableWidgetList.selectedIndexes()[0].row()
132
            col = self.ui.tableWidgetList.selectedIndexes()[0].column()
133
            drawingName = self.ui.tableWidgetList.item(row, 1).text()
134
        except Exception as ex:
135
            pass
136
        try:
137
            reply = QMessageBox.question(self, 'Continue?', '이미지를 삭제하시겠습니까? ', QMessageBox.Yes, QMessageBox.Cancel)
138
            if reply == QMessageBox.Yes:
139
                appDocData = AppDocData.instance()
140
                project = appDocData.getCurrentProject()
141

  
142
                drawingPath = os.path.join(project.getTrainingFilePath(), drawingName)
143
                if os.path.isfile(drawingPath):
144
                    os.remove(drawingPath)
145
                boxName = drawingPath.replace('.png', '.boxS')
146
                if os.path.isfile(boxName):
147
                    os.remove(boxName)
148
                self.listUpdate()
149
        except Exception as ex:
150
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
72 151

  
73 152
    '''
74 153
        @brief      make training data by button click
......
184 263
            trainingImgPath = os.path.join(project.getTrainingFilePath(), 'seed.seedF.exp0.tif')
185 264
            trainingBoxPath = os.path.join(project.getTrainingFilePath(), 'seed.seedF.exp0.box')
186 265
            trainingTextImg.save(trainingImgPath, compression='tiff_lzw')
187
            fw = open(trainingBoxPath, 'w') #파일 있으면 새로 만듬 예외 처리 안됨, 임시
266
            fw = open(trainingBoxPath, 'w', encoding='utf8')
188 267
            fw.write(outBox)
189 268
            fw.close()
269

  
270
            # 실제 적용 데이터 생성
271
            trainCmd = tesseract_cmd + ' ' + trainingImgPath + ' ' + trainingBoxPath.replace('.box', '') + ' nobatch box.train'
272
            subprocess.call(trainCmd, shell = True)
273

  
274
            unicharsetExtractorCmd = unicharset_extractor_cmd + ' ' + trainingBoxPath
275
            subprocess.call(unicharsetExtractorCmd, shell = True)
276

  
277
            #setUnicharsetPropertiesCmd = set_unicharset_properties_cmd + 
278
            
190 279
 
191 280
        except Exception as ex:
192 281
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
......
215 304
            
216 305
            boxName = drawingName.replace('.png', '.boxS')
217 306

  
218
            docData = AppDocData.instance()
219
            dataList = docData.getTrainingFileList()
307
            dataList = appDocData.getTrainingFileList()
220 308
            isBoxFile = False
221 309
            for data in dataList:
222 310
                if data.find(boxName) is not -1:
......
232 320
        try:
233 321
            dialog = QTrainingEditorDialog(self, drawingPath, trainingBoxPath, boundaryOcrData)
234 322
            dialog.exec_()
235
            
236
            docData = AppDocData.instance()
237
            dataList = docData.getTrainingFileList()
238
            imgCount = 0
239
            for data in dataList:
240
                if data.find('.png') is not -1:
241
                    imgCount += 1            
242
            self.ui.tableWidgetList.setRowCount(imgCount)
243
        
244
            row = 0
245
            for data in dataList:
246
                if data.find('.png') is not -1:
247
                    self.ui.tableWidgetList.setItem(row, 0, QTableWidgetItem(str(row + 1)))
248
                    self.ui.tableWidgetList.setItem(row, 1, QTableWidgetItem(data))
249
                    allDataList = docData.getTrainingFileList()
250
                    for adata in allDataList:
251
                        boxName = data.replace('.png', '.boxS')
252
                        if adata.find(boxName) is not -1:
253
                            appDocData = AppDocData.instance()
254
                            project = appDocData.getCurrentProject()
255
                            boxPath = os.path.join(project.getTrainingFilePath(), boxName)
256
                            modifiedTime = time.ctime(os.path.getmtime(boxPath))
257
                            self.ui.tableWidgetList.setItem(row, 2, QTableWidgetItem(modifiedTime))
258
                    row += 1
259

  
323
            self.listUpdate()
260 324
        except Exception as ex:
261 325
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
262 326

  
......
274 338
            self.listCellDoubleClicked(row, col)
275 339
        except Exception as ex:
276 340
            pass
277
        return
278 341

  
279 342
    '''
280 343
        @brief      make Box data by cell double click
DTI_PID/DTI_PID/TrainingImageList_UI.py
1 1
# -*- coding: utf-8 -*-
2 2

  
3
# Form implementation generated from reading ui file '.\UI\TrainingImageList.ui'
3
# Form implementation generated from reading ui file './UI/TrainingImageList.ui'
4 4
#
5 5
# Created by: PyQt5 UI code generator 5.11.2
6 6
#
......
20 20
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
21 21
        self.verticalLayout_3 = QtWidgets.QVBoxLayout()
22 22
        self.verticalLayout_3.setObjectName("verticalLayout_3")
23
        self.label_2 = QtWidgets.QLabel(TraingingImageListDialog)
24
        self.label_2.setAlignment(QtCore.Qt.AlignCenter)
25
        self.label_2.setObjectName("label_2")
26
        self.verticalLayout_3.addWidget(self.label_2)
23
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
24
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
25
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
26
        self.horizontalLayout_4.addItem(spacerItem)
27
        self.pushButtonImageDelete = QtWidgets.QPushButton(TraingingImageListDialog)
28
        self.pushButtonImageDelete.setObjectName("pushButtonImageDelete")
29
        self.horizontalLayout_4.addWidget(self.pushButtonImageDelete)
30
        self.pushButtonBoxDelete = QtWidgets.QPushButton(TraingingImageListDialog)
31
        self.pushButtonBoxDelete.setAutoDefault(False)
32
        self.pushButtonBoxDelete.setObjectName("pushButtonBoxDelete")
33
        self.horizontalLayout_4.addWidget(self.pushButtonBoxDelete)
34
        self.verticalLayout_3.addLayout(self.horizontalLayout_4)
27 35
        self.tableWidgetList = QtWidgets.QTableWidget(TraingingImageListDialog)
28 36
        self.tableWidgetList.setColumnCount(1)
29 37
        self.tableWidgetList.setObjectName("tableWidgetList")
......
31 39
        self.tableWidgetList.verticalHeader().setVisible(False)
32 40
        self.verticalLayout_3.addWidget(self.tableWidgetList)
33 41
        self.pushButtonBox = QtWidgets.QPushButton(TraingingImageListDialog)
42
        self.pushButtonBox.setAutoDefault(False)
34 43
        self.pushButtonBox.setObjectName("pushButtonBox")
35 44
        self.verticalLayout_3.addWidget(self.pushButtonBox)
36 45
        self.pushButtonMakeTrainingData = QtWidgets.QPushButton(TraingingImageListDialog)
46
        self.pushButtonMakeTrainingData.setAutoDefault(False)
37 47
        self.pushButtonMakeTrainingData.setObjectName("pushButtonMakeTrainingData")
38 48
        self.verticalLayout_3.addWidget(self.pushButtonMakeTrainingData)
39 49
        self.horizontalLayout_2.addLayout(self.verticalLayout_3)
40 50
        self.verticalLayout.addLayout(self.horizontalLayout_2)
41 51
        self.horizontalLayout = QtWidgets.QHBoxLayout()
42 52
        self.horizontalLayout.setObjectName("horizontalLayout")
43
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
44
        self.horizontalLayout.addItem(spacerItem)
45
        self.pushButton_2 = QtWidgets.QPushButton(TraingingImageListDialog)
46
        self.pushButton_2.setObjectName("pushButton_2")
47
        self.horizontalLayout.addWidget(self.pushButton_2)
48
        self.pushButton = QtWidgets.QPushButton(TraingingImageListDialog)
49
        self.pushButton.setObjectName("pushButton")
50
        self.horizontalLayout.addWidget(self.pushButton)
53
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
54
        self.horizontalLayout.addItem(spacerItem1)
55
        self.pushButtonClose = QtWidgets.QPushButton(TraingingImageListDialog)
56
        self.pushButtonClose.setAutoDefault(False)
57
        self.pushButtonClose.setObjectName("pushButtonClose")
58
        self.horizontalLayout.addWidget(self.pushButtonClose)
51 59
        self.verticalLayout.addLayout(self.horizontalLayout)
52 60
        self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
53 61

  
......
57 65
    def retranslateUi(self, TraingingImageListDialog):
58 66
        _translate = QtCore.QCoreApplication.translate
59 67
        TraingingImageListDialog.setWindowTitle(_translate("TraingingImageListDialog", "Training Image List"))
60
        self.label_2.setText(_translate("TraingingImageListDialog", "List"))
68
        self.pushButtonImageDelete.setText(_translate("TraingingImageListDialog", "이미지 삭제"))
69
        self.pushButtonBoxDelete.setText(_translate("TraingingImageListDialog", "박스 작업 내역 삭제"))
61 70
        self.pushButtonBox.setText(_translate("TraingingImageListDialog", "문자 영역 수정"))
62 71
        self.pushButtonMakeTrainingData.setText(_translate("TraingingImageListDialog", "학습 데이터 생성"))
63
        self.pushButton_2.setText(_translate("TraingingImageListDialog", "PushButton"))
64
        self.pushButton.setText(_translate("TraingingImageListDialog", "PushButton"))
72
        self.pushButtonClose.setText(_translate("TraingingImageListDialog", "닫기"))
65 73

  
66 74

  
67 75
if __name__ == "__main__":
DTI_PID/DTI_PID/UI/TrainingImageList.ui
21 21
       <item>
22 22
        <layout class="QVBoxLayout" name="verticalLayout_3">
23 23
         <item>
24
          <widget class="QLabel" name="label_2">
25
           <property name="text">
26
            <string>List</string>
27
           </property>
28
           <property name="alignment">
29
            <set>Qt::AlignCenter</set>
30
           </property>
31
          </widget>
24
          <layout class="QHBoxLayout" name="horizontalLayout_4">
25
           <item>
26
            <spacer name="horizontalSpacer_2">
27
             <property name="orientation">
28
              <enum>Qt::Horizontal</enum>
29
             </property>
30
             <property name="sizeHint" stdset="0">
31
              <size>
32
               <width>40</width>
33
               <height>20</height>
34
              </size>
35
             </property>
36
            </spacer>
37
           </item>
38
           <item>
39
            <widget class="QPushButton" name="pushButtonImageDelete">
40
             <property name="text">
41
              <string>이미지 삭제</string>
42
             </property>
43
            </widget>
44
           </item>
45
           <item>
46
            <widget class="QPushButton" name="pushButtonBoxDelete">
47
             <property name="text">
48
              <string>박스 작업 내역 삭제</string>
49
             </property>
50
             <property name="autoDefault">
51
              <bool>false</bool>
52
             </property>
53
            </widget>
54
           </item>
55
          </layout>
32 56
         </item>
33 57
         <item>
34 58
          <widget class="QTableWidget" name="tableWidgetList">
......
46 70
           <property name="text">
47 71
            <string>문자 영역 수정</string>
48 72
           </property>
73
           <property name="autoDefault">
74
            <bool>false</bool>
75
           </property>
49 76
          </widget>
50 77
         </item>
51 78
         <item>
......
53 80
           <property name="text">
54 81
            <string>학습 데이터 생성</string>
55 82
           </property>
83
           <property name="autoDefault">
84
            <bool>false</bool>
85
           </property>
56 86
          </widget>
57 87
         </item>
58 88
        </layout>
......
75 105
        </spacer>
76 106
       </item>
77 107
       <item>
78
        <widget class="QPushButton" name="pushButton_2">
108
        <widget class="QPushButton" name="pushButtonClose">
79 109
         <property name="text">
80
          <string>PushButton</string>
110
          <string>닫기</string>
81 111
         </property>
82
        </widget>
83
       </item>
84
       <item>
85
        <widget class="QPushButton" name="pushButton">
86
         <property name="text">
87
          <string>PushButton</string>
112
         <property name="autoDefault">
113
          <bool>false</bool>
88 114
         </property>
89 115
        </widget>
90 116
       </item>

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)