def create_quadrilateral_2(connected=False): """Create 2 quadrilaterals per image. Args: connected: contain connected masks or not. Returns: quadrilateral_list: List of Quadrilateral instances. """ # first quadrilateral quadrilateral_1 = Quadrilateral([]) # second quadrilateral quadrilateral_2 = Quadrilateral([]) while True: quadrilateral_1.update() cur_iter_num = 0 max_iter_num = 5 flag = False while cur_iter_num < max_iter_num: quadrilateral_2.update() if connected: flag = quadrilateral_1.is_soft_overlap(quadrilateral_2) else: flag = quadrilateral_1.is_overlap(quadrilateral_2) cur_iter_num += 1 if flag: continue else: break if flag: continue else: break quadrilateral_list = [quadrilateral_1, quadrilateral_2] return quadrilateral_list
def create_quadrilateral_3(connected=False): """Create 3 quadrilaterals per image. Args: connected: contain connected masks or not. Returns: quadrilateral_list: List of Quadrilateral instances. """ quadrilateral_1 = Quadrilateral([]) quadrilateral_2 = Quadrilateral([]) quadrilateral_3 = Quadrilateral([]) while True: quadrilateral_1.update() cur_iter_num = 0 max_iter_num = 5 flag = False inner_flag = False while cur_iter_num < max_iter_num: quadrilateral_2.update() if connected: flag = quadrilateral_1.is_soft_overlap(quadrilateral_2) else: flag = quadrilateral_1.is_overlap(quadrilateral_2) cur_iter_num += 1 if flag: continue else: inner_cur_iter_num = 0 inner_max_iter_num = 8 while inner_cur_iter_num < inner_max_iter_num: quadrilateral_3.update() if connected: inner_flag = ( quadrilateral_3.is_soft_overlap(quadrilateral_1) or quadrilateral_3.is_soft_overlap(quadrilateral_2)) else: inner_flag = ( quadrilateral_3.is_overlap(quadrilateral_1) or quadrilateral_3.is_overlap(quadrilateral_2)) inner_cur_iter_num += 1 if inner_flag: continue else: break if inner_flag: continue else: break if inner_flag or flag: continue else: break quadrilateral_list = [quadrilateral_1, quadrilateral_2, quadrilateral_3] return quadrilateral_list