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

网友投稿 1744 2022-11-23

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

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

1. What

非极大值抑制,简称为NMS算法,英文为Non-Maximum Suppression。其思想是搜素局部最大值,抑制极大值。NMS算法在不同应用中的具体实现不太一样,但思想是一样的。非极大值抑制,常用于边缘检测、目标检测等计算机视觉任务。

2. Why

2. How

其技术流程如下:

根据置信度得分进行排序;选择置信度最高的比边界框添加到最终输出列表中,将其从边界框列表中删除;计算所有边界框的面积;计算置信度最高的边界框与其它候选框的IoU;删除IoU大于阈值的边界框;重复上述过程,直至边界框列表为空。

python代码

import cv2import numpy as np""" Non-max Suppression Algorithm @param list Object candidate bounding boxes @param list Confidence score of bounding boxes @param float IoU threshold @return Rest boxes after nms operation"""def nms(bounding_boxes, confidence_score, threshold): # If no bounding boxes, return empty list if len(bounding_boxes) == 0: return [], [] # Bounding boxes boxes = np.array(bounding_boxes) # coordinates of bounding boxes start_x = boxes[:, 0] start_y = boxes[:, 1] end_x = boxes[:, 2] end_y = boxes[:, 3] # Confidence scores of bounding boxes score = np.array(confidence_score) # Picked bounding boxes picked_boxes = [] picked_score = [] # Compute areas of bounding boxes areas = (end_x - start_x + 1) * (end_y - start_y + 1) # Sort by confidence score of bounding boxes order = np.argsort(score) # Iterate bounding boxes while order.size > 0: # The index of largest confidence score index = order[-1] # Pick the bounding box with largest confidence score picked_boxes.append(bounding_boxes[index]) picked_score.append(confidence_score[index]) # Compute ordinates of intersection-over-union(IOU) x1 = np.maximum(start_x[index], start_x[order[:-1]]) x2 = np.minimum(end_x[index], end_x[order[:-1]]) y1 = np.maximum(start_y[index], start_y[order[:-1]]) y2 = np.minimum(end_y[index], end_y[order[:-1]]) # Compute areas of intersection-over-union w = np.maximum(0.0, x2 - x1 + 1) h = np.maximum(0.0, y2 - y1 + 1) intersection = w * h # Compute the ratio between intersection and union ratio = intersection / (areas[index] + areas[order[:-1]] - intersection) left = np.where(ratio < threshold) order = order[left] return picked_boxes, picked_score

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:C语言每日练习之求两个矩阵的乘积详解
下一篇:Leetcode题目71. 简化路径
相关文章

 发表评论

暂时没有评论,来抢沙发吧~