Example #1
0
def calc_axis_iou(a,b,axis=0):
    if isinstance(b, list):
        if axis == 0:
            ious = [calc_iou([a['cx'] - a['w'] / 2, a['cx'] + a['w'] / 2], [x['cx'] - x['w'] / 2, x['cx'] + x['w'] / 2]) for x in b]
        else:
            ious = [calc_iou([a['cy'] - a['h'] / 2, a['cy'] + a['h'] / 2], [x['cy'] - x['h'] / 2, x['cy'] + x['h'] / 2]) for x in b]
        iou = max(ious)
    elif isinstance(a, list):
        if axis == 0:
            ious = [calc_iou([x['cx'] - x['w'] / 2, x['cx'] + x['w'] / 2], [b['cx'] - b['w'] / 2, b['cx'] + b['w'] / 2]) for x in a]
        else:
            ious = [calc_iou([x['cy'] - x['h'] / 2, x['cy'] + x['h'] / 2], [b['cy'] - b['h'] / 2, b['cy'] + b['h'] / 2]) for x in a]
        iou = max(ious)
    else:
        if axis == 0:
            iou = calc_iou([a['cx'] - a['w'] / 2, a['cx'] + a['w'] / 2], [b['cx'] - b['w'] / 2, b['cx'] + b['w'] / 2])
        else:
            iou = calc_iou([a['cy'] - a['h'] / 2, a['cy'] + a['h'] / 2], [b['cy'] - b['h'] / 2, b['cy'] + b['h'] / 2])
    return iou
def calc_axis_iou(a, b, axis=0):
    if isinstance(b, list):  # b 是list类型时
        if axis == 0:  # x 方向的交叉率
            #                     左                        右                     左                 右
            ious = [
                calc_iou([a['cx'] - a['w'] / 2, a['cx'] + a['w'] / 2],
                         [x['cx'] - x['w'] / 2, x['cx'] + x['w'] / 2])
                for x in b
            ]  #
        else:  # y 方向的交叉类
            ious = [
                calc_iou([a['cy'] - a['h'] / 2, a['cy'] + a['h'] / 2],
                         [x['cy'] - x['h'] / 2, x['cy'] + x['h'] / 2])
                for x in b
            ]
        iou = max(ious)
    elif isinstance(a, list):
        if axis == 0:
            ious = [
                calc_iou([x['cx'] - x['w'] / 2, x['cx'] + x['w'] / 2],
                         [b['cx'] - b['w'] / 2, b['cx'] + b['w'] / 2])
                for x in a
            ]
        else:
            ious = [
                calc_iou([x['cy'] - x['h'] / 2, x['cy'] + x['h'] / 2],
                         [b['cy'] - b['h'] / 2, b['cy'] + b['h'] / 2])
                for x in a
            ]
        iou = max(ious)
    else:  # a b 都不是 list类型
        if axis == 0:  #
            iou = calc_iou([a['cx'] - a['w'] / 2, a['cx'] + a['w'] / 2],
                           [b['cx'] - b['w'] / 2, b['cx'] + b['w'] / 2])
        else:
            iou = calc_iou([a['cy'] - a['h'] / 2, a['cy'] + a['h'] / 2],
                           [b['cy'] - b['h'] / 2, b['cy'] + b['h'] / 2])
    return iou