def _find_horizontal_line_space(self, v_ind, prev_space, borders): """find left and right border of horizontal space in given line (v_ind) if there is several of them""" zeros = sspace._find_zeros(self.line.im[v_ind, range(prev_space[0], prev_space[1])]) if len(zeros) > 1: print("Expected 0 or 1 spaces at next line, but got %s" % [(z[0] + prev_space[0], z[1] + prev_space[0]) for z in zeros]) max_length = 0 zero = [0, 0] for z in zeros: if z[1] - z[0] > max_length: zero = z elif len(zeros) == 1: zero = zeros[0] else: return None right = zero[1] + prev_space[0] while right < borders[1] and self.line.im[v_ind, right] == 0: right += 1 left = zero[0] + prev_space[0] while left > borders[0] and self.line.im[v_ind, left] == 0: left -= 1 if left < borders[0] or borders[1] < right: return None return left + 1, right
def _find_horizontal_line_space(self, v_ind, prev_space, borders): """find left and right border of horizontal space in given line (v_ind) if there is several of them""" zeros = sspace._find_zeros( self.line.im[v_ind, range(prev_space[0], prev_space[1])]) if len(zeros) > 1: print("Expected 0 or 1 spaces at next line, but got %s" % [(z[0] + prev_space[0], z[1] + prev_space[0]) for z in zeros]) max_length = 0 zero = [0, 0] for z in zeros: if z[1] - z[0] > max_length: zero = z elif len(zeros) == 1: zero = zeros[0] else: return None right = zero[1] + prev_space[0] while right < borders[1] and self.line.im[v_ind, right] == 0: right += 1 left = zero[0] + prev_space[0] while left > borders[0] and self.line.im[v_ind, left] == 0: left -= 1 if left < borders[0] or borders[1] < right: return None return left + 1, right
def _find_vertical_space(self, horizontal, vertical): """find vertical space borders in given zone""" sub_zone = self.line.absoluteZone(horizontal, vertical).extract() spaces = sspace._find_zeros(np.sum(sub_zone, 0)) if spaces is None or len(spaces) == 0: return None space = spaces[-1] return space[0] + horizontal[0], space[1] + horizontal[0]