remove unused function (used by old table extraction)

This commit is contained in:
Robert Sachunsky 2026-07-30 15:35:24 +02:00
parent fa21cff3a9
commit 642363c7d0

View file

@ -893,78 +893,6 @@ class Eynollah:
self.logger.debug("exit do_order_of_regions") self.logger.debug("exit do_order_of_regions")
return results return results
def check_iou_of_bounding_box_and_contour_for_tables(
self, layout, table_prediction_early, pixel_table, num_col_classifier):
layout_org = np.copy(layout)
layout_org[layout_org == pixel_table] = 0
layout = (layout == pixel_table).astype(np.uint8) * 1
_, thresh = cv2.threshold(layout, 0, 255, 0)
contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnt_size = np.array([cv2.contourArea(cnt) for cnt in contours])
contours_new = []
for i, contour in enumerate(contours):
x, y, w, h = cv2.boundingRect(contour)
iou = cnt_size[i] /float(w*h) *100
if iou<80:
layout_contour = np.zeros(layout_org.shape[:2])
layout_contour = cv2.fillPoly(layout_contour, pts=[contour] ,color=1)
layout_contour_sum = layout_contour.sum(axis=0)
layout_contour_sum_diff = np.diff(layout_contour_sum)
layout_contour_sum_diff= np.abs(layout_contour_sum_diff)
layout_contour_sum_diff_smoothed= gaussian_filter1d(layout_contour_sum_diff, 10)
peaks, _ = find_peaks(layout_contour_sum_diff_smoothed, height=0)
peaks= peaks[layout_contour_sum_diff_smoothed[peaks]>4]
for j in range(len(peaks)):
layout_contour[:,peaks[j]-3+1:peaks[j]+1+3] = 0
layout_contour=cv2.erode(layout_contour[:,:], KERNEL, iterations=5)
layout_contour=cv2.dilate(layout_contour[:,:], KERNEL, iterations=5)
layout_contour = layout_contour.astype(np.uint8)
_, thresh = cv2.threshold(layout_contour, 0, 255, 0)
contours_sep, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for ji in range(len(contours_sep) ):
contours_new.append(contours_sep[ji])
if num_col_classifier>=2:
only_recent_contour_image = np.zeros(layout.shape[:2])
only_recent_contour_image = cv2.fillPoly(only_recent_contour_image,
pts=[contours_sep[ji]], color=1)
table_pixels_masked_from_early_pre = only_recent_contour_image * table_prediction_early
iou_in = 100. * table_pixels_masked_from_early_pre.sum() / only_recent_contour_image.sum()
#print(iou_in,'iou_in_in1')
if iou_in>30:
layout_org = cv2.fillPoly(layout_org, pts=[contours_sep[ji]], color=pixel_table)
else:
pass
else:
layout_org= cv2.fillPoly(layout_org, pts=[contours_sep[ji]], color=pixel_table)
else:
contours_new.append(contour)
if num_col_classifier>=2:
only_recent_contour_image = np.zeros(layout.shape[:2])
only_recent_contour_image = cv2.fillPoly(only_recent_contour_image, pts=[contour],color=1)
table_pixels_masked_from_early_pre = only_recent_contour_image * table_prediction_early
iou_in = 100. * table_pixels_masked_from_early_pre.sum() / only_recent_contour_image.sum()
#print(iou_in,'iou_in')
if iou_in>30:
layout_org = cv2.fillPoly(layout_org, pts=[contour], color=pixel_table)
else:
pass
else:
layout_org = cv2.fillPoly(layout_org, pts=[contour], color=pixel_table)
return layout_org, contours_new
def delete_separator_around(self, splitter_y, peaks_neg, image_by_region, label_seps, label_table): def delete_separator_around(self, splitter_y, peaks_neg, image_by_region, label_seps, label_table):
# format of subboxes: box=[x1, x2 , y1, y2] # format of subboxes: box=[x1, x2 , y1, y2]
pix_del = 100 pix_del = 100