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

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)及其变种实现

猜你喜欢

转载自blog.csdn.net/dou3516/article/details/109283311
今日推荐