@staticmethod<EOL><INDENT>def _guess_lines(ys, max_lines=<NUM_LIT:50>, confidence_minimum=<NUM_LIT:0.0>):<DEDENT>
ys = ys.astype(numpy.float32)<EOL>compactness_list, means_list, diffs, deviations = [], [], [], []<EOL>start_n = <NUM_LIT:1><EOL>for k in range(start_n, min(len(ys), max_lines)):<EOL><INDENT>compactness, classified_points, means = cv2.kmeans(data=ys, K=k, bestLabels=None, criteria=(<EOL>cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_MAX_ITER, <NUM_LIT:1>, <NUM_LIT:10>), attempts=<NUM_LIT:2>, flags=cv2.KMEANS_PP_CENTERS)<EOL>means = numpy.sort(means, axis=<NUM_LIT:0>)<EOL>means_list.append(means)<EOL>compactness_list.append(compactness)<EOL>if k < <NUM_LIT:3>:<EOL><INDENT>tmp1 = [<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT>, <NUM_LIT>]  <EOL><DEDENT>else:<EOL><INDENT>tmp1 = numpy.diff(means, axis=<NUM_LIT:0>)  <EOL><DEDENT>tmp2 = numpy.std(tmp1) / numpy.mean(means)  <EOL>tmp3 = numpy.sum((tmp1 - numpy.mean(tmp1)) ** <NUM_LIT:2>)  <EOL>diffs.append(tmp1)<EOL>deviations.append(tmp3)<EOL><DEDENT>compactness_list = numpy.diff(<EOL>numpy.log(numpy.array(compactness_list) + <NUM_LIT>))  <EOL>deviations = numpy.array(deviations[<NUM_LIT:1>:])<EOL>deviations[<NUM_LIT:0>] = numpy.mean(deviations[<NUM_LIT:1>:])<EOL>compactness_list = (compactness_list - numpy.mean(compactness_list)) / numpy.std(compactness_list)<EOL>deviations = (deviations - numpy.mean(deviations)) / numpy.std(deviations)<EOL>aglomerated_metric = <NUM_LIT:0.1> * compactness_list + <NUM_LIT> * deviations<EOL>i = numpy.argmin(aglomerated_metric) + <NUM_LIT:1><EOL>lines = means_list[i]<EOL>betterness = numpy.sort(aglomerated_metric, axis=<NUM_LIT:0>)<EOL>confidence = (betterness[<NUM_LIT:1>] - betterness[<NUM_LIT:0>]) / (betterness[<NUM_LIT:2>] - betterness[<NUM_LIT:1>])<EOL>if confidence < confidence_minimum:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>return lines<EOL>
guesses and returns text inter-line distance, number of lines, y_position of first line