def get_vertical_white_edge_dis(img): """Get vertical white edge distance of character image. Args: img: Character image. Returns: An interger distance. """ bw = imu.preprocess_bw_inv(img) weight, profile = imu.horizontal_proj(bw) horCoorY1 = 0 if weight[0] == 0: i = 0 while weight[i] == 0 and i < len(weight): i += 1 horCoorY1 = i horCoorY2 = len(weight) - 1 if weight[-1] == 0: j = len(weight) - 1 while weight[j] == 0 and j > 0: j -= 1 horCoorY2 = j return horCoorY1, len(weight) - horCoorY2
def divide_hor(img, coor): """Divide paper by blank detection in horizontal direction. Args: img: Image to be divided. Returns: A list of vertical coordinates. """ h, w = img.shape[0:2] result = [] for c in coor: horCoorY1 = [] horCoorY2 = [] imgPart = img[0:h, c[0]:c[1]] bw = imu.preprocess_bw_inv(imgPart) weight, profile = imu.horizontal_proj(bw) if weight[0] > 0: horCoorY1.append(0) for i in range(1, len(weight) - 1): if weight[i] > 0: if weight[i + 1] == 0: horCoorY2.append(i) if weight[i - 1] == 0: horCoorY1.append(i) if weight[-1] > 0: horCoorY2.append(len(weight) - 1) # print(verCoorX1) # print(verCoorX2) line = list(zip(horCoorY1, horCoorY2)) for l in line: if l[1] - l[0] > 10: result.append((c[0], l[0], c[1], l[1])) return result