프로젝트

일반

사용자정보

개정판 7c7f8619

ID7c7f8619b754884a386bd9d1442653bd95dac256
상위 63740307
하위 b456019a

함의성이(가) 약 5년 전에 추가함

issue #506: short text

Change-Id: I7f7b65252ed855621f0fdf9b6644ee81d6d095f7

차이점 보기:

DTI_PID/DTI_PID/MainWindow.py
1570 1570
    def onViewText(self, isChecked):
1571 1571
        selected = [item for item in self.graphicsView.scene().items() if issubclass(type(item), QEngineeringTextItem)]
1572 1572
        for item in selected:
1573
            item.setVisible(isChecked)
1573
            if type(item) is not QEngineeringLineNoTextItem:
1574
                item.setVisible(isChecked)
1574 1575

  
1575 1576
    '''
1576 1577
        @brief  visible/invisible Symbol 
DTI_PID/DTI_PID/OcrResultDialog.py
363 363
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
364 364
        imgNot = np.ones(img.shape, np.uint8)
365 365
        cv2.bitwise_not(img, imgNot)
366
        imgNot = cv2.dilate(imgNot, np.ones((8, 8), np.uint8))
366
        imgNot = cv2.dilate(imgNot, np.ones((4, 4), np.uint8))
367 367

  
368 368
        contours, hierarchy = cv2.findContours(imgNot, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
369 369
        minX, minY, maxX, maxY = sys.maxsize, sys.maxsize, 0, 0
DTI_PID/DTI_PID/tesseract_ocr_module.py
106 106
        im = Image.fromarray(img)
107 107
        # add padding to increase text recognition
108 108
        im = im.rotate(-angle, expand=True)
109
        imgWidth = im.width
110
        imgHeight = im.height
111 109
        
112
        #long_img = None
113
        #if imgHeight / imgWidth > 0.5 and imgHeight < maxSize:
114
        #    long_img = Image.new('RGB', (imgWidth * 3, imgHeight), (255, 255, 255))
115
        #    long_img.paste(im, (0, 0))
116
        #    long_img.paste(im, (imgWidth, 0))
117
        #    long_img.paste(im, (imgWidth * 2, 0))
118
        #    im = long_img
119

  
120 110
        im = ImageOps.expand(im, border=thickness, fill='white')
121 111
        imgWidth = im.width
122 112
        imgHeight = im.height
123 113

  
124 114
        boundaryOcrData = pytesseract.image_to_boxes(im, config=_conf, lang=oCRLang)
125

  
126 115
        bounding_boxes = boundaryOcrData.split('\n')
116

  
117
        long_img = None
118
        if not boundaryOcrData and imgHeight / imgWidth > 0.5 and abs(angle) < 1:
119
            img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
120
            imgNot = np.ones(img.shape, np.uint8)
121
            cv2.bitwise_not(img, imgNot)
122
            imgNot = cv2.dilate(imgNot, np.ones((3, 3), np.uint8))
123

  
124
            contours, hierarchy = cv2.findContours(imgNot, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
125
            minX, minY, maxX, maxY = sys.maxsize, sys.maxsize, 0, 0
126
            if len(contours) is 0:
127
                minX, minY, maxX, maxY = 0, 0, imgWidth, imgHeight
128
            else:
129
                minX, minY, maxX, maxY = sys.maxsize, sys.maxsize, 0, 0
130
                for cnt in contours:
131
                    x, y, w, h = cv2.boundingRect(cnt)
132
                    minX = min(x, minX)
133
                    minY = min(y, minY)
134
                    maxX = max(x + w, maxX)
135
                    maxY = max(y + h, maxY)
136
                minX, minY, maxX, maxY = minX, minY, maxX, maxY
137

  
138
            fit_width = maxX - minX
139
            fit_length = maxY - minY
140
            if fit_length < maxSize:
141
                long_img = Image.new('RGB', (maxX * 3, maxY), (255, 255, 255))
142
                fit_im = im.crop((minX + thickness, minY + thickness, minX + thickness + fit_width, minY + thickness + fit_length))
143
                long_img.paste(fit_im, (0, 0))
144
                long_img.paste(fit_im, (fit_width, 0))
145
                long_img.paste(fit_im, (fit_width * 2, 0))
146
                im = long_img
147

  
148
                im = ImageOps.expand(im, border=thickness, fill='white')
149
                imgWidth = im.width
150
                imgHeight = im.height
151
                offset_x, offset_y = minX, minY
152

  
153
                boundaryOcrData = pytesseract.image_to_boxes(im, config=_conf, lang=oCRLang)
154
                bounding_boxes = boundaryOcrData.split('\n')
155

  
127 156
        merged_boxes = []
128 157

  
129 158
        for box in bounding_boxes:
......
168 197
            if cropped.width == 0 or cropped.height == 0:
169 198
                continue
170 199
            text = pytesseract.image_to_string(cropped, config=_conf, lang=oCRLang)
171
            #if long_img:
172
            #    text = text[:int(len(text)/ 3)]
173
            #    rect = QRect(rect.left(), imgHeight - rect.bottom(), int((rect.width() - thickness)/ 3), rect.height())
200

  
201
            if long_img:
202
                text = text[:int(len(text)/ 3)]
203
                rect = QRect(rect.left() + offset_x, imgHeight - rect.bottom() + offset_y, int(rect.width()/ 3), rect.height())
174 204
            
175 205
            # skip if text is not allowed single character when text is one char
176 206
            if not text or (len(text) == 1 and text not in allowed_single_chars):
minorTools/makeClearSql.py
2 2
    import os
3 3
    
4 4
    sqlPath = os.path.join('E:\Projects\DTIPID_GERRIT\minorTools', 'clear.txt')
5
    
5

  
6
    drawing_uids = ['1e40e611-cd83-4c99-9711-b45321c3641e', '98240e9a-8ac9-4968-8203-7db2ace5023a']
7

  
8
    '''
6 9
    drawing_uids = ['ca0423e7-bde1-4b64-9d4a-45afa09d2b19', 'cf1166cd-b027-4d5e-88b2-d817e8d9638f', \
7 10
                    'd17b490e-9c33-4451-a727-0cfc076ee8f3', 'd7dd4f37-db5f-433a-b76a-9843027f4307', 'dc4df203-9fd7-47c0-a1c7-704be8f68719', \
8 11
                    'ecbe6ada-dd70-419f-8bf1-0df8edb524f0', 'f1cdd4b3-d54a-48e8-9855-85cdf426142e', 'f52d3484-f6bc-4a4f-b8a8-04f867b4cbb6', \
......
21 24
                    '18fcfb0d-1529-4cdf-a94f-47edab607bc2', '12bb5341-2038-44e7-b8d7-1d55be426bb2', '10c7e8e1-dd25-47f2-b691-71192693a12d', \
22 25
                    '0a4f828f-68c1-486c-83b9-4be49a443135', '07a5abbd-88d5-460f-89bc-7bb7cedc9746', '0547c696-1963-44c2-9eba-5100297edd40', \
23 26
                    '046e4093-9d9c-49f2-bd7c-af9afedf34d3', '03347731-0f96-4be7-b4bd-223d70c67f75', '016da493-0e9d-42d3-b942-5a45cb36335e']
27
    '''
24 28
    sqls = []
25 29

  
26 30
    for index in range(len(drawing_uids)):
minorTools/xmlTextSearcher.py
3 3
def finder():
4 4
    print("finder start")
5 5
    
6
    targetText = ['t strainer<']
6
    targetText = ['DESUPERHEATER<']
7 7
    path = 'W:\ID2_Project\POSCO\Temp'
8 8

  
9 9
    print("target : " + str(len(targetText)))

내보내기 Unified diff

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