非极大抑制(Non-maximum suppression)python代码实现
原创Butertfly 发布于2018-11-20 18:48:57 阅读数 293 收藏
展开
定位一个物体,最后算法就找出了一堆的方框,我们需要判别哪些矩形框是没用的。非极大值抑制:先假设有6个矩形框,根据分类器类别分类概率做排序,从大到小分别属于物体的概率分别为A、B、C、D、E、F。

(1)从最大概率矩形框F开始,分别判断B~F与A的重叠度IOU是否大于某个设定的阈值;

(2)假设B、D与F的重叠度超过阈值,那么就扔掉B、D;并标记第一个矩形框A,是我们保留下来的。

(3)从剩下的矩形框C、E、F中,选择概率最大的C,然后判断C与E、F的重叠度,重叠度大于一定的阈值,那么就扔掉;并标记C是我们保留下来的第二个矩形框。

就这样一直重复,找到所有被保留下来的矩形框。

# import the necessary packages
import numpy as np

# Felzenszwalb et al.
def non_max_suppression_slow(boxes, thresh):
# if there are no boxes, return an empty list
if len(boxes) == 0:
return []

# initialize the list of picked indexes
pick = []

# grab the coordinates of the bounding boxes
x1 = boxes[:, 0]
y1 = boxes[:, 1]
x2 = boxes[:, 2]
y2 = boxes[:, 3]
scores = boxes[:, 4]

# compute the area of the bounding boxes and sort the bounding
# boxes by the bottom-right y-coordinate of the bounding box
area = (x2 - x1 + 1) * (y2 - y1 + 1)

# 获取置信度,并降序排列,获取其在boxes中对应的索引
idxs = scores.argsort()[::-1]

while idxs.size > 0:
i = idxs[0]
pick.append(i)

# find the largest (x, y) coordinates for the start of
# the bounding box and the smallest (x, y) coordinates
# for the end of the bounding box
xx1 = np.maximum(x1[i], x1[idxs[1:]])
yy1 = np.maximum(y1[i], y1[idxs[1:]])
xx2 = np.minimum(x2[i], x2[idxs[1:]])
yy2 = np.minimum(y2[i], y2[idxs[1:]])

# compute the width and height of the bounding box
w = np.maximum(0.0, xx2 - xx1 + 1)
h = np.maximum(0.0, yy2 - yy1 + 1)

# compute the intersection over union(IOU) between the computed
# bounding box and the bounding box in the area list
inter = w * h
union = area[i] + area[idxs[1:]] - inter
IOU = inter / union

indexes = np.where(IOU < thresh)

idxs = idxs[indexes + 1]

# return only the bounding boxes that were picked
return boxes[pick]

References:

1.https://www.pyimagesearch.com/2014/11/17/non-maximum-suppression-object-detection-python/

2.https://blog.csdn.net/l_ml_m_lm_m/article/details/79881437

3.https://blog.csdn.net/u011534057/article/details/51235718

4.http://www.cnblogs.com/makefile/p/nms.html

————————————————
版权声明:本文为CSDN博主「Butertfly」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Butertfly/article/details/84307659

非极大抑制睔PYTHON实现的更多相关文章

  1. 非极大值抑制(non-maximum suppression)的理解与实现

    非极大抑制(Non-Maximum Suppression) Non-Maximum Suppression for Object Detection in Python RCNN 和微软提出的 SP ...

  2. 第二十七节,IOU和非极大值抑制

    你如何判断对象检测算法运作良好呢?在这一节中,你将了解到并交比函数,可以用来评价对象检测算法. 一 并交比(Intersection over union ) 在对象检测任务中,你希望能够同时定位对象 ...

  3. 【56】目标检测之NMS非极大值抑制

    非极大值抑制(Non-max suppression) 到目前为止你们学到的对象检测中的一个问题是,你的算法可能对同一个对象做出多次检测,所以算法不是对某个对象检测出一次,而是检测出多次.非极大值抑制 ...

  4. 『Python』图像金字塔、滑动窗口和非极大值抑制实现

    图像金字塔 1.在从cv2.resize中,传入参数时先列后行的 2.使用了python中的生成器,调用时使用for i in pyramid即可 3.scaleFactor是缩放因子,需要保证缩放后 ...

  5. 非极大值抑制算法(Python实现)

    date: 2017-07-21 16:48:02 非极大值抑制算法(Non-maximum suppression, NMS) 算法原理 非极大值抑制算法的本质是搜索局部极大值,抑制非极大值元素. ...

  6. 非极大值抑制(NMS)的几种实现

    因为之前对比了RoI pooling的几种实现,发现python.pytorch的自带工具函数速度确实很慢,所以这里再对Faster-RCNN中另一个速度瓶颈NMS做一个简单对比试验. 这里做了四组对 ...

  7. 非极大值抑制(Non-Maximum Suppression,NMS)

    概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的元素,可以理解为局部最大搜索.这个局部代表的是一个邻域,邻域有两个参数可变,一是邻域的维数,二 ...

  8. 非极大值抑制(NMS)

    转自:https://www.cnblogs.com/makefile/p/nms.html 概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的 ...

  9. 非极大值抑制Non-Maximum Suppression(NMS)

    非极大值抑制(Non-Maximum Suppression,NMS)   概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的元素,可以理解为局 ...

随机推荐

  1. mysqld: Can't change dir to 'D:\TONG\mysql-5.7.19-winx64\data\' (Errcode: 2 - No such file or directory)

    mysqld: Can't change dir to 'D:\TONG\mysql-5.7.19-winx64\data\' (Errcode: 2 - No such file or direct ...

  2. Mybatis遇到的报错

    MyBatis遇到的报错: 1.Caused by: org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 17; 元素类型为 &q ...

  3. unity 热更方案对比

    现在一般使用的方案有:tulua&ulua.xlua.ILRuntime 对比: tulua&ulua 方案成熟,稳定第三方库支持 xlua 之前是为了热更修复线上bug的,腾讯发起的 ...

  4. JS实现对对象的深拷贝

    手动遍历对象拷贝 /** * 深拷贝 * @param {*} obj 拷贝对象(object or array) * @param {*} cache 缓存数组 */ function deepCo ...

  5. selenium webdriver 执行Javascript

    @Test public void testElementByID() { //通过JS获取页面元素 driver.get(url); driver.manage().window().maximiz ...

  6. python包管理历史

    1.标准库工具distutils,2000年发布,是包安装和发布工具 setup.python 程序,利用distutils 开发 示例: python setup.py install 安装一个包 ...

  7. Python函数-2 匿名函数

    匿名函数 当我们在创建函数时,有些时候,不需要显式地定义函数,直接传入匿名函数更方便.这省去了我们挖空心思为函数命名的麻烦,也能少写不少代码,很多编程语言都提供这一特性. Python语言使用lamb ...

  8. 怎么HTML表格中的所有字体居中?

    一开始,我在table标签里加入align="center"  发现没什么用.... 后来在css里加入,就可以了 成果如图:

  9. 布线问题&魔法花园_最短路径

    布线问题 问题描述:印刷电路板将布线区域划分成n×m个方格阵列,精确的电路布线问题要求确定连接方格a到方格b的最短布线方案:布线时,电路只能沿着直线或直角(方格)布线:已经布线的方格被锁定,即不允许其 ...

  10. WCF服务调用方式

    WCF服务调用通过两种常用的方式:一种是借助代码生成工具SvcUtil.exe或者添加服务引用的方式,一种是通过ChannelFactory直接创建服务代理对象进行服务调用.