常用NMS(非极大值抑制)接口、NMS及变种实现介绍

156 篇文章 7 订阅

1、常用NMS 接口

(1)opencv.dnn.NMSBoxes

nms_indices = cv.dnn.NMSBoxes(box, conf, confThreshold, nmsThreshold)

API文档:https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga9d118d70a1659af729d01b10233213ee

void cv::dnn::NMSBoxes (const std::vector< Rect > &bboxes, const std::vector< float > &scores, const float score_threshold, const float nms_threshold, std::vector< int > &indices, const float eta=1.f, const int top_k=0)
 Performs non maximum suppression given boxes and corresponding scores. More...
 
void cv::dnn::NMSBoxes (const std::vector< Rect2d > &bboxes, const std::vector< float > &scores, const float score_threshold, const float nms_threshold, std::vector< int > &indices, const float eta=1.f, const int top_k=0)
 
void cv::dnn::NMSBoxes (const std::vector< RotatedRect > &bboxes, const std::vector< float > &scores, const float score_threshold, const float nms_threshold, std::vector< int > &indices, const float eta=1.f, const int top_k=0)

(2)nms (python)

支持 正框、旋转框和多边形

安装(需要cv2): pip install nms

使用:

indicies = nms.nms.nms_rboxes(rrects, scores)

By default, nms.nms.nms_boxes(), nms.nms.nms_polygons() and nms.nms.nms_rboxes() use the Malisiiewicz et. al. NMS Algorithm. If you would prefer to use the OpenCV2 Fast algorithm or Felzenszwalb et. al. algorithm you can do so with the optional parameter nms_algorithm. For example:

indicies = nms.nms.nms_rboxes(rrects, scores, nms_algorithm=malisiewicz.nms)

nms.nms.nms_boxes(), nms.nms.nms_polygons() and nms.nms.nms_rboxes() will also accept a list of key word arguments (**kwargs). The kwargs are passed to the NMS function to set values for the NMS threshold, confidence threshold, top_k and eta (eta is only applicable when using Fast).

For example, to set the NMS threshold to 0.5 (note that use of kwargs requires that nms_algorithm parameter be present):

indicies = nms.nms.nms_rboxes(rrects, scores, nms_algorithm=malisiewicz.nms, nms_threshold=0.5)

Please see the docs for nms.fast.nms(), nms.malisiewicz.nms() and nms.felzenszwalb.nms() for additional information on kwargs

These are the NMS functions you are looking for.

nms.nms.boxes(rects, scores, nms_algorithm=<function nms>, **kwargs)[source]

Non Maxima Suppression for rectangles.

This function is provided for completeness as it replicates the functionality of cv2.dnn.NMSBoxes. This may be slightly faster as NMSBoxes uses the FAST comparison algorithm and by default this used Malisiewicz et al.

Parameters:
  • rects (list) – a list of rectangles, each described by (x, y, w, h) (same as cv2.NMSBoxes)
  • scores (list) – a list of the scores associated with rects
  • nms_algorithm (function) – the NMS comparison function to use, kwargs will be passed to this function. Defaults to nms.malisiewicz.nms()
Returns:

a list of indicies of the best rects

nms.nms.polygons(polys, scores, nms_algorithm=<function nms>, **kwargs)[source]

Non Maxima Suppression for polygons

Parameters:
  • polys (list) – a list of polygons, each described by their xy verticies
  • scores (list) – a list of the scores associated with the polygons
  • nms_algorithm (function) – the NMS comparison function to use, kwargs will be passed to this function. Defaults to nms.malisiewicz.nms()
Returns:

an array of indicies of the best polys

nms.nms.rboxes(rrects, scores, nms_algorithm=<function nms>, **kwargs)[source]

Non Maxima Suppression for rotated rectangles

Parameters:
  • rrects (list) – a list of polygons, each described by ((cx, cy), (w,h), deg)
  • scores (list) – a list of the scores associated with the rects
  • nms_algorithm (function) – the NMS comparison function to use, kwargs will be passed to this function. Defaults to nms.malisiewicz.NMS()
Returns:

an array of indicies of the best rrects

 

2、非极大值抑制(NMS)及其变种实现

 

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值