프로젝트

일반

사용자정보

개정판 e41f2b9c

IDe41f2b9cf3d0c5295b57730fd0c4b0dcaf1d8a77
상위 65cdeb69
하위 8a4263cb

김정우 이(가) 6년 이상 전에 추가함

RemoveTextCommand 에서 텍스트 +-1 영역에사각형을 그리도록 변경 / tesseract_ocr_module에서 split된 텍스트 배열 사이즈 검사 / QSymbolEditorDialog 에 RemoveText 기능 활성화

차이점 보기:

DTI_PID/DTI_PID/Commands/RemoveTextCommand.py
18 18
import io
19 19

  
20 20
class RemoveTextCommand(AbstractCommand.AbstractCommand):
21
    '''
22
        @history    2018.05.09  Jeongwoo    Draw Rect on ±1 area
23
    '''
21 24
    def __init__(self, imageViewer):
22 25
        super(RemoveTextCommand, self).__init__(imageViewer)
23 26
        self.name = 'RemoveText' 
......
29 32
        pyImage = Image.open(io.BytesIO(buffer.data()))
30 33
        self.textInfoList = TOCR.getCharactersInfo(np.array(pyImage), (0, 0))
31 34
        pixmap = self.imageViewer.pixmap()
35
        ADJUST = 1
32 36
        for textInfo in self.textInfoList:
33 37
            painter = QPainter()
34 38
            painter.begin(pixmap)
35 39
            painter.setPen(QColor(255, 255, 255))
36 40
            painter.setBrush(QColor(255, 255, 255))
37
            painter.drawRect(QRect(textInfo.getX(), textInfo.getY(), textInfo.getW(), textInfo.getH()))
41
            painter.drawRect(QRect(textInfo.getX()-ADJUST, textInfo.getY()-ADJUST, textInfo.getW()+ADJUST, textInfo.getH()+ADJUST))
38 42
            painter.end()
39 43
        self.imageViewer.setImage(pixmap)
40 44
    
DTI_PID/DTI_PID/QSymbolEditorDialog.py
563 563
        @brief  Remove Text Tool Button Clicked
564 564
        @author Jeongwoo
565 565
        @date   2018.05.03
566
        @history    2018.05.09  Jeongwoo    Remove comment and activate RemoveTextCommand
566 567
    '''
567 568
    def removeTextClickEvent(self, event):
568 569
        print("removeText")
569
        QMessageBox.about(self.ui.removeTextButton, "알림", "추후 지원될 예정입니다.")
570
        #self.ui.imageView.command = RemoveTextCommand.RemoveTextCommand(self.ui.imageView)
570
        self.ui.imageView.command = RemoveTextCommand.RemoveTextCommand(self.ui.imageView)
571 571

  
572 572
    def adjustOriginalPoint(self, adjustX, adjustY):
573 573
        originalPoint = self.ui.originalPointLineEdit.text()
DTI_PID/DTI_PID/tesseract_ocr_module.py
34 34
    @brief      Get Text info in Symbol (Instrumentation, OPC, etc...)
35 35
    @author     Jeongwoo
36 36
    @date       2018.05.04
37
    @history    2018.05.09  Jeongwoo    Check split text' length
37 38
'''
38 39
def getTextInfoInSymbol(img, startPoint, flag = FLAG_IMAGE_TO_BOXES, conf = DEFAULT_CONF):
39 40
    im = Image.fromarray(img)
......
57 58
    for index in range(len(boundaryOcrData.split('\n'))):
58 59
        data = boundaryOcrData.split('\n')[index]
59 60
        sData = data.split(' ')
60
        char = sData[0]
61
        if len(sData) >= 5: 
62
            char = sData[0]
61 63

  
62
        if WHITE_LIST_CHARS.find(char) >= 0:
63
            csx = int(sData[1])
64
            csy = imgHeight - int(sData[4])
65
            cex = int(sData[3])
66
            cey = int(sData[2])
67
            cw = cex - csx
68
            ch = abs(cey - int(sData[4]))
64
            if WHITE_LIST_CHARS.find(char) >= 0:
65
                csx = int(sData[1])
66
                csy = imgHeight - int(sData[4])
67
                cex = int(sData[3])
68
                cey = int(sData[2])
69
                cw = cex - csx
70
                ch = abs(cey - int(sData[4]))
69 71
            
70
            if cw >= MIN_TEXT_SIZE or ch >= MIN_TEXT_SIZE:
71
                charWidth = max(charWidth, cw)
72
                charHeight = max(charHeight, ch)
73
                currentRect = None
74
                if lastRT != (-1, -1):
75
                    currentRect = QRect(csx, csy, csx + cw, csy + ch)
76
                if lastRT == (-1, -1) and lineRect is None:
77
                    tempText = tempText + char
78
                    lastRT = (csx+cw, csy)
79
                    lineSp = (csx, csy)
80
                    lastCharHeight = charHeight
81
                    lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], charHeight)
82
                elif (lineRect is not None and currentRect is not None) and lineRect.intersects(currentRect):
83
                    tempText = tempText + char
84
                    lastRT = (csx+cw, min(lineSp[1], csy))
85
                    lineSp = (lineSp[0], min(lineSp[1], csy))
86
                    lastCharHeight = charHeight
87
                    lineRect.setHeight(charHeight)
88
                else:
89
                    # Save previous line
90
                    prevLineText = ti.TextInfo(tempText, startPoint[0]+lineSp[0], startPoint[1]+lineSp[1], lastRT[0] - lineSp[0], lastCharHeight, 0)
91
                    textInfoList.append(prevLineText)
92
                    textGroupIndex = textGroupIndex + 1
93

  
94
                    # Start new line
95
                    tempText = char
96
                    charWidth = cw
97
                    charHeight = ch
98
                    lastRT = (csx + cw, csy)
99
                    lineSp = (csx, csy)
100
                    lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], ch)
72
                if cw >= MIN_TEXT_SIZE or ch >= MIN_TEXT_SIZE:
73
                    charWidth = max(charWidth, cw)
74
                    charHeight = max(charHeight, ch)
75
                    currentRect = None
76
                    if lastRT != (-1, -1):
77
                        currentRect = QRect(csx, csy, csx + cw, csy + ch)
78
                    if lastRT == (-1, -1) and lineRect is None:
79
                        tempText = tempText + char
80
                        lastRT = (csx+cw, csy)
81
                        lineSp = (csx, csy)
82
                        lastCharHeight = charHeight
83
                        lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], charHeight)
84
                    elif (lineRect is not None and currentRect is not None) and lineRect.intersects(currentRect):
85
                        tempText = tempText + char
86
                        lastRT = (csx+cw, min(lineSp[1], csy))
87
                        lineSp = (lineSp[0], min(lineSp[1], csy))
88
                        lastCharHeight = charHeight
89
                        lineRect.setHeight(charHeight)
90
                    else:
91
                        # Save previous line
92
                        prevLineText = ti.TextInfo(tempText, startPoint[0]+lineSp[0], startPoint[1]+lineSp[1], lastRT[0] - lineSp[0], lastCharHeight, 0)
93
                        textInfoList.append(prevLineText)
94
                        textGroupIndex = textGroupIndex + 1
95

  
96
                        # Start new line
97
                        tempText = char
98
                        charWidth = cw
99
                        charHeight = ch
100
                        lastRT = (csx + cw, csy)
101
                        lineSp = (csx, csy)
102
                        lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], ch)
101 103

  
102 104
    if not (len(textInfoList) > textGroupIndex) and (tempText is not None and len(tempText) > 0):
103 105
        textInfo = ti.TextInfo(tempText, startPoint[0]+lineSp[0], startPoint[1]+lineSp[1], lastRT[0] - lineSp[0], charHeight, 0)
......
112 114
    @brief      Get info about each character
113 115
    @author     Jeongwoo
114 116
    @date       2018.05.03
117
    @history    2018.05.09  Jeongwoo    Check split text' length
115 118
'''
116 119
def getCharactersInfo(img, startPoint, flag = FLAG_IMAGE_TO_BOXES, conf = DEFAULT_CONF):
117 120
    im = Image.fromarray(img)
......
123 126
    for index in range(len(boundaryOcrData.split('\n'))):
124 127
        data = boundaryOcrData.split('\n')[index]
125 128
        sData = data.split(' ')
126
        char = sData[0]
127
        csx = int(sData[1])
128
        csy = imgHeight - int(sData[4])
129
        cex = int(sData[3])
130
        cey = int(sData[2])
131
        cw = cex - csx
132
        ch = abs(cey - int(sData[4]))
129
        if len(sData) >= 5: 
130
            char = sData[0]
131
            csx = int(sData[1])
132
            csy = imgHeight - int(sData[4])
133
            cex = int(sData[3])
134
            cey = int(sData[2])
135
            cw = cex - csx
136
            ch = abs(cey - int(sData[4]))
133 137

  
134
        textInfoList.append(ti.TextInfo(char, startPoint[0]+csx, startPoint[1]+csy, cw, ch, 0))
138
            textInfoList.append(ti.TextInfo(char, startPoint[0]+csx, startPoint[1]+csy, cw, ch, 0))
135 139

  
136 140
    return textInfoList
137 141

  
......
139 143
'''
140 144
    @history    2018.04.26  Jeongwoo    Make TextInfo object with Calculated Coords (with BoundBox Coords)
141 145
                2018.04.30  Jeongwoo    Add QRect.setHeight() in if-statement [(lineRect is not None and currentRect is not None) and lineRect.intersects(currentRect)]
146
                2018.05.09  Jeongwoo    Check split text' length
142 147
'''
143 148
def getTextInfo(img, startPoint, flag = FLAG_IMAGE_TO_BOXES, conf = DEFAULT_CONF):
144 149
    im = Image.fromarray(img)
......
164 169
        for index in range(len(boundaryOcrData.split('\n'))):
165 170
            data = boundaryOcrData.split('\n')[index]
166 171
            sData = data.split(' ')
167
            char = sData[0]
168
            csx = int(sData[1])
169
            csy = imgHeight - int(sData[4])
170
            cex = int(sData[3])
171
            cey = int(sData[2])
172
            cw = cex - csx
173
            ch = abs(cey - int(sData[4]))
174
            charWidth = max(charWidth, cw)
175
            charHeight = max(charHeight, ch)
176
            currentRect = None
177
            if lastRT != (-1, -1):
178
                currentRect = QRect(csx, csy, csx + cw, csy + ch)
179
            if lastRT == (-1, -1) and lineRect is None:
180
                tempText = tempText + char
181
                lastRT = (csx+cw, csy)
182
                lineSp = (csx, csy)
183
                lastCharHeight = charHeight
184
                lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], charHeight)
185
            elif (lineRect is not None and currentRect is not None) and lineRect.intersects(currentRect):
186
                tempText = tempText + char
187
                lastRT = (csx+cw, min(lineSp[1], csy))
188
                lineSp = (lineSp[0], min(lineSp[1], csy))
189
                lastCharHeight = charHeight
190
                lineRect.setHeight(charHeight)
191
            else:
192
                # Save previous line
193
                prevLineText = ti.TextInfo(splitText[textGroupIndex], startPoint[0]+lineSp[0], startPoint[1]+lineSp[1], lastRT[0] - lineSp[0], lastCharHeight, 0)
194
                textInfoList.append(prevLineText)
195
                textGroupIndex = textGroupIndex + 1
196

  
197
                # Start new line
198
                tempText = char
199
                charWidth = cw
200
                charHeight = ch
201
                lastRT = (csx + cw, csy)
202
                lineSp = (csx, csy)
203
                lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], ch)
172
            if len(sData) >= 5:
173
                char = sData[0]
174
                csx = int(sData[1])
175
                csy = imgHeight - int(sData[4])
176
                cex = int(sData[3])
177
                cey = int(sData[2])
178
                cw = cex - csx
179
                ch = abs(cey - int(sData[4]))
180
                charWidth = max(charWidth, cw)
181
                charHeight = max(charHeight, ch)
182
                currentRect = None
183
                if lastRT != (-1, -1):
184
                    currentRect = QRect(csx, csy, csx + cw, csy + ch)
185
                if lastRT == (-1, -1) and lineRect is None:
186
                    tempText = tempText + char
187
                    lastRT = (csx+cw, csy)
188
                    lineSp = (csx, csy)
189
                    lastCharHeight = charHeight
190
                    lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], charHeight)
191
                elif (lineRect is not None and currentRect is not None) and lineRect.intersects(currentRect):
192
                    tempText = tempText + char
193
                    lastRT = (csx+cw, min(lineSp[1], csy))
194
                    lineSp = (lineSp[0], min(lineSp[1], csy))
195
                    lastCharHeight = charHeight
196
                    lineRect.setHeight(charHeight)
197
                else:
198
                    # Save previous line
199
                    prevLineText = ti.TextInfo(splitText[textGroupIndex], startPoint[0]+lineSp[0], startPoint[1]+lineSp[1], lastRT[0] - lineSp[0], lastCharHeight, 0)
200
                    textInfoList.append(prevLineText)
201
                    textGroupIndex = textGroupIndex + 1
202

  
203
                    # Start new line
204
                    tempText = char
205
                    charWidth = cw
206
                    charHeight = ch
207
                    lastRT = (csx + cw, csy)
208
                    lineSp = (csx, csy)
209
                    lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], ch)
204 210

  
205 211
        if not (len(textInfoList) > textGroupIndex) and textGroupIndex < len(splitText):
206 212
            textInfo = ti.TextInfo(splitText[textGroupIndex], startPoint[0]+lineSp[0], startPoint[1]+lineSp[1], lastRT[0] - lineSp[0], charHeight, 0)

내보내기 Unified diff