프로젝트

일반

사용자정보

개정판 26c50689

ID26c50689b468fddaf01149f4bfae30033d0701fd
상위 6693dc6c
하위 bb613a8a, aa1b6842

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

Tesseract OCR 시 전달받은 StartPoint 를 이용하도록 수정 / QOcrResultDialog 정보 표기에 이용되는 좌표의 경우 BoundingBox 정보를 포함하지 않도록 수식 변경

차이점 보기:

DTI_PID/DTI_PID/Commands/AreaOcrCommand.py
55 55
                            if textInfoList is not None and len(textInfoList) > 0:
56 56
                                for textInfo in textInfoList:
57 57
                                    print("Accepted")
58
                                    x = int(selectionBBox.x()) + textInfo.getX()
59
                                    y = int(selectionBBox.y()) + textInfo.getY()
58
                                    x = textInfo.getX()
59
                                    y = textInfo.getY()
60 60
                                    angle = textInfo.getAngle()
61 61
                                    text = textInfo.getText()
62 62
                                    width = textInfo.getW()
DTI_PID/DTI_PID/QOcrResultDialog.py
63 63
        self.image = self.image.transformed(transform)
64 64
        self.graphicsView.setImage(self.image)
65 65

  
66
    '''
67
        @history 2018.04.26 Jeongwoo Add Rectangle with modified Coords
68
    '''
66 69
    def detectText(self):
67 70
        buffer = QBuffer()
68 71
        buffer.open(QBuffer.ReadWrite)
69 72
        self.image.save(buffer, "PNG")
70 73
        pyImage = Image.open(io.BytesIO(buffer.data()))
71
        self.textInfoList = TOCR.getTextInfo(np.array(pyImage), (self.boundingBox.left(), self.boundingBox.top()))
74
        self.textInfoList = TOCR.getTextInfo(np.array(pyImage), (int(self.boundingBox.x()), int(self.boundingBox.y())))
72 75
        if self.textInfoList is not None and len(self.textInfoList) > 0:
73 76
            self.ui.detectResultTextEdit_2.setText(self.getPlainText(self.textInfoList))
74 77
            for textInfo in self.textInfoList:
75
                self.graphicsView.scene.addRect(textInfo.getX(), textInfo.getY(), textInfo.getW(), textInfo.getH(), QPen(Qt.red, 2, Qt.SolidLine))
78
                self.graphicsView.scene.addRect(textInfo.getX()-int(self.boundingBox.x()), textInfo.getY()-int(self.boundingBox.y()), textInfo.getW(), textInfo.getH(), QPen(Qt.red, 2, Qt.SolidLine))
76 79
        else:
77 80
            self.ui.detectResultTextEdit_2.setText("Not Found")
78 81

  
......
90 93
        @author     Jeongwoo
91 94
        @date       18.04.19
92 95
        @history    18.04.20    Jeongwoo    Calculate Start Point Coordinates by rotated angle
96
                    18.04.26    Jeongwoo    Scene.itemAt(textX - boundBox.x(), textY - boundBox.y())
93 97
    '''
94 98
    def accept(self):
95 99
        self.isAccepted = True
......
98 102
        if self.textInfoList is not None and len(self.textInfoList) > 0:
99 103
            for index in range(len(splitText)):
100 104
                textInfo = self.textInfoList[index]
101
                item = self.graphicsView.scene.itemAt(QPointF(float(textInfo.getX()), float(textInfo.getY())), QTransform())
105
                item = self.graphicsView.scene.itemAt(QPointF(float(textInfo.getX() - int(self.boundingBox.x())), float(textInfo.getY()-int(self.boundingBox.y()))), QTransform())
102 106
                if item is not None:
103 107
                    ## Transform rectangle for calculate start point
104 108
                    imgTransform = QTransform()
......
108 112
                        imgTransform.translate(self.image.width()*0.5, self.image.height()*0.5)
109 113
                    imgTransform.rotate(-abs(self.angle))
110 114
                    imgTransform.translate(-self.image.width()*0.5, -self.image.height()*0.5)
111
                    rect = QRect(textInfo.getX(), textInfo.getY(), textInfo.getW(), textInfo.getH())
115
                    rect = QRect(textInfo.getX() - int(self.boundingBox.x()), textInfo.getY() - int(self.boundingBox.y()), textInfo.getW(), textInfo.getH())
112 116
                    rect = imgTransform.mapRect(rect)
113 117
                    ## up to here
114
                    textInfo.setX(rect.x())
115
                    textInfo.setY(rect.y())
118
                    textInfo.setX(rect.x() + int(self.boundingBox.x()))
119
                    textInfo.setY(rect.y() + int(self.boundingBox.y()))
116 120
                    textInfo.setText(splitText[index])
117 121
                    radian = round(math.radians(abs(self.angle)), 2)
118 122
                    textInfo.setAngle(radian) # 360 degree == 6.28319 radian
DTI_PID/DTI_PID/tesseract_ocr_module.py
26 26
pytesseract.pytesseract.tesseract_cmd = 'D:\\Program Files\\Tesseract-OCR\\tesseract.exe'
27 27
tesseract_cmd = 'D:\\Program Files\\Tesseract-OCR\\tesseract.exe'
28 28

  
29
'''
30
    @history    2018.04.26  Jeongwoo    Make TextInfo object with Calculated Coords (with BoundBox Coords)
31
'''
29 32
def getTextInfo(img, startPoint, flag = FLAG_IMAGE_TO_BOXES, conf = """--psm 6 -c tessedit_char_whitelist=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-~.,/!@#$%&*(){}<>:;+=?\\"\\'"""):
30 33
    im = Image.fromarray(img)
31 34
    imgWidth = im.width
......
75 78
                lastCharHeight = charHeight
76 79
            else:
77 80
                # Save previous line
78
                prevLineText = ti.TextInfo(splitText[textGroupIndex], lineSp[0], lineSp[1], lastRT[0] - lineSp[0], lastCharHeight, 0)
81
                prevLineText = ti.TextInfo(splitText[textGroupIndex], startPoint[0]+lineSp[0], startPoint[1]+lineSp[1], lastRT[0] - lineSp[0], lastCharHeight, 0)
79 82
                textInfoList.append(prevLineText)
80 83
                textGroupIndex = textGroupIndex + 1
81 84

  
......
88 91
                lineRect = QRect(lineSp[0], lineSp[1], imgWidth - lineSp[0], ch)
89 92

  
90 93
        if not (len(textInfoList) > textGroupIndex) and textGroupIndex < len(splitText):
91
            textInfo = ti.TextInfo(splitText[textGroupIndex], lineSp[0], lineSp[1], lastRT[0] - lineSp[0], charHeight, 0)
94
            textInfo = ti.TextInfo(splitText[textGroupIndex], startPoint[0]+lineSp[0], startPoint[1]+lineSp[1], lastRT[0] - lineSp[0], charHeight, 0)
92 95
            if textInfo not in textInfoList:
93 96
                textInfoList.append(textInfo)
94 97
        else:

내보내기 Unified diff