Beispiel #1
0
class Block:
    def __init__(self, bound, id, layer, parent_id):
        col_min, row_min, col_max, row_max = bound
        self.bbox = Bbox(col_min, row_min, col_max, row_max)

        self.id = id
        self.layer = layer
        self.parent_id = parent_id

    def put_bbox(self):
        return self.bbox.put_bbox()

    def relation(self, bound):
        '''
        relation: -1 : a in b
                  0  : a, b are not intersected
                  1  : b in a
                  2  : a, b are identical or intersected
        '''
        col_min, row_min, col_max, row_max = bound
        bbox = Bbox(col_min, row_min, col_max, row_max)
        return self.bbox.bbox_relation_nms(bbox)

    def resize_bbox(self, det_height, tgt_height, bias):
        col_min, row_min, col_max, row_max = self.bbox.put_bbox()
        scale = tgt_height / det_height
        self.bbox = Bbox(
            int(col_min * scale) + bias,
            int(row_min * scale) + bias,
            int(col_max * scale) - bias,
            int(row_max * scale) - bias)
class Block:
    def __init__(self, bound, id, layer, parent_id):
        col_min, row_min, col_max, row_max = bound
        self.bbox = Bbox(col_min, row_min, col_max, row_max)

        self.id = id
        self.layer = layer
        self.parent_id = parent_id

    def put_bbox(self):
        return self.bbox.put_bbox()

    def relation(self, bound):
        '''
        relation: -1 : a in b
                  0  : a, b are not intersected
                  1  : b in a
                  2  : a, b are intersected
                  3  : a, b are same
        '''
        col_min, row_min, col_max, row_max = bound
        bbox = Bbox(col_min, row_min, col_max, row_max)
        return self.bbox.bbox_relation_nms(bbox)

    def resize_bbox(self, det_height, tgt_height, bias):
        col_min, row_min, col_max, row_max = self.bbox.put_bbox()
        scale = tgt_height / det_height
        self.bbox = Bbox(
            int(col_min * scale) + bias,
            int(row_min * scale) + bias,
            int(col_max * scale) - bias,
            int(row_max * scale) - bias)

    def is_bottom_or_top_bar(self, img_height=800):
        column_min, row_min, column_max, row_max = self.bbox.put_bbox()
        if row_max < img_height * 0.06 or row_min > img_height * 0.9:
            return True
        return False