zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    php+apache+mysql环境搭建
    怎么理解依赖注入
    maven修改远程和本地仓库地址
    idea创建的java web项目打包发布到tomcat
    MYSQL 导入导出数据库文件
    MySQL约束
    mysql字符集校对
    prime
    POJ-2564 01背包问题
    POJ-1564 dfs
  • 原文地址:https://www.cnblogs.com/pluviophile/p/nms.html
Copyright © 2011-2022 走看看