프로젝트

일반

사용자정보

개정판 857e8599

ID857e859901e46107cefa952c2eb04fff65d0a397
상위 03e258fa
하위 1ba6e7ae

humkyung 이(가) 약 7년 전에 추가함

Modified LineDetector

차이점 보기:

DTI_PID/DTI_PID/App.py
208 208
    def recognize(self, MainWindow):
209 209
        from QRecognitionDialog import QRecognitionDialog
210 210
        from LineDetector import LineDetector
211
        import random
211 212

  
212 213
        try:
213 214
            self.dlg = QRecognitionDialog(self)
......
223 224
                detector = LineDetector(area.img)
224 225
                for item in self.graphicsView.scene.items():
225 226
                    if (type(item) is SymbolSvgItem):
227
                        color = QColor(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))
228
                        res = detector.detectConnectedLine(item, int(area.x), int(area.y))
229
                        if res is not None:
230
                            for pts in res:
231
                                processLine = QEngineeringLineItem()
232
                                for pt in pts:
233
                                    processLine._pol.append(QPointF(pt[0] + int(area.x), pt[1] + int(area.y)))
234
                                processLine._path.addPolygon(processLine._pol)
235
                                processLine.setPath(processLine._path)
236
                                processLine.setPen(QPen(color, 5, Qt.SolidLine))
237
                                self.graphicsView.scene.addItem(processLine)
238

  
239
                        '''
226 240
                        res = detector.detectConnectedLine(item, int(area.x), int(area.y))
227 241
                        for pts in res:
228 242
                            processLine = QEngineeringLineItem()
......
231 245
                            processLine._path.addPolygon(processLine._pol)
232 246
                            processLine.setPath(processLine._path)
233 247
                            self.graphicsView.scene.addItem(processLine)
248
                        '''
234 249
                # up to here
235 250
        except Exception as ex:
236 251
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
DTI_PID/DTI_PID/LineDetector.py
368 368
                for i in range(imgWidth-windowSize[0], -1, -1):
369 369
                    window = image[0:windowSize[1], i:i+windowSize[0]]
370 370
                    if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break
371
                if abs(pt[0] - i) > windowSize[0]: 
371
                if abs(pt[0] - i - windowSize[0]) > windowSize[0]: 
372 372
                    self.image[int(pt[1]-yHalf*2):int(pt[1]+yHalf*2), (i+windowSize[0]+yHalf):pt[0]] = white
373
                    return [(pt[0], pt[1]), (i+windowSize[0], pt[1])]
373
                    return [(pt[0], pt[1]), (i+windowSize[0]+yHalf, pt[1])]
374 374
            elif ([0,1] == dir):
375 375
                windowSize.reverse()
376 376
                xHalf = int(windowSize[0]*0.5)
......
383 383
                    if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break
384 384
                if i > windowSize[1]:
385 385
                    self.image[(pt[1]):(pt[1]+i), (pt[0]-xHalf*2):(pt[0]+xHalf*2)] = white
386
                    return [(pt[0], pt[1]), (pt[0], pt[1] + i)]
386
                    return [(pt[0], pt[1]), (pt[0], pt[1] + i - xHalf)]
387 387
            elif ([0,-1] == dir):
388 388
                windowSize.reverse()
389 389
                xHalf = int(windowSize[0]*0.5)
......
394 394
                for i in range(imgHeight-windowSize[1], -1, -1):
395 395
                    window = image[i:i+windowSize[1], 0:windowSize[0]]
396 396
                    if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break
397
                if abs(pt[1] - i) > windowSize[1]:
397
                if abs(pt[1] - i - windowSize[1]) > windowSize[1]:
398 398
                    self.image[(i+windowSize[1]):pt[1], (pt[0]-xHalf*2):(pt[0]+xHalf*2)] = white
399
                    return [(pt[0], pt[1]), (pt[0], i+windowSize[1])]
399
                    return [(pt[0], pt[1]), (pt[0], i+windowSize[1]+xHalf)]
400 400
        except Exception as ex:
401 401
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
402 402

  

내보내기 Unified diff

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