프로젝트

일반

사용자정보

개정판 1b502652

ID1b5026526fe68e881d44709916cb181e964d764f
상위 d076a78e
하위 684578e1, d52b3462

김정우 이(가) 약 7년 전에 추가함

SymbolGenerator 수정 및 potrace를 이용한 svg파일 생성

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
90 90

  
91 91
        return symbolNametList
92 92

  
93
    '''
94
        @brief  delete added symbol data
95
    '''
96
    def deleteSymbol(self, dbPath, imagePath):
97
        ret = False
98
        try:
99
            conn = sqlite3.connect(dbPath)
100
            cursor = conn.cursor()
101
            sql = "DELETE FROM Symbol WHERE path = ?"
102
            try:
103
                cursor.execute(sql, (imagePath,))
104
                conn.commit()
105
                ret = True
106
            except Exception as ex:
107
                print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
108
                ret = False
109
        finally:
110
            conn.close()
111
            return (ret, imagePath)
112

  
93 113
    pass
DTI_PID/DTI_PID/Commands/ConnectionPointCommand.py
44 44
                clickedY = int(scenePos.y())
45 45
                
46 46
                if (clickedX >= 0 and clickedX <= width) and (clickedY >= 0 and clickedY <= height):
47
                    self.imageViewer.scene.addItem(self.imageViewer.scene.addEllipse(QRectF(scenePos.x() - 0.5, scenePos.y() - 0.5, 1, 1), QPen(QColor(0, 0, 255)), QBrush(QColor(0, 0, 255))))
47
                    self.imageViewer.scene.addItem(self.imageViewer.scene.addEllipse(QRectF(int(scenePos.x()) - 0.5, int(scenePos.y()) - 0.5, 1, 1), QPen(QColor(0, 0, 255)), QBrush(QColor(0, 0, 255))))
48 48
                    #self.isSelected = True
49 49
                    text = "{},{}".format(clickedX, clickedY)
50 50
                    self.connectionPointLineEdit.setText(text)
DTI_PID/DTI_PID/Commands/OriginalPointCommand.py
48 48
                    clickedY = int(scenePos.y())
49 49

  
50 50
                    if self.isOnImage(clickedX, clickedY):
51
                        self.imageViewer.scene.addItem(self.imageViewer.scene.addEllipse(QRectF(scenePos.x() - 0.5, scenePos.y() - 0.5, 1, 1), QPen(QColor(255, 0, 0)), QBrush(QColor(255, 0, 0))))
51
                        self.imageViewer.scene.addItem(self.imageViewer.scene.addEllipse(QRectF(int(scenePos.x()) - 0.5, int(scenePos.y()) - 0.5, 1, 1), QPen(QColor(255, 0, 0)), QBrush(QColor(255, 0, 0))))
52 52
                        self.isSelected = True
53 53
                        self.originalPointLineEdit.setText("{},{}".format(clickedX, clickedY))
54 54
                        self.imageViewer.isOriginalPointSelected = True
......
63 63
                coords = event.pos()
64 64
                if self.isOnImage(scenePos.x(), scenePos.y()):
65 65
                    self.showGuideline(scenePos)
66
                    self.originalPointLineEdit.setText("{},{}".format(scenePos.x(), scenePos.y()))
66
                    self.originalPointLineEdit.setText("{},{}".format(int(scenePos.x()), int(scenePos.y())))
67 67
                else:
68 68
                    self.showGuideline(self.initMinPoint)
69 69
                    self.originalPointLineEdit.setText("")
DTI_PID/DTI_PID/DTI_PID.py
795 795
            cv2.imwrite(os.path.dirname(os.path.realpath(__file__)) + "\\res\\Result\\result_fslo_rect_"+srcName+"_600dpi.png", src)
796 796

  
797 797
            ####### Potrace
798
            imgLineList = potrace.passpotrace(removedSymbolImgPath)
798
            #imgLineList = potrace.passpotrace(removedSymbolImgPath)
799
            imgLineList = []
799 800

  
800 801
            xmlPath = xg.writeXml(srcName, srcWidth, srcHeight, searchedSymbolList, textInfoList, imgLineList)
801 802
            res.append(xmlPath)
DTI_PID/DTI_PID/QSymbolEditorDialog.py
23 23

  
24 24
    def __init__(self, parent, image, project):
25 25
        QDialog.__init__(self, parent)
26

  
27 26
        self.image = image
28 27
        self.project = project
29 28
        self.ui = UI_SymbolEditor.Ui_Dialog()
......
35 34
        self.isAccepted = False
36 35
        self.dbHelper = SG_DbHelper.SG_DbHelper(self.project.getPath())
37 36

  
37
    '''
38
        @brief  Set up QtImageViewer and QImage
39
    '''
38 40
    def setupImageViewer(self):
39 41
        x = self.ui.imageViewContainer.x()
40 42
        y = self.ui.imageViewContainer.y()
......
54 56
        self.ui.imageView.setImage(image)
55 57
        self.ui.imageViewerContainerLayout.addWidget(self.ui.imageView)
56 58

  
59
    '''
60
        @brief  Set up Hand, Crop, ETC Tools
61
    '''
57 62
    def setupTools(self):
58 63
        self.ui.handButton.clicked.connect(self.handToolClickEvent)
59 64
        self.ui.penButton.clicked.connect(self.penToolClickEvent)
......
64 69
        self.ui.zoomButton.clicked.connect(self.zoomToolClickEvent)
65 70
        self.ui.initZoomButton.clicked.connect(self.zoomInitToolClickEvent)
66 71
        self.ui.guidelineCheckbox.stateChanged.connect(self.guidelineStateChangedEvent)
72
        #self.ui.additionalSymbolListWidget.keyPressEvent.connect(self.additionalSymbolListKeyPressEvent)
73
        #self.ui.connectionPointList.keyPressEvent.connect(self.additionalSymbolListKeyPressEvent)
67 74

  
75
    '''
76
        @brief  Init Forms with type and default values
77
    '''
68 78
    def initForms(self):
69 79
        self.ui.idLineEdit.setValidator(QRegExpValidator(QtCore.QRegExp("^[1-9]\d+$")))
70 80
        self.ui.thresholdLineEdit.setValidator(QRegExpValidator(QtCore.QRegExp("^[0-9]\d+$"))) # ([0-1]{1}[.])?[0-9]+
......
78 88
        self.initBaseSymbolComboBoxItems()
79 89
        self.initAdditionalSymbolComboBoxItems()
80 90
        
91
    '''
92
        @brief  Set data on forms, For modifying symbol
93
    '''
81 94
    def initContents(self):
82 95
        self.ui.targetDBLineEdit.setText(self.project.getPath()+'/db/ITI_PID.db')
83 96
        #self.ui.isOriginDetectComboBox
......
87 100
        #self.ui.defaultSymbolDirectionComboBox
88 101
        #self.ui.additionalSymbolComboBox
89 102

  
103
    '''
104
        @brief  Init ComboBox Items For DB Field [IsDetectOrigin]
105
    '''
90 106
    def initIsOriginDetectComboBoxItems(self):
91 107
        self.ui.isOriginDetectComboBox.addItem("원본 도면", 0)
92 108
        self.ui.isOriginDetectComboBox.addItem("텍스트 제거 도면", 1)
93 109

  
110
    '''
111
        @brief  Init ComboBox Items For DB Field [OcrOption]
112
    '''
94 113
    def initOcrOptionComboBoxItems(self):
95 114
        self.ui.ocrOptionComboBox.addItem("OCR 미적용", 0)
96 115
        self.ui.ocrOptionComboBox.addItem("일반 심볼", 1)
97 116
        self.ui.ocrOptionComboBox.addItem("Instrument 계통", 2)
98

  
117
        
118
    '''
119
        @brief  Init ComboBox Items For Direction of DB Field [additionalSymbol]
120
    '''
99 121
    def initDefaultSymbolDirectionComboBoxItems(self):
100
        self.ui.defaultSymbolDirectionComboBox.addItem("상", 0)
101
        self.ui.defaultSymbolDirectionComboBox.addItem("하", 2)
102
        self.ui.defaultSymbolDirectionComboBox.addItem("좌", 3)
103
        self.ui.defaultSymbolDirectionComboBox.addItem("우", 1)
104

  
122
        self.ui.defaultSymbolDirectionComboBox.addItem("UP", 0)
123
        self.ui.defaultSymbolDirectionComboBox.addItem("DOWN", 2)
124
        self.ui.defaultSymbolDirectionComboBox.addItem("LEFT", 3)
125
        self.ui.defaultSymbolDirectionComboBox.addItem("RIGHT", 1)
126
        
127
    '''
128
        @brief  Init ComboBox Items For DB Field [baseSymbol]
129
    '''
105 130
    def initBaseSymbolComboBoxItems(self):
106 131
        symbolNameList = AppDocData.instance().getSymbolNameList()
132
        symbolNameList.sort()
107 133
        symbolNameList.insert(0, "None")
108 134
        for name in symbolNameList:
109 135
            self.ui.baseSymbolComboBox.addItem(name)
110

  
136
            
137
    '''
138
        @brief  Init ComboBox Items For symbolName of DB Field [additionalSymbol]
139
    '''
111 140
    def initAdditionalSymbolComboBoxItems(self):
112 141
        symbolNameList = AppDocData.instance().getSymbolNameList()
142
        symbolNameList.sort()
113 143
        symbolNameList.insert(0, "None")
114 144
        for name in symbolNameList:
115 145
            self.ui.additionalSymbolComboBox.addItem(name)
116

  
146
    
147
    '''
148
        @brief  remove ConnectionPoint Circles (Using for loop)
149
    '''
117 150
    def removeConnectionPointCircles(self, circlePointList):
118 151
        for circlePoint in circlePointList:
119 152
            self.removeConnectionPointCircle(circlePoint)
120

  
153
            
154
    '''
155
        @brief  remove each ConnectionPoint Circle
156
    '''
121 157
    def removeConnectionPointCircle(self, circlePoint):
122 158
        self.ui.imageView.scene.removeItem(self.ui.imageView.scene.itemAt(QtCore.QPointF(int(circlePoint.x()), int(circlePoint.y())), QTransform()))
123

  
159
        
160
    '''
161
        @brief  Display this QDialog
162
    '''
124 163
    def showDialog(self):
125 164
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
126 165
        self.show()
127 166
        self.exec_()
128 167
        return self.isAccepted
129

  
168
    
169
    '''
170
        @brief  Using input [Name], make file name
171
                If the [Name] exists, add number like [FILE_NAME(1), FILE_NAME(2), ...]
172
                Recursive function
173
    '''
130 174
    def makeFileName(self, originName, newName):
131 175
        imageFolderDir = self.project.getPath() + "\\image"
132 176
        imageDir = imageFolderDir + "\\" + newName + ".png"
......
138 182
            return self.makeFileName(originName, imgName)
139 183
        else:
140 184
            return newName
141

  
185
        
186
    '''
187
        @brief  Make symbol object for saving on DB
188
    '''
142 189
    def makeSymbolData(self):
143 190
        symId = self.ui.idLineEdit.text()
144 191
        name = self.ui.nameLineEdit.text()
145
        type = self.ui.typeLineEdit.text()
192
        type = '' #Empty
146 193
        self.FILE_NUMBER = 0
147 194
        fileName = self.makeFileName(name, name)
148 195
        path = self.project.getPath() + "\\image\\" + fileName + ".png"
......
154 201
        isContainChild = 1 if self.ui.isContainChildCheckBox.isChecked() else 0
155 202
        originalPoint = self.ui.originalPointLineEdit.text()
156 203
        connectionPoint = self.makeConnectionPointListString()
157
        ### 기초심볼추가
158 204
        baseSymbol = self.ui.baseSymbolComboBox.currentText()
159
        ### 부가심볼추가
160 205
        additionalSymbol = self.makeAdditionalSymbolListString()
161 206

  
162 207
        convertedThreshold = int(threshold) / 100.0
......
165 210
                                   , rotationCount, ocrOption, isContainChild, originalPoint, connectionPoint, baseSymbol, additionalSymbol)
166 211

  
167 212
        return newSym
168

  
213
    
214
    '''
215
        @brief  Make AdditionalSymbol String
216
                [AdditionalSymbolString = DIRECTION,SYMBOL_NAME/DIRECTION,SYMBOL_NAME/...]
217
    '''
169 218
    def makeAdditionalSymbolListString(self):
170 219
        ret = ""
171 220
        listItems = []
......
179 228
                    ret = ret + "/"
180 229
                ret = ret + text
181 230
        return ret
182

  
231
    
232
    '''
233
        @brief  Make ConnectionPoint String
234
                [ConnectionPointString = x1,y1/x2,y2/...]
235
    '''
183 236
    def makeConnectionPointListString(self):
184 237
        ret = ""
185 238
        listItems = []
......
193 246
                    ret = ret + "/"
194 247
                ret = ret + text
195 248
        return ret
196

  
249
    
250
    '''
251
        @brief  Called when Save Button Clicked
252
                Validation Check → Make Symbol Data → Insert Symbol Data into DB → Save png and svg files
253
    '''
197 254
    def accept(self):
198 255
        print("save")
199 256

  
......
203 260
            isAdded, fileName, imagePath = self.dbHelper.insertSymbol(self.makeSymbolData())
204 261

  
205 262
            if isAdded:
206
                image = self.ui.imageView.image()
207
                if image is not None:
208
                    image.save(imagePath, 'PNG')
209
                    potrace.convertImageToSvg(imagePath, self.project.getPath()+"\\svg\\" + fileName + ".svg")
210
                    self.isAccepted = True
263
                try:
264
                    image = self.ui.imageView.image()
265
                    if image is not None:
266
                        image.save(imagePath, 'PNG')
267
                        potrace.convertImageToSvg(imagePath, self.project.getPath()+"/svg/" + fileName + ".svg")
268
                        self.isAccepted = True
269
                        QDialog.accept(self)
270
                except:
271
                    self.resetInsertSymbol(imagePath, fileName)
272
                    self.isAccepted = False
273
                    QMessageBox.about(self.ui.buttonBox, "알림", "심볼 저장 과정 중 문제가 발생했습니다.")
211 274
            else:
212 275
                QMessageBox.about(self.ui.buttonBox, "알림", "심볼 저장 과정 중 문제가 발생했습니다.")
213
            QDialog.accept(self)
214 276
        else:
215 277
            print("invalid symbol info")
216 278
            QMessageBox.about(self.ui.buttonBox, "알림", exceptionMsg)
217

  
279
            
280
    '''
281
        @brief  Called When Cancel Button Clicked
282
    '''
218 283
    def cancel(self):
219 284
        print("cancel")
220 285
        self.isAccepted = Flase
221 286
        QDialog.cancel(self)
287
        
288
    '''
289
        @brief  Called When error occured while saving png and svg files
290
                Delete png, svg files and record from DB
291
    '''
292
    def resetInsertSymbol(self, imagePath, fileName):
293
        if os.path.exists(imagePath):
294
            os.remove(imagePath)
295

  
296
        svgPath = self.project.getPath()+"/svg/" + fileName + ".svg"
297
        if os.path.exists(svgPath):
298
            os.remove(svgPath)
299

  
300
        dbPath = self.project.getPath()+"/db/ITI_PID.db"
301
        AppDocData.instance().deleteSymbol(dbPath, imagePath)
222 302

  
223 303
    def keyPressEvent(self, event):
224 304
        if event.key() == QtCore.Qt.Key_Delete:
225
            selectedItems = self.ui.connectionPointList.selectedItems()
226
            if selectedItems is not None:
227
                for item in selectedItems:
228
                    text = item.text()
229
                    x = int(text.split(",")[0])
230
                    y = int(text.split(",")[1])
231
                    self.removeConnectionPointCircle(QtCore.QPointF(x, y))
232
                    self.ui.connectionPointList.takeItem(self.ui.connectionPointList.row(item))
233

  
305
            if self.ui.connectionPointList.hasFocus():
306
                selectedItems = self.ui.connectionPointList.selectedItems()
307
                if selectedItems is not None:
308
                    for item in selectedItems:
309
                        text = item.text()
310
                        x = int(text.split(",")[0])
311
                        y = int(text.split(",")[1])
312
                        self.removeConnectionPointCircle(QtCore.QPointF(x, y))
313
                        self.ui.connectionPointList.takeItem(self.ui.connectionPointList.row(item))
314
            elif self.ui.additionalSymbolListWidget.hasFocus():
315
                selectedItems = self.ui.additionalSymbolListWidget.selectedItems()
316
                if selectedItems is not None:
317
                    for item in selectedItems:
318
                        self.ui.additionalSymbolListWidget.takeItem(self.ui.additionalSymbolListWidget.row(item))
319
                        
320
    '''
321
        @brief  Hand Tool Button Clicked
322
    '''
234 323
    def handToolClickEvent(self, event):
235 324
        print("hand tool clicked")
236 325
        self.ui.imageView.command = HandCommand.HandCommand(self.ui.imageView)
237

  
326
                         
327
    '''
328
        @brief  Zoom Init Tool Button Clicked
329
    '''
238 330
    def zoomInitToolClickEvent(self, event):
239 331
        print("zoom init tool clicked")
240 332
        self.ui.imageView.command = None
241 333
        self.ui.imageView.zoomImageInit()
242

  
334
                         
335
    '''
336
        @brief  Zoom Tool Button Clicked
337
    '''
243 338
    def zoomToolClickEvent(self, event):
244 339
        print("zoom tool clicked")
245 340
        self.ui.imageView.command = ZoomCommand.ZoomCommand(self.ui.imageView)
246

  
341
                         
342
    '''
343
        @brief  Pen Tool Button Clicked
344
    '''
247 345
    def penToolClickEvent(self, event):
248 346
        print("Pen")
249 347
        width = self.ui.toolWidget.findChild(QSpinBox, 'penWidthSpinBox').value()
250 348
        self.ui.imageView.command = PenCommand.PenCommand(self.ui.imageView)
251 349
        self.ui.imageView.command.width = width
252

  
350
                         
351
    '''
352
        @brief  Pen Width Value Changed
353
    '''
253 354
    def penWidthChangedEvent(self, value):
254 355
        print("Pen Width " + str(value))
255 356
        if self.ui.imageView.command is not None and type(self.ui.imageView.command) is PenCommand.PenCommand:
256 357
            self.ui.imageView.command.width = value
257

  
358
                 
359
    '''
360
        @brief  Eraser Tool Button Clicked
361
    '''
258 362
    def eraserToolClickEvent(self, event):
259 363
        print("eraser")
260 364
        width = self.ui.toolWidget.findChild(QSpinBox, 'eraserSpinBox').value()
261 365
        self.ui.imageView.command = EraserCommand.EraserCommand(self.ui.imageView)
262 366
        self.ui.imageView.command.width = width
263

  
367
                         
368
    '''
369
        @brief  Eraser Width Value Changed
370
    '''
264 371
    def eraserWidthChangedEvent(self, value):
265 372
        print("eraser " + str(value))
266 373
        if self.ui.imageView.command is not None and type(self.ui.imageView.command) is EraserCommand.EraserCommand:
267 374
            self.ui.imageView.command.width = value
268

  
375
                             
376
    '''
377
        @brief  Area Eraser Tool Button Clicked
378
    '''
269 379
    def areaEraserToolClickEvent(self, event):
270 380
        print("area eraser")
271 381
        self.ui.imageView.command = AreaEraserCommand.AreaEraserCommand(self.ui.imageView)
272

  
382
                         
383
    '''
384
        @brief  Guideline Check State Changed
385
    '''
273 386
    def guidelineStateChangedEvent(self, value):
274 387
        if self.ui.guidelineCheckbox.isChecked():
275 388
            self.ui.imageView.showGuideline(True)
276 389
        else:
277 390
            self.ui.imageView.showGuideline(False)
278

  
391
                             
392
    '''
393
        @brief  Add AdditionalSymbol String on ListWidget
394
    '''
279 395
    def addAdditionalSymbol(self, event):
280 396
        print("addAdditionalSymbol")
281 397
        additionalSymbolIndex = self.ui.additionalSymbolComboBox.currentIndex()
......
289 405
                QMessageBox.about(self.ui.buttonBox, "알림", "이미 추가된 아이템입니다.")
290 406
            else:
291 407
                self.ui.additionalSymbolListWidget.addItem(text)
292

  
408
                                 
409
    '''
410
        @brief  Check the text is already added
411
    '''
293 412
    def isAlreadyAdded(self, text):
294 413
        for index in range(self.ui.additionalSymbolListWidget.count()):
295 414
            item = self.ui.additionalSymbolListWidget.item(index)
296 415
            if item.text() == text:
297 416
                return True
298 417
        return False
299

  
418
                     
419
    '''
420
        @brief  Original Point Tool Button Clicked
421
    '''
300 422
    def addOriginalPoint(self, event):
301 423
        print("addOriginalPoint")
302 424
        self.ui.imageView.command = OriginalPointCommand.OriginalPointCommand(self.ui.imageView, self.ui.originalPointLineEdit)
303

  
425
                         
426
    '''
427
        @brief  Connection Point Tool Button Clicked
428
    '''
304 429
    def addConnectionPoint(self, event):
305 430
        print("addConnectionPoint")
306 431
        self.ui.imageView.command = ConnectionPointCommand.ConnectionPointCommand(self.ui.imageView, self.ui.connectionPointLineEdit, self.ui.connectionPointList)
307

  
432
                         
433
    '''
434
        @brief  Validation Check
435
        @return (isValid, errorMsg)
436
    '''
308 437
    def isValidSymbolInfo(self):
309 438
        print("isValid")
310 439
        EXCEPTION_MSG_FORMAT = "{} 입력을 확인해주세요."
......
325 454
            infoTitle = self.ui.nameLabel.text()
326 455
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
327 456

  
328
        #if not self.ui.typeLineEdit.text():
329
        #    infoTitle = self.ui.typeLabel.text()
330
        #    return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
331

  
332 457
        thresholdText = self.ui.thresholdLineEdit.text()
333 458
        threshold = float(thresholdText) if thresholdText else -1
334 459
        if not(threshold >= 0 and threshold <= 100):
DTI_PID/DTI_PID/QtImageViewer.py
289 289
            height = image.height()
290 290
            if self.crosshairPos is not None:
291 291
                pen = QPen()
292
                pen.setColor(QColor(80, 80, 80))
292
                pen.setColor(QColor(180, 180, 180))
293 293
                pen.setStyle(Qt.DashLine)
294 294
                pen.setWidthF(0.3)
295 295
                painter.setPen(pen)
......
316 316
        width = image.width()
317 317
        height = image.height()
318 318
        pen = QPen()
319
        pen.setColor(QColor(80, 80, 80))
319
        pen.setColor(QColor(180, 180, 180))
320 320
        pen.setStyle(Qt.DashLine)
321 321
        pen.setWidthF(0.5)
322 322
        if isShow:
DTI_PID/DTI_PID/UI/SymbolEditor.ui
160 160
                <widget class="QLineEdit" name="nameLineEdit"/>
161 161
               </item>
162 162
               <item row="3" column="0">
163
                <widget class="QLabel" name="typeLabel">
164
                 <property name="font">
165
                  <font>
166
                   <weight>75</weight>
167
                   <bold>true</bold>
168
                  </font>
169
                 </property>
170
                 <property name="text">
171
                  <string>Type</string>
172
                 </property>
173
                </widget>
174
               </item>
175
               <item row="3" column="1">
176
                <widget class="QLineEdit" name="typeLineEdit"/>
177
               </item>
178
               <item row="4" column="0">
179 163
                <widget class="QLabel" name="thresholdLabel">
180 164
                 <property name="font">
181 165
                  <font>
......
188 172
                 </property>
189 173
                </widget>
190 174
               </item>
191
               <item row="4" column="1">
175
               <item row="3" column="1">
192 176
                <widget class="QLineEdit" name="thresholdLineEdit"/>
193 177
               </item>
194
               <item row="5" column="0">
178
               <item row="4" column="0">
195 179
                <widget class="QLabel" name="minMatchPointLabel">
196 180
                 <property name="font">
197 181
                  <font>
......
204 188
                 </property>
205 189
                </widget>
206 190
               </item>
207
               <item row="5" column="1">
191
               <item row="4" column="1">
208 192
                <widget class="QLineEdit" name="minMatchPointLineEdit"/>
209 193
               </item>
210
               <item row="6" column="0">
194
               <item row="5" column="0">
211 195
                <widget class="QLabel" name="isOriginDetectLabel">
212 196
                 <property name="font">
213 197
                  <font>
......
220 204
                 </property>
221 205
                </widget>
222 206
               </item>
223
               <item row="6" column="1">
207
               <item row="5" column="1">
224 208
                <widget class="QComboBox" name="isOriginDetectComboBox"/>
225 209
               </item>
226
               <item row="7" column="0">
210
               <item row="6" column="0">
227 211
                <widget class="QLabel" name="rotationCountLabel">
228 212
                 <property name="font">
229 213
                  <font>
......
236 220
                 </property>
237 221
                </widget>
238 222
               </item>
239
               <item row="7" column="1">
223
               <item row="6" column="1">
240 224
                <widget class="QSpinBox" name="rotationCountSpinBox">
241 225
                 <property name="minimum">
242 226
                  <number>0</number>
......
249 233
                 </property>
250 234
                </widget>
251 235
               </item>
252
               <item row="8" column="0">
236
               <item row="7" column="0">
253 237
                <widget class="QLabel" name="ocrOptionLabel">
254 238
                 <property name="font">
255 239
                  <font>
......
262 246
                 </property>
263 247
                </widget>
264 248
               </item>
265
               <item row="8" column="1">
249
               <item row="7" column="1">
266 250
                <widget class="QComboBox" name="ocrOptionComboBox"/>
267 251
               </item>
268
               <item row="10" column="0">
252
               <item row="8" column="0">
253
                <widget class="QLabel" name="isContainChildLabel">
254
                 <property name="font">
255
                  <font>
256
                   <weight>75</weight>
257
                   <bold>true</bold>
258
                  </font>
259
                 </property>
260
                 <property name="text">
261
                  <string>자식 심볼 포함 여부</string>
262
                 </property>
263
                </widget>
264
               </item>
265
               <item row="8" column="1">
266
                <widget class="QCheckBox" name="isContainChildCheckBox">
267
                 <property name="text">
268
                  <string/>
269
                 </property>
270
                 <property name="checkable">
271
                  <bool>true</bool>
272
                 </property>
273
                </widget>
274
               </item>
275
               <item row="9" column="0">
269 276
                <widget class="QLabel" name="baseSymbolLabel">
270 277
                 <property name="font">
271 278
                  <font>
......
278 285
                 </property>
279 286
                </widget>
280 287
               </item>
281
               <item row="10" column="1">
288
               <item row="9" column="1">
282 289
                <widget class="QComboBox" name="baseSymbolComboBox"/>
283 290
               </item>
284
               <item row="11" column="0">
291
               <item row="10" column="0">
285 292
                <widget class="QLabel" name="additionalSymbolLabel">
286 293
                 <property name="font">
287 294
                  <font>
......
294 301
                 </property>
295 302
                </widget>
296 303
               </item>
297
               <item row="11" column="1">
304
               <item row="10" column="1">
298 305
                <layout class="QHBoxLayout" name="horizontalLayout_2">
299 306
                 <item>
300 307
                  <widget class="QComboBox" name="defaultSymbolDirectionComboBox">
......
307 314
                  </widget>
308 315
                 </item>
309 316
                 <item>
310
                  <widget class="QComboBox" name="addtionalSymbolComboBox"/>
317
                  <widget class="QComboBox" name="additionalSymbolComboBox"/>
311 318
                 </item>
312 319
                 <item>
313 320
                  <widget class="QPushButton" name="addAdditionalSymbolButton">
......
324 331
                 </item>
325 332
                </layout>
326 333
               </item>
327
               <item row="12" column="1">
328
                <widget class="QListView" name="additionalSymbolListView"/>
329
               </item>
330
               <item row="13" column="0">
334
               <item row="12" column="0">
331 335
                <widget class="QLabel" name="originalPointLabel">
332 336
                 <property name="sizePolicy">
333 337
                  <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
......
349 353
                 </property>
350 354
                </widget>
351 355
               </item>
352
               <item row="13" column="1">
356
               <item row="12" column="1">
353 357
                <layout class="QHBoxLayout" name="horizontalLayout_4">
354 358
                 <item>
355 359
                  <widget class="QLineEdit" name="originalPointLineEdit">
......
373 377
                 </item>
374 378
                </layout>
375 379
               </item>
376
               <item row="16" column="0">
380
               <item row="15" column="0">
377 381
                <widget class="QLabel" name="connectionPointLabel">
378 382
                 <property name="font">
379 383
                  <font>
......
389 393
                 </property>
390 394
                </widget>
391 395
               </item>
392
               <item row="16" column="1">
396
               <item row="15" column="1">
393 397
                <layout class="QHBoxLayout" name="horizontalLayout_6">
394 398
                 <item>
395 399
                  <widget class="QLineEdit" name="connectionPointLineEdit">
......
413 417
                 </item>
414 418
                </layout>
415 419
               </item>
416
               <item row="17" column="1">
420
               <item row="16" column="1">
417 421
                <widget class="QListWidget" name="connectionPointList"/>
418 422
               </item>
419
               <item row="9" column="0">
420
                <widget class="QLabel" name="isContainChildLabel">
421
                 <property name="font">
422
                  <font>
423
                   <weight>75</weight>
424
                   <bold>true</bold>
425
                  </font>
426
                 </property>
427
                 <property name="text">
428
                  <string>자식 심볼 포함 여부</string>
429
                 </property>
430
                </widget>
431
               </item>
432
               <item row="9" column="1">
433
                <widget class="QCheckBox" name="isContainChildCheckBox">
434
                 <property name="text">
435
                  <string/>
436
                 </property>
437
                 <property name="checkable">
438
                  <bool>true</bool>
439
                 </property>
440
                </widget>
423
               <item row="11" column="1">
424
                <widget class="QListWidget" name="additionalSymbolListWidget"/>
441 425
               </item>
442 426
              </layout>
443 427
             </widget>
DTI_PID/DTI_PID/UI_SymbolEditor.py
79 79
        self.nameLineEdit = QtWidgets.QLineEdit(self.formLayoutWidget)
80 80
        self.nameLineEdit.setObjectName("nameLineEdit")
81 81
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.nameLineEdit)
82
        self.typeLabel = QtWidgets.QLabel(self.formLayoutWidget)
83
        font = QtGui.QFont()
84
        font.setBold(True)
85
        font.setWeight(75)
86
        self.typeLabel.setFont(font)
87
        self.typeLabel.setObjectName("typeLabel")
88
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.typeLabel)
89
        self.typeLineEdit = QtWidgets.QLineEdit(self.formLayoutWidget)
90
        self.typeLineEdit.setObjectName("typeLineEdit")
91
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.typeLineEdit)
92 82
        self.thresholdLabel = QtWidgets.QLabel(self.formLayoutWidget)
93 83
        font = QtGui.QFont()
94 84
        font.setBold(True)
95 85
        font.setWeight(75)
96 86
        self.thresholdLabel.setFont(font)
97 87
        self.thresholdLabel.setObjectName("thresholdLabel")
98
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.thresholdLabel)
88
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.thresholdLabel)
99 89
        self.thresholdLineEdit = QtWidgets.QLineEdit(self.formLayoutWidget)
100 90
        self.thresholdLineEdit.setObjectName("thresholdLineEdit")
101
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.thresholdLineEdit)
91
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.thresholdLineEdit)
102 92
        self.minMatchPointLabel = QtWidgets.QLabel(self.formLayoutWidget)
103 93
        font = QtGui.QFont()
104 94
        font.setBold(True)
105 95
        font.setWeight(75)
106 96
        self.minMatchPointLabel.setFont(font)
107 97
        self.minMatchPointLabel.setObjectName("minMatchPointLabel")
108
        self.formLayout.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.minMatchPointLabel)
98
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.minMatchPointLabel)
109 99
        self.minMatchPointLineEdit = QtWidgets.QLineEdit(self.formLayoutWidget)
110 100
        self.minMatchPointLineEdit.setObjectName("minMatchPointLineEdit")
111
        self.formLayout.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.minMatchPointLineEdit)
101
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.minMatchPointLineEdit)
112 102
        self.isOriginDetectLabel = QtWidgets.QLabel(self.formLayoutWidget)
113 103
        font = QtGui.QFont()
114 104
        font.setBold(True)
115 105
        font.setWeight(75)
116 106
        self.isOriginDetectLabel.setFont(font)
117 107
        self.isOriginDetectLabel.setObjectName("isOriginDetectLabel")
118
        self.formLayout.setWidget(6, QtWidgets.QFormLayout.LabelRole, self.isOriginDetectLabel)
108
        self.formLayout.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.isOriginDetectLabel)
119 109
        self.isOriginDetectComboBox = QtWidgets.QComboBox(self.formLayoutWidget)
120 110
        self.isOriginDetectComboBox.setObjectName("isOriginDetectComboBox")
121
        self.formLayout.setWidget(6, QtWidgets.QFormLayout.FieldRole, self.isOriginDetectComboBox)
111
        self.formLayout.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.isOriginDetectComboBox)
122 112
        self.rotationCountLabel = QtWidgets.QLabel(self.formLayoutWidget)
123 113
        font = QtGui.QFont()
124 114
        font.setBold(True)
125 115
        font.setWeight(75)
126 116
        self.rotationCountLabel.setFont(font)
127 117
        self.rotationCountLabel.setObjectName("rotationCountLabel")
128
        self.formLayout.setWidget(7, QtWidgets.QFormLayout.LabelRole, self.rotationCountLabel)
118
        self.formLayout.setWidget(6, QtWidgets.QFormLayout.LabelRole, self.rotationCountLabel)
129 119
        self.rotationCountSpinBox = QtWidgets.QSpinBox(self.formLayoutWidget)
130 120
        self.rotationCountSpinBox.setMinimum(0)
131 121
        self.rotationCountSpinBox.setMaximum(3)
132 122
        self.rotationCountSpinBox.setProperty("value", 0)
133 123
        self.rotationCountSpinBox.setObjectName("rotationCountSpinBox")
134
        self.formLayout.setWidget(7, QtWidgets.QFormLayout.FieldRole, self.rotationCountSpinBox)
124
        self.formLayout.setWidget(6, QtWidgets.QFormLayout.FieldRole, self.rotationCountSpinBox)
135 125
        self.ocrOptionLabel = QtWidgets.QLabel(self.formLayoutWidget)
136 126
        font = QtGui.QFont()
137 127
        font.setBold(True)
138 128
        font.setWeight(75)
139 129
        self.ocrOptionLabel.setFont(font)
140 130
        self.ocrOptionLabel.setObjectName("ocrOptionLabel")
141
        self.formLayout.setWidget(8, QtWidgets.QFormLayout.LabelRole, self.ocrOptionLabel)
131
        self.formLayout.setWidget(7, QtWidgets.QFormLayout.LabelRole, self.ocrOptionLabel)
142 132
        self.ocrOptionComboBox = QtWidgets.QComboBox(self.formLayoutWidget)
143 133
        self.ocrOptionComboBox.setObjectName("ocrOptionComboBox")
144
        self.formLayout.setWidget(8, QtWidgets.QFormLayout.FieldRole, self.ocrOptionComboBox)
134
        self.formLayout.setWidget(7, QtWidgets.QFormLayout.FieldRole, self.ocrOptionComboBox)
135
        self.isContainChildLabel = QtWidgets.QLabel(self.formLayoutWidget)
136
        font = QtGui.QFont()
137
        font.setBold(True)
138
        font.setWeight(75)
139
        self.isContainChildLabel.setFont(font)
140
        self.isContainChildLabel.setObjectName("isContainChildLabel")
141
        self.formLayout.setWidget(8, QtWidgets.QFormLayout.LabelRole, self.isContainChildLabel)
142
        self.isContainChildCheckBox = QtWidgets.QCheckBox(self.formLayoutWidget)
143
        self.isContainChildCheckBox.setText("")
144
        self.isContainChildCheckBox.setCheckable(True)
145
        self.isContainChildCheckBox.setObjectName("isContainChildCheckBox")
146
        self.formLayout.setWidget(8, QtWidgets.QFormLayout.FieldRole, self.isContainChildCheckBox)
145 147
        self.baseSymbolLabel = QtWidgets.QLabel(self.formLayoutWidget)
146 148
        font = QtGui.QFont()
147 149
        font.setBold(True)
148 150
        font.setWeight(75)
149 151
        self.baseSymbolLabel.setFont(font)
150 152
        self.baseSymbolLabel.setObjectName("baseSymbolLabel")
151
        self.formLayout.setWidget(10, QtWidgets.QFormLayout.LabelRole, self.baseSymbolLabel)
153
        self.formLayout.setWidget(9, QtWidgets.QFormLayout.LabelRole, self.baseSymbolLabel)
152 154
        self.baseSymbolComboBox = QtWidgets.QComboBox(self.formLayoutWidget)
153 155
        self.baseSymbolComboBox.setObjectName("baseSymbolComboBox")
154
        self.formLayout.setWidget(10, QtWidgets.QFormLayout.FieldRole, self.baseSymbolComboBox)
156
        self.formLayout.setWidget(9, QtWidgets.QFormLayout.FieldRole, self.baseSymbolComboBox)
155 157
        self.additionalSymbolLabel = QtWidgets.QLabel(self.formLayoutWidget)
156 158
        font = QtGui.QFont()
157 159
        font.setBold(True)
158 160
        font.setWeight(75)
159 161
        self.additionalSymbolLabel.setFont(font)
160 162
        self.additionalSymbolLabel.setObjectName("additionalSymbolLabel")
161
        self.formLayout.setWidget(11, QtWidgets.QFormLayout.LabelRole, self.additionalSymbolLabel)
163
        self.formLayout.setWidget(10, QtWidgets.QFormLayout.LabelRole, self.additionalSymbolLabel)
162 164
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
163 165
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
164 166
        self.defaultSymbolDirectionComboBox = QtWidgets.QComboBox(self.formLayoutWidget)
......
172 174
        self.addAdditionalSymbolButton.setMaximumSize(QtCore.QSize(40, 16777215))
173 175
        self.addAdditionalSymbolButton.setObjectName("addAdditionalSymbolButton")
174 176
        self.horizontalLayout_2.addWidget(self.addAdditionalSymbolButton)
175
        self.formLayout.setLayout(11, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_2)
176
        self.additionalSymbolListWidget = QtWidgets.QListWidget(self.formLayoutWidget)
177
        self.additionalSymbolListWidget.setObjectName("additionalSymbolListWidget")
178
        self.formLayout.setWidget(12, QtWidgets.QFormLayout.FieldRole, self.additionalSymbolListWidget)
177
        self.formLayout.setLayout(10, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_2)
179 178
        self.originalPointLabel = QtWidgets.QLabel(self.formLayoutWidget)
180 179
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
181 180
        sizePolicy.setHorizontalStretch(0)
......
188 187
        self.originalPointLabel.setFont(font)
189 188
        self.originalPointLabel.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
190 189
        self.originalPointLabel.setObjectName("originalPointLabel")
191
        self.formLayout.setWidget(13, QtWidgets.QFormLayout.LabelRole, self.originalPointLabel)
190
        self.formLayout.setWidget(12, QtWidgets.QFormLayout.LabelRole, self.originalPointLabel)
192 191
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
193 192
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
194 193
        self.originalPointLineEdit = QtWidgets.QLineEdit(self.formLayoutWidget)
......
199 198
        self.addOriginalPointButton.setMaximumSize(QtCore.QSize(40, 16777215))
200 199
        self.addOriginalPointButton.setObjectName("addOriginalPointButton")
201 200
        self.horizontalLayout_4.addWidget(self.addOriginalPointButton)
202
        self.formLayout.setLayout(13, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_4)
201
        self.formLayout.setLayout(12, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_4)
203 202
        self.connectionPointLabel = QtWidgets.QLabel(self.formLayoutWidget)
204 203
        font = QtGui.QFont()
205 204
        font.setBold(True)
......
207 206
        self.connectionPointLabel.setFont(font)
208 207
        self.connectionPointLabel.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
209 208
        self.connectionPointLabel.setObjectName("connectionPointLabel")
210
        self.formLayout.setWidget(16, QtWidgets.QFormLayout.LabelRole, self.connectionPointLabel)
209
        self.formLayout.setWidget(15, QtWidgets.QFormLayout.LabelRole, self.connectionPointLabel)
211 210
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
212 211
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
213 212
        self.connectionPointLineEdit = QtWidgets.QLineEdit(self.formLayoutWidget)
......
218 217
        self.addConnectionPointButton.setMaximumSize(QtCore.QSize(40, 16777215))
219 218
        self.addConnectionPointButton.setObjectName("addConnectionPointButton")
220 219
        self.horizontalLayout_6.addWidget(self.addConnectionPointButton)
221
        self.formLayout.setLayout(16, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_6)
220
        self.formLayout.setLayout(15, QtWidgets.QFormLayout.FieldRole, self.horizontalLayout_6)
222 221
        self.connectionPointList = QtWidgets.QListWidget(self.formLayoutWidget)
223 222
        self.connectionPointList.setObjectName("connectionPointList")
224
        self.formLayout.setWidget(17, QtWidgets.QFormLayout.FieldRole, self.connectionPointList)
225
        self.isContainChildLabel = QtWidgets.QLabel(self.formLayoutWidget)
226
        font = QtGui.QFont()
227
        font.setBold(True)
228
        font.setWeight(75)
229
        self.isContainChildLabel.setFont(font)
230
        self.isContainChildLabel.setObjectName("isContainChildLabel")
231
        self.formLayout.setWidget(9, QtWidgets.QFormLayout.LabelRole, self.isContainChildLabel)
232
        self.isContainChildCheckBox = QtWidgets.QCheckBox(self.formLayoutWidget)
233
        self.isContainChildCheckBox.setText("")
234
        self.isContainChildCheckBox.setCheckable(True)
235
        self.isContainChildCheckBox.setObjectName("isContainChildCheckBox")
236
        self.formLayout.setWidget(9, QtWidgets.QFormLayout.FieldRole, self.isContainChildCheckBox)
223
        self.formLayout.setWidget(16, QtWidgets.QFormLayout.FieldRole, self.connectionPointList)
224
        self.additionalSymbolListWidget = QtWidgets.QListWidget(self.formLayoutWidget)
225
        self.additionalSymbolListWidget.setObjectName("additionalSymbolListWidget")
226
        self.formLayout.setWidget(11, QtWidgets.QFormLayout.FieldRole, self.additionalSymbolListWidget)
237 227
        self.scrollArea.setWidget(self.scrollAreaWidgetContents)
238 228
        self.verticalLayout.addWidget(self.scrollArea)
239 229
        self.buttonBox = QtWidgets.QDialogButtonBox(self.verticalLayoutWidget)
......
313 303
        self.targetDBLabel.setText(_translate("Dialog", "대상 DB"))
314 304
        self.idLabel.setText(_translate("Dialog", "ID"))
315 305
        self.nameLabel.setText(_translate("Dialog", "Name"))
316
        self.typeLabel.setText(_translate("Dialog", "Type"))
317 306
        self.thresholdLabel.setText(_translate("Dialog", "임계값(%)"))
318 307
        self.minMatchPointLabel.setText(_translate("Dialog", "최소 특징점 개수"))
319 308
        self.isOriginDetectLabel.setText(_translate("Dialog", "검출 소스"))
320 309
        self.rotationCountLabel.setText(_translate("Dialog", "검출 시 심볼 회전수"))
321 310
        self.ocrOptionLabel.setText(_translate("Dialog", "OCR 옵션"))
311
        self.isContainChildLabel.setText(_translate("Dialog", "자식 심볼 포함 여부"))
322 312
        self.baseSymbolLabel.setText(_translate("Dialog", "기초 심볼"))
323 313
        self.additionalSymbolLabel.setText(_translate("Dialog", "부가 심볼"))
324 314
        self.addAdditionalSymbolButton.setText(_translate("Dialog", "추가"))
......
326 316
        self.addOriginalPointButton.setText(_translate("Dialog", "추가"))
327 317
        self.connectionPointLabel.setText(_translate("Dialog", "Connection Point"))
328 318
        self.addConnectionPointButton.setText(_translate("Dialog", "추가"))
329
        self.isContainChildLabel.setText(_translate("Dialog", "자식 심볼 포함 여부"))
330 319
        self.handButton.setText(_translate("Dialog", "Hand"))
331 320
        self.penButton.setText(_translate("Dialog", "Pen"))
332 321
        self.eraserButton.setText(_translate("Dialog", "Eraser"))
DTI_PID/DTI_PID/potrace.py
20 20

  
21 21
    image  = cv2.imread(imgFilePath, cv2.IMREAD_GRAYSCALE)
22 22
    threshold = cv2.threshold(image, thresh, 255, cv2.THRESH_BINARY)[1]
23
    kernel = np.ones((3, 3), np.uint8)
24
    erode = cv2.dilate(threshold, kernel, iterations=1)
25 23

  
26 24
    # convert to bmp binary so that potrace can handle it
27
    retval, buf = cv2.imencode('.bmp', erode)
25
    retval, buf = cv2.imencode('.bmp', threshold)
28 26
    if retval == False:
29 27
        raise ValueError('Failed to convert into BMP binary data')
30 28
    # convert buf from numpy.ndarray to bytes
......
47 45
    if len(stderr) != 0:
48 46
        raise RuntimeError('Potrace threw error:\n' + stderr.decode('utf-8'))
49 47
    
50
    svgData = stdout
51
    #svgData = stdout.decode("utf-8")
52
    #svgData = stdout.decode("utf-16")
53
    #svgData = svgData.replace(u"\u000B", u"")
54
    #svgData = svgData.encode("utf-8")
55

  
56
    xmlFile = open(destFilePath, "wb")#, encoding = "utf-8")
57
    xmlFile.write(svgData)
58
    xmlFile.close()
48
    svgFile = open(destFilePath, "w")
49
    svgFile.write(stdout.decode("utf-8"))
50
    svgFile.close()
59 51

  
60 52
# extract line from image by using potrace
61
def passpotrace(imgFile):
62
    thresh = 127
53
# 사용하지 않음
54
#def passpotrace(imgFile):
55
#    thresh = 127
63 56

  
64
    image  = cv2.imread(imgFile, cv2.IMREAD_GRAYSCALE)
65
    threshold = cv2.threshold(image, thresh, 255, cv2.THRESH_BINARY)[1]
66
    kernel = np.ones((3, 3), np.uint8)
67
    erode = cv2.dilate(threshold, kernel, iterations=1)
57
#    image  = cv2.imread(imgFile, cv2.IMREAD_GRAYSCALE)
58
#    threshold = cv2.threshold(image, thresh, 255, cv2.THRESH_BINARY)[1]
59
#    kernel = np.ones((3, 3), np.uint8)
60
#    erode = cv2.dilate(threshold, kernel, iterations=1)
68 61

  
69
    # convert to bmp binary so that potrace can handle it
70
    retval, buf = cv2.imencode('.bmp', erode)
71
    if retval == False:
72
        raise ValueError('Failed to convert into BMP binary data')
73
    # convert buf from numpy.ndarray to bytes
74
    binbmp = buf.tobytes()
62
#    # convert to bmp binary so that potrace can handle it
63
#    retval, buf = cv2.imencode('.bmp', erode)
64
#    if retval == False:
65
#        raise ValueError('Failed to convert into BMP binary data')
66
#    # convert buf from numpy.ndarray to bytes
67
#    binbmp = buf.tobytes()
75 68
    
76
    args = [
77
        POTRACE,
78
        '-', '-o-', '--svg'
79
    ]
69
#    args = [
70
#        POTRACE,
71
#        '-', '-o-', '--svg'
72
#    ]
80 73
    
81
    p = subprocess.Popen(
82
        args,
83
        stdin=subprocess.PIPE,
84
        stdout=subprocess.PIPE,
85
        stderr=subprocess.PIPE,
86
        shell=False
87
        )
74
#    p = subprocess.Popen(
75
#        args,
76
#        stdin=subprocess.PIPE,
77
#        stdout=subprocess.PIPE,
78
#        stderr=subprocess.PIPE,
79
#        shell=False
80
#        )
88 81
        
89
    stdout, stderr = p.communicate(input=binbmp)
90
    if len(stderr) != 0:
91
        raise RuntimeError('Potrace threw error:\n' + stderr.decode('utf-8'))
82
#    stdout, stderr = p.communicate(input=binbmp)
83
#    if len(stderr) != 0:
84
#        raise RuntimeError('Potrace threw error:\n' + stderr.decode('utf-8'))
92 85

  
93
    imgLines = []
94
    # parse svg data and extract lines
95
    svgdom = minidom.parseString(stdout)
96
    transform = svgdom.getElementsByTagName('g')[0].getAttribute('transform')
97
    translate = transform.split(' ')[0].split('translate')[1].split(',')
98
    dx = float(translate[0][1:])
99
    dy = float(translate[1][:-1])
100
    scale = transform.split(' ')[1].split('scale')[1].split(',')
101
    sx = float(scale[0][1:])
102
    sy = float(scale[1][:-1])
86
#    imgLines = []
87
#    # parse svg data and extract lines
88
#    svgdom = minidom.parseString(stdout)
89
#    transform = svgdom.getElementsByTagName('g')[0].getAttribute('transform')
90
#    translate = transform.split(' ')[0].split('translate')[1].split(',')
91
#    dx = float(translate[0][1:])
92
#    dy = float(translate[1][:-1])
93
#    scale = transform.split(' ')[1].split('scale')[1].split(',')
94
#    sx = float(scale[0][1:])
95
#    sy = float(scale[1][:-1])
103 96

  
104
    pathstrings = [path.getAttribute('d') for path in svgdom.getElementsByTagName('path')]
105
    for pathstring in pathstrings:
106
        pathdata = svg.path.parse_path(pathstring)
107
        for segment in pathdata:
108
            if type(segment) is svg.path.Line:
109
                line = LineString([(segment.start.real / ADJUST, segment.start.imag / ADJUST), (segment.end.real / ADJUST, segment.end.imag / ADJUST)])
110
                imgLines.append(line)
111
    # up to here
112
    return imgLines
97
#    pathstrings = [path.getAttribute('d') for path in svgdom.getElementsByTagName('path')]
98
#    for pathstring in pathstrings:
99
#        pathdata = svg.path.parse_path(pathstring)
100
#        for segment in pathdata:
101
#            if type(segment) is svg.path.Line:
102
#                line = LineString([(segment.start.real / ADJUST, segment.start.imag / ADJUST), (segment.end.real / ADJUST, segment.end.imag / ADJUST)])
103
#                imgLines.append(line)
104
#    # up to here
105
#    return imgLines
113 106
    
114 107
if __name__ == '__main__':
115 108
    execpath = os.path.dirname(os.path.realpath(__file__))

내보내기 Unified diff

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