def read_txt(name, use_bound=False, rect_label=None, is_gt=False):
    ret = []
    if (not osp.exists(name)):
        return ret
    with open(name) as fin:
        for line in fin:
            info = line.strip().split()
            if (len(info) == 1):
                continue
            if (is_gt and (len(info) != 9)):
                continue
            info = list(map(int, info))
            if (rect_label != None):
                rect_label.append(is_rect(info[1:]))
            pts = [(info[i], info[(i + 1)]) for i in range(1, len(info), 2)]
            (cx, cy) = get_cent(info[1:])
            pts.sort(key=(lambda a: math.atan2((a[1] - cy), (a[0] - cx))))
            frame = Polygon(pts)
            if use_bound:
                (x1, y1, x2, y2) = frame.bounds
                frame = Polygon([[x1, y1], [x2, y1], [x2, y2], [x1, y2]])
            if (not frame.is_valid):
                print(info[0])
                continue
            ret.append(frame)
    return ret
def read_txt(name, use_bound=False, rect_label=None, is_gt=False):
    ret = []
    if (not osp.exists(name)):
        return ret
    with open(name) as fin:
        for line in fin:
            info = line.strip().split()
            if (len(info) == 1):
                continue
            if (is_gt and (len(info) != 9)):
                continue
            info = list(map(int, info))
            if (rect_label != None):
                rect_label.append(is_rect(info[1:]))
            pts = [(info[i], info[(i + 1)]) for i in range(1, len(info), 2)]
            (cx, cy) = get_cent(info[1:])
            pts.sort(key=(lambda a: math.atan2((a[1] - cy), (a[0] - cx))))
            frame = Polygon(pts)
            if use_bound:
                (x1, y1, x2, y2) = frame.bounds
                frame = Polygon([[x1, y1], [x2, y1], [x2, y2], [x1, y2]])
            if (not frame.is_valid):
                print(info[0])
                continue
            ret.append(frame)
    return ret