프로젝트

일반

사용자정보

개정판 a92bc8a0

IDa92bc8a01f6bcaf9fc16a3b8f5174ad9ad33d09a
상위 ee4fc60f
하위 d9cdb857

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

Add Expand and Shrink size for recognizing text

차이점 보기:

DTI_PID/DTI_PID/DTI_PID.py
1094 1094
    docData = AppDocData.instance()
1095 1095
    project = docData.getCurrentProject()
1096 1096

  
1097
    #configs = docData.getConfigs('Text Size', 'Min Text Size')
1098
    #self.ui.minTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.minTextSizeSpinBox.setValue(30)
1099 1097
    configs = docData.getConfigs('Text Size', 'Max Text Size')
1100 1098
    maxTextSize = int(configs[0].value) if 1 == len(configs) else 100
1101 1099

  
......
1106 1104
    for contour in contours:
1107 1105
        # remove too big one
1108 1106
        [x, y, w, h] = cv2.boundingRect(contour)
1109
        if (w > maxTextSize or h > maxTextSize): continue
1107
        if (w > maxTextSize and h > maxTextSize): continue
1110 1108

  
1111 1109
        area = cv2.contourArea(contour, True)
1112 1110
        if area >= 0:
......
1119 1117
    cv2.imwrite(filePath, contourImg)
1120 1118

  
1121 1119
    rects = []
1122
    eroded = cv2.erode(contourImg, np.ones((8,8), np.uint8))
1120
    configs = docData.getConfigs('Text Recognition', 'Expand Size')
1121
    expandSize = int(configs[0].value) if 1 == len(configs) else 10
1122
    eroded = cv2.erode(contourImg, np.ones((expandSize,expandSize), np.uint8))
1123
    
1124
    filePath = os.path.join(project.getTempPath(), 'eroded_OCR.png')
1125
    cv2.imwrite(filePath, eroded)
1126

  
1123 1127
    eroded = cv2.bitwise_not(eroded)
1124 1128
    image, contours, hierarchy = cv2.findContours(eroded, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
1125 1129
    for contour in contours:
1126 1130
        area = cv2.contourArea(contour, True)
1127 1131
        if area < 0:
1128 1132
            [x, y, w, h] = cv2.boundingRect(contour)
1129
            if w < 10 and h < 10: continue; # skip too small one
1133
            if (w < 10 and h < 10) or (w > maxTextSize and h > maxTextSize): continue; # skip too small or big one
1130 1134
            
1131 1135
            img = contourImg[y:y+h, x:x+w]
1132 1136
            img = cv2.bitwise_not(img)

내보내기 Unified diff

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