boxes[i] += [hor_min, hor_max] lines.append(img[box[0]:box[1], box[2]:box[3]]) # bounding boxes in shape [x_min, y_min, width, height] bboxes = [[box[2], box[0], box[3] - box[2], box[1] - box[0]] for box in boxes] return lines, bboxes if __name__ == "__main__": args = Arguments() args.n_angles = 50 args.n_bins = 30 img = load_img('data/5.jpg') rotated = correct_rot(img, args) lines, bboxes = extract_lines(rotated, args) plt.imshow(img[0:150, 0:200], cmap='gray') plt.xticks([]) plt.yticks([]) #plt.savefig('plots/to_be_rotated.pdf', bbox_inches='tight') plt.show() o = 50 fig = plt.figure() ax = fig.add_subplot(111)
# turning angle angle = angles[np.argmin(H)] angle = -angle * 180 / np.pi # rotating image img = rotate(img, angle) return img if __name__ == "__main__": args = Arguments() args.n_angles = 50 args.n_bins = 100 img = load_img('data_test/1.jpg') rotated = correct_rot(img, args) plt.imshow(img[0:150, 0:200], cmap='gray') plt.xticks([]) plt.yticks([]) #plt.savefig('plots/to_be_rotated.pdf', bbox_inches='tight') plt.show() plt.imshow(rotated[50:200, 50:250], cmap='gray') plt.grid(True) plt.xticks([]) plt.yticks([]) #plt.savefig('plots/rotated.pdf', bbox_inches='tight')