From c25c8d764ed8fdd9a478bf7e5467ea1f3b5b1734 Mon Sep 17 00:00:00 2001 From: cdietrich Date: Tue, 4 Oct 2022 13:40:42 +0200 Subject: [PATCH] black --- cv_analysis/utils/connect_rects.py | 48 ++++++++++++++++++----------- cv_analysis/utils/postprocessing.py | 2 +- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/cv_analysis/utils/connect_rects.py b/cv_analysis/utils/connect_rects.py index 09d48bb..9a438da 100644 --- a/cv_analysis/utils/connect_rects.py +++ b/cv_analysis/utils/connect_rects.py @@ -6,10 +6,14 @@ def is_near_enough(rect_pair, max_gap=14): x1, y1, w1, h1 = rect_pair[0] x2, y2, w2, h2 = rect_pair[1] - return any([abs(x1 - (x2 + w2)) <= max_gap, - abs(x2 - (x1 + w1)) <= max_gap, - abs(y2 - (y1 + h1)) <= max_gap, - abs(y1 - (y2 + h2)) <= max_gap]) + return any( + [ + abs(x1 - (x2 + w2)) <= max_gap, + abs(x2 - (x1 + w1)) <= max_gap, + abs(y2 - (y1 + h1)) <= max_gap, + abs(y1 - (y2 + h2)) <= max_gap, + ] + ) def is_overlapping(rect_pair): @@ -23,28 +27,36 @@ def is_overlapping(rect_pair): def is_on_same_line(rect_pair): x1, y1, w1, h1 = rect_pair[0] x2, y2, w2, h2 = rect_pair[1] - return any([any([abs(y1 - y2) <= 10, - abs(y1 + h1 - (y2 + h2)) <= 10]), - any([y2 <= y1 and y1 + h1 <= y2 + h2, - y1 <= y2 and y2 + h2 <= y1 + h1])]) + return any( + [ + any([abs(y1 - y2) <= 10, abs(y1 + h1 - (y2 + h2)) <= 10]), + any([y2 <= y1 and y1 + h1 <= y2 + h2, y1 <= y2 and y2 + h2 <= y1 + h1]), + ] + ) def has_correct_position1(rect_pair): x1, y1, w1, h1 = rect_pair[0] x2, y2, w2, h2 = rect_pair[1] - return any([any([abs(x1 - x2) <= 10, - abs(y1 - y2) <= 10, - abs(x1 + w1 - (x2 + w2)) <= 10, - abs(y1 + h1 - (y2 + h2)) <= 10]), - any([y2 <= y1 and y1 + h1 <= y2 + h2, - y1 <= y2 and y2 + h2 <= y1 + h1, - x2 <= x1 and x1 + w1 <= x2 + w2, - x1 <= x2 and x2 + w2 <= x1 + w1])]) + return any( + [ + any( + [abs(x1 - x2) <= 10, abs(y1 - y2) <= 10, abs(x1 + w1 - (x2 + w2)) <= 10, abs(y1 + h1 - (y2 + h2)) <= 10] + ), + any( + [ + y2 <= y1 and y1 + h1 <= y2 + h2, + y1 <= y2 and y2 + h2 <= y1 + h1, + x2 <= x1 and x1 + w1 <= x2 + w2, + x1 <= x2 and x2 + w2 <= x1 + w1, + ] + ), + ] + ) def is_related(rect_pair): - return (is_near_enough(rect_pair) and has_correct_position1(rect_pair)) or is_overlapping( - rect_pair) + return (is_near_enough(rect_pair) and has_correct_position1(rect_pair)) or is_overlapping(rect_pair) def fuse_rects(rect1, rect2): diff --git a/cv_analysis/utils/postprocessing.py b/cv_analysis/utils/postprocessing.py index ea4c4ee..bbb90b7 100644 --- a/cv_analysis/utils/postprocessing.py +++ b/cv_analysis/utils/postprocessing.py @@ -1,7 +1,7 @@ -from collections import namedtuple from functools import partial from itertools import starmap, compress from typing import Iterable + from cv_analysis.utils.structures import Rectangle