nms

nms函数是保留选框中得分最高的那一个
Python代码如下

def nms(boxes, threshold, method):
    """
    boxes: [x1, y1, x2, y2, score]
    """
    # if input is empty return directly
    if boxes.size == 0:
        return np.empty(shape=[0])

    x1 = boxes[:, 0]   # up-left point
    y1 = boxes[:, 1]   # of the bounding box
    x2 = boxes[:, 2]   # bottom-right point
    y2 = boxes[:, 3]   # of the bounding box
    s = boxes[:, 4]    # score of the bounding box

    # area of the bounding boxes
    area = (x2 - x1 + 1) * (y2 - y1 + 1)
    # sort by score
    I = np.argsort(s)

    # initial
    pick = np.zeros_like(s, dtype=np.uint16)
    counter = 0

    while I.size > 0:
        i = I[-1]  # hightest score
        pick[counter] = i
        counter += 1
        idx = I[0:-1]

        # area of intersection
        xx1 = np.maximum(x1[i], x1[idx])
        yy1 = np.maximum(y1[i], y1[idx])
        xx2 = np.minimum(x2[i], x2[idx])
        yy2 = np.minimum(y2[i], y2[idx])
        w = np.maximum(0.0, xx2 - xx1 + 1)
        h = np.maximum(0.0, yy2 - yy1 + 1)
        inter = w * h

        if method is 'Min':
            # inter_area/minium_area
            o = inter / np.minimum(area[i], area[idx])
        else:
            # inter_area/union_area
            o = inter / (area[i] + area[idx] - inter)
        I = I[np.where(o <= threshold)]
    pick = pick[0:counter]
    return pick

参考 https://blog.csdn.net/shuzfan/article/details/52711706

转载于:https://www.cnblogs.com/pluviophile/p/nms.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值