diff --git a/vidocp/table_parsing.py b/vidocp/table_parsing.py index 8d71baf..155cc15 100644 --- a/vidocp/table_parsing.py +++ b/vidocp/table_parsing.py @@ -5,7 +5,6 @@ from operator import attrgetter import cv2 import numpy as np from pdf2image import pdf2image -from scipy import ndimage from vidocp.utils.display import show_mpl from vidocp.utils.draw import draw_rectangles @@ -25,53 +24,6 @@ def add_external_contours(image, img): return image -# def rotate_line_components(img_bin_h, img_bin_v): -# def get_avg_angle(img_bin): -# edges = cv2.Canny(img_bin, 50, 150, apertureSize=3) -# lines = cv2.HoughLines(edges, 1, np.pi / 180, 200) -# angles_deg = [] -# -# for line in lines: -# line = line[0] -# rho, theta = line -# angles_deg.append(180 / np.pi * theta) -# -# avg_ang_deg = sum(angles_deg) / len(angles_deg) -# return avg_ang_deg -# -# avg_ang_h = get_avg_angle(img_bin_h) -# avg_ang_v = get_avg_angle(img_bin_v) -# print(avg_ang_h,avg_ang_v) -# -# if avg_ang_h > avg_ang_v: # leftrotated scan -# rot_ang_h = 270 + avg_ang_h -# rot_ang_v = avg_ang_v -# elif avg_ang_h < avg_ang_v: # rightrotated scan -# rot_ang_h = 90 - avg_ang_h -# rot_ang_v = avg_ang_v -# print(rot_ang_h, rot_ang_v) -# img_bin_hr = ndimage.rotate(img_bin_h, rot_ang_h, reshape=False) -# img_bin_vr = ndimage.rotate(img_bin_v, rot_ang_v, reshape=False) -# #show_mpl(img_bin_hr) -# -# -# # print(average_angle_in_deg, "angle before angle correction") -# # # average_angle_in_deg = 90 - average_angle_in_deg -# # # print(average_angle_in_deg) -# # if average_angle_in_deg == 0.0 or average_angle_in_deg == 90.0: -# # print("angle is 0 or 90") -# # return img_bin -# # elif average_angle_in_deg > 0: #linksrtoation im originalbild -# # print("leftrot angle is not 0 or 90") -# # average_angle_in_deg = 360 - average_angle_in_deg -# # else: -# # print("rightrot", average_angle_in_deg) -# # print(average_angle_in_deg, "angle for Rotationsmatrix") -# # img_bin_rotated = ndimage.rotate(img_bin, average_angle_in_deg, reshape=False) -# # show_mpl(img_bin_rotated) -# -# return img_bin_hr, img_bin_vr - def isolate_vertical_and_horizontal_components(img_bin, bounding_rects): line_min_width = 48 @@ -82,8 +34,6 @@ def isolate_vertical_and_horizontal_components(img_bin, bounding_rects): img_bin_v = cv2.morphologyEx(img_bin, cv2.MORPH_OPEN, kernel_v) show_mpl(img_bin_h | img_bin_v) - # img_bin_h, img_bin_v = rotate_line_components(img_bin_h,img_bin_v) - kernel_h = np.ones((1, 30), np.uint8) kernel_v = np.ones((30, 1), np.uint8) img_bin_h = cv2.dilate(img_bin_h, kernel_h, iterations=2)