added todo comments

This commit is contained in:
Matthias Bisping 2022-02-06 21:25:01 +01:00
parent 90b8613bf8
commit 295666c28f
2 changed files with 8 additions and 4 deletions

View File

@ -6,7 +6,7 @@ import cv2
import numpy as np
from pdf2image import pdf2image
from vidocp.utils.display import show_mpl
from vidocp.utils.display import show_mpl, show_cv2
from vidocp.utils.draw import draw_stats, draw_rectangles
from vidocp.utils.filters import is_large_enough
from vidocp.utils.post_processing import remove_isolated, xywh_to_vecs, xywh_to_vec_rect, vecs_to_vec_rect, adjacent1d
@ -39,6 +39,7 @@ def isolate_vertical_and_horizontal_components(img_bin):
return img_bin_final
# FIXME: does not work yet
def has_table_shape(rects):
assert isinstance(rects, list)
@ -83,6 +84,7 @@ def parse_table(image: np.array):
th1, img_bin = cv2.threshold(gray_scale, 150, 255, cv2.THRESH_BINARY)
img_bin = ~img_bin
img_bin = isolate_vertical_and_horizontal_components(img_bin)
img_bin_final = add_external_contours(img_bin, img_bin)
@ -90,6 +92,7 @@ def parse_table(image: np.array):
stats = np.vstack(list(filter(is_large_enough, stats)))
rects = stats[:, :-1][2:]
# FIXME: produces false negatives for `data0/043d551b4c4c768b899eaece4466c836.pdf 1 --type table`
rects = list(remove_isolated(rects, input_sorted=True))
# print(f"{has_table_shape(rects) = }")

View File

@ -17,11 +17,12 @@ def remove_overlapping(rectangles):
def remove_included(rectangles):
def included(a, b):
return b.xmin >= a.xmin and b.ymin >= a.ymin and b.xmax <= a.xmax and b.ymax <= a.ymax
def includes(a, b, tol=3):
"""does a include b?"""
return b.xmin + tol >= a.xmin and b.ymin + tol >= a.ymin and b.xmax - tol <= a.xmax and b.ymax - tol <= a.ymax
def is_not_included(rect, rectangles):
return not any(included(r2, rect) for r2 in rectangles if not rect == r2)
return not any(includes(r2, rect) for r2 in rectangles if not rect == r2)
rectangles = list(map(xywh_to_vec_rect, rectangles))
rectangles = filter(partial(is_not_included, rectangles=rectangles), rectangles)