Unverified Commit 9a3fe26e authored by myhloli's avatar myhloli Committed by GitHub

Merge pull request #71 from myhloli/master

fix remove error
parents 8c644744 f70289f9
...@@ -71,7 +71,9 @@ def remove_need_drop_blocks(all_bboxes, discarded_blocks): ...@@ -71,7 +71,9 @@ def remove_need_drop_blocks(all_bboxes, discarded_blocks):
for discarded_block in discarded_blocks: for discarded_block in discarded_blocks:
block_bbox = block[:4] block_bbox = block[:4]
if calculate_overlap_area_in_bbox1_area_ratio(block_bbox, discarded_block['bbox']) > 0.6: if calculate_overlap_area_in_bbox1_area_ratio(block_bbox, discarded_block['bbox']) > 0.6:
need_remove.append(block) if block not in need_remove:
need_remove.append(block)
break
if len(need_remove) > 0: if len(need_remove) > 0:
for block in need_remove: for block in need_remove:
...@@ -90,7 +92,7 @@ def remove_overlaps_min_blocks(all_bboxes): ...@@ -90,7 +92,7 @@ def remove_overlaps_min_blocks(all_bboxes):
overlap_box = get_minbox_if_overlap_by_ratio(block1_bbox, block2_bbox, 0.8) overlap_box = get_minbox_if_overlap_by_ratio(block1_bbox, block2_bbox, 0.8)
if overlap_box is not None: if overlap_box is not None:
bbox_to_remove = next((block for block in all_bboxes if block[:4] == overlap_box), None) bbox_to_remove = next((block for block in all_bboxes if block[:4] == overlap_box), None)
if bbox_to_remove is not None: if bbox_to_remove is not None and bbox_to_remove not in need_remove:
need_remove.append(bbox_to_remove) need_remove.append(bbox_to_remove)
if len(need_remove) > 0: if len(need_remove) > 0:
......
...@@ -14,14 +14,14 @@ def remove_overlaps_min_spans(spans): ...@@ -14,14 +14,14 @@ def remove_overlaps_min_spans(spans):
if span1 != span2: if span1 != span2:
overlap_box = get_minbox_if_overlap_by_ratio(span1['bbox'], span2['bbox'], 0.65) overlap_box = get_minbox_if_overlap_by_ratio(span1['bbox'], span2['bbox'], 0.65)
if overlap_box is not None: if overlap_box is not None:
bbox_to_remove = next((span for span in spans if span['bbox'] == overlap_box), None) span_need_remove = next((span for span in spans if span['bbox'] == overlap_box), None)
if bbox_to_remove is not None: if span_need_remove is not None and span_need_remove not in dropped_spans:
dropped_spans.append(bbox_to_remove) dropped_spans.append(span_need_remove)
if len(dropped_spans) > 0: if len(dropped_spans) > 0:
for dropped_span in dropped_spans: for span_need_remove in dropped_spans:
spans.remove(dropped_span) spans.remove(span_need_remove)
dropped_span['tag'] = DropTag.SPAN_OVERLAP span_need_remove['tag'] = DropTag.SPAN_OVERLAP
return spans, dropped_spans return spans, dropped_spans
...@@ -33,8 +33,9 @@ def remove_spans_by_bboxes(spans, need_remove_spans_bboxes): ...@@ -33,8 +33,9 @@ def remove_spans_by_bboxes(spans, need_remove_spans_bboxes):
for span in spans: for span in spans:
for removed_bbox in need_remove_spans_bboxes: for removed_bbox in need_remove_spans_bboxes:
if calculate_overlap_area_in_bbox1_area_ratio(span['bbox'], removed_bbox) > 0.5: if calculate_overlap_area_in_bbox1_area_ratio(span['bbox'], removed_bbox) > 0.5:
need_remove_spans.append(span) if span not in need_remove_spans:
break need_remove_spans.append(span)
break
if len(need_remove_spans) > 0: if len(need_remove_spans) > 0:
for span in need_remove_spans: for span in need_remove_spans:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment