프로젝트

일반

사용자정보

개정판 50bc35f8

ID50bc35f8467443f3d636f3e31b7cd34409cd4856
상위 07480b60
하위 a7f6a96b

humkyung 이(가) 6년 이상 전에 추가함

fixed issue #537: 미인식 부분 사용자 통보

차이점 보기:

DTI_PID/DTI_PID/DTI_PID.py
667 667
    @brief  draw found symbols and texts
668 668
    @author Jeongwoo
669 669
'''
670
def drawFoundSymbolsOnCanvas(drawingPath , width, height, listWidget):
670
def drawFoundSymbolsOnCanvas(drawingPath , textInfos , listWidget):
671 671
    global src
672 672
    global srcGray
673 673
    global ocrCompletedSrc
674 674
    global searchedSymbolList
675 675
    global canvas
676
    global textInfoList
677 676

  
678 677
    canvas = np.zeros(src.shape, np.uint8)
679 678
    canvas[::] = (255, 255, 255)
......
685 684
        for symbol in searchedSymbolList:
686 685
            drawFoundSymbols(symbol, listWidget)
687 686

  
688
        for text in textInfoList:
689
            if not checkTextInSymbol((text.getX(), text.getY())):
690
                left = text.getX()
691
                top = text.getY()
692
                right = text.getX() + text.getW()
693
                bottom = text.getY() + text.getH()
687
        for text in textInfos:
688
            #if not checkTextInSymbol((text.getX(), text.getY())):
689
            left = text.getX()
690
            top = text.getY()
691
            right = text.getX() + text.getW()
692
            bottom = text.getY() + text.getH()
694 693

  
695
                canvas[top:bottom, left:right] = src[top:bottom, left:right]
694
            canvas[top:bottom, left:right] = src[top:bottom, left:right]
696 695

  
697
        cv2.imwrite(os.path.join(project.getTempPath(), "found_" + os.path.basename(drawingPath)), canvas)
696
        cv2.imwrite(os.path.join(project.getTempPath(), "FOUND_" + os.path.basename(drawingPath)), canvas)
698 697
    except Exception as ex:
699 698
        print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
700 699
        
......
803 802
                        print(tInfo.getText())
804 803
                updateProgressSignal.emit(maxProgressValue)
805 804

  
806
            cv2.imwrite(os.path.join(project.getTempPath(), "ocr_" + os.path.basename(mainRes)), ocrCompletedSrc)
805
            cv2.imwrite(os.path.join(project.getTempPath(), "XOCR_" + os.path.basename(mainRes)), ocrCompletedSrc)
807 806

  
808 807
        # parse Note
809 808
        noteArea = AppDocData.instance().getArea('Note')
......
1029 1028
                pool.shutdown(wait = True)
1030 1029

  
1031 1030
                chan, docData.imgWidth, docData.imgHeight = src.shape[::-1]
1032
                drawFoundSymbolsOnCanvas(mainRes, docData.imgWidth, docData.imgHeight, listWidget)
1031
                drawFoundSymbolsOnCanvas(mainRes, textInfoList, listWidget)
1033 1032
                
1034 1033
                docData.imgName = os.path.splitext(os.path.basename(mainRes))[0]
1035 1034

  
......
1060 1059
                listWidget.addItem("Recognized symbol count : " + str(len(searchedSymbolList)))
1061 1060
                
1062 1061
                # get difference between original and recognized image
1063
                foundFilePath = os.path.join(project.getTempPath(), "found_" + os.path.basename(path))
1062
                foundFilePath = os.path.join(project.getTempPath(), "FOUND_" + os.path.basename(path))
1064 1063
                getDifference(path, foundFilePath)
1065 1064
                # up to here
1066 1065
                
......
1143 1142
                [_x, _y, _w, _h] = cv2.boundingRect(xx)
1144 1143
                cv2.rectangle(img, (_x, _y), (_x+_w, _y+_h), 255, 1)
1145 1144

  
1146
                if (_w < _h*1.3) or (_w > maxTextSize and _h < maxTextSize): # width is greater than height*1.3(times 1.3 becase of 'W' character)
1145
                if (_w < _h) or (_w > maxTextSize and _h < maxTextSize): # width is greater than height
1147 1146
                    horizontal += 1 + (_w*_h)/(w*h)
1148 1147
                else:
1149 1148
                    vertical += 1 + (_w*_h)/(w*h)
......
1211 1210
                imgNotOper = cv2.bitwise_not(imgRecognized[y:y+height, x:x+width])
1212 1211
                imgDiff[y:y+height, x:x+width] = cv2.bitwise_xor(imgOriginal[y:y+height, x:x+width], imgNotOper)
1213 1212
                
1214
            # Remove Noise
1215
            kernel = np.ones((5, 5), np.uint8)
1216
            imgDiff = cv2.dilate(imgDiff, kernel)
1213
            # remove noise
1214
            imgDiff = cv2.dilate(imgDiff, np.ones((2, 2), np.uint8))
1217 1215

  
1218 1216
            docData = AppDocData.instance()
1219 1217
            project = docData.getCurrentProject()
1220
            cv2.imwrite(os.path.join(project.getTempPath(), "diff_" + os.path.basename(orgImagePath)), imgDiff)
1218
            cv2.imwrite(os.path.join(project.getTempPath(), "DIFF_" + os.path.basename(orgImagePath)), imgDiff)
1221 1219
    except Exception as ex:
1222 1220
        print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
1223 1221
   
DTI_PID/DTI_PID/MainWindow.py
675 675
            windowSize = docData.getSlidingWindowSize()
676 676
            thickness = int(windowSize[1])
677 677

  
678
            diffFilePath = os.path.join(project.getTempPath(), "diff_" + os.path.basename(self.path))
678
            diffFilePath = os.path.join(project.getTempPath(), "DIFF_" + os.path.basename(self.path))
679 679
            imgDiff = cv2.threshold(cv2.cvtColor(cv2.imread(diffFilePath, 1), cv2.COLOR_BGR2GRAY), 127, 255, cv2.THRESH_BINARY)[1]
680 680

  
681 681
            lines = [item for item in self.graphicsView.scene.items() if (type(item) is QEngineeringLineItem)]
......
686 686
                cv2.line(imgDiff, (round(ptStart[0]), round(ptStart[1])), (round(ptEnd[0]), round(ptEnd[1])), 255, thickness)
687 687
                # up to here
688 688

  
689
            #cv2.imwrite(diffFilePath, imgDiff)
690
            
691
            # get difference part and then display it
692
            #imgDiff = cv2.cvtColor(cv2.imread(diffFilePath, 1), cv2.COLOR_BGR2GRAY)
693
            #ret, mask = cv2.threshold(imgDiff, 127, 255, cv2.THRESH_BINARY)
694 689
            imgNot = np.ones(imgDiff.shape, np.uint8)
695 690
            cv2.bitwise_not(imgDiff, imgNot)
696
            #imgNot = cv2.dilate(imgNot, np.ones((8, 8), np.uint8))
691
            imgNot = cv2.dilate(imgNot, np.ones((8,8), np.uint8))
697 692

  
698 693
            image, contours, hierarchy = cv2.findContours(imgNot, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
699 694
            for contour in contours:
......
702 697
                # remove too small one
703 698
                if (w < 10 or h < 10): continue
704 699

  
700
                # create unknown item
705 701
                epsilon = cv2.arcLength(contour, True)*0.01
706 702
                approx = cv2.approxPolyDP(contour, epsilon, True)
707 703
                approx = [pt[0] for pt in approx]
708 704
                item = QEngineeringUnknownItem(approx)
709 705
                item.transfer.removed.connect(self.itemRemoved)
710 706
                self.addUnknownItemToScene(item)
711
            # up to here
707
                # up to here
712 708

  
713
            notFilePath = os.path.join(project.getTempPath(), "not_" + os.path.basename(self.path))
709
            notFilePath = os.path.join(project.getTempPath(), "NOT_" + os.path.basename(self.path))
714 710
            cv2.imwrite(notFilePath, imgNot)
715 711
        except Exception as ex:
716 712
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
......
924 920
        unknownItem.setZValue(-10)
925 921
        unknownItem.addUnknownItemToScene(self.graphicsView.scene)
926 922

  
927

  
928 923
    '''
929 924
        @brief      generate output xml file
930 925
        @author     humkyung
DTI_PID/DTI_PID/QcImageViewer.py
64 64
    def wheelEvent(self, event):
65 65
        if self.isPressCtrl == True:
66 66
            event.modifiers()
67
            print("Pressed Ctrl and Mouse Wheel")
68 67

  
69 68
    def initImage(self):
70 69
        self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
DTI_PID/DTI_PID/QtImageViewer.py
322 322

  
323 323
    def wheelEvent(self, event):
324 324
        if self.isPressCtrl == True:
325
            print("Pressed Ctrl and Mouse Wheel")
326 325
            if self.canZoom and self.hasImage():
327 326
                numDegrees = event.angleDelta() / 8
328 327
                if numDegrees is not None:
DTI_PID/DTI_PID/Shapes/QEngineeringUnknownItem.py
122 122
        @date       2018.06.14
123 123
    '''
124 124
    def addUnknownItemToScene(self, scene):
125
        self.setPen(QPen(Qt.red, 5, Qt.DashDotLine))
125
        self.setPen(QPen(Qt.red, 1, Qt.DashDotLine))
126 126
        self.setZValue(1.0)
127 127
        scene.addItem(self)
128 128

  

내보내기 Unified diff