From 66cf55ea1f00105b310db41ff3e448e01d9dacdb Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Mon, 16 Mar 2020 18:05:07 +0100 Subject: [PATCH] dnn: expose only float variant of NMSBoxes for bindings the float variant was always shadowed by the int version as Rect2d is implicitly convertible to Rect. This swaps things which is fine, as the vector of boxes was always copied and the computation was done in double. --- modules/dnn/include/opencv2/dnn/dnn.hpp | 2 +- modules/dnn/misc/python/test/test_dnn.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/dnn/include/opencv2/dnn/dnn.hpp b/modules/dnn/include/opencv2/dnn/dnn.hpp index e67a465334..199e6d71c1 100644 --- a/modules/dnn/include/opencv2/dnn/dnn.hpp +++ b/modules/dnn/include/opencv2/dnn/dnn.hpp @@ -1038,7 +1038,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN * @param eta a coefficient in adaptive threshold formula: \f$nms\_threshold_{i+1}=eta\cdot nms\_threshold_i\f$. * @param top_k if `>0`, keep at most @p top_k picked indices. */ - CV_EXPORTS_W void NMSBoxes(const std::vector& bboxes, const std::vector& scores, + CV_EXPORTS void NMSBoxes(const std::vector& bboxes, const std::vector& scores, const float score_threshold, const float nms_threshold, CV_OUT std::vector& indices, const float eta = 1.f, const int top_k = 0); diff --git a/modules/dnn/misc/python/test/test_dnn.py b/modules/dnn/misc/python/test/test_dnn.py index f849cfaa10..932984f1c2 100644 --- a/modules/dnn/misc/python/test/test_dnn.py +++ b/modules/dnn/misc/python/test/test_dnn.py @@ -230,6 +230,12 @@ class dnn_test(NewOpenCVTests): self.assertTrue(ret) normAssert(self, refs[i], result, 'Index: %d' % i, 1e-10) + def test_nms(self): + confs = (1, 1) + rects = ((0, 0, 0.4, 0.4), (0, 0, 0.2, 0.4)) # 0.5 overlap + + self.assertTrue(all(cv.dnn.NMSBoxes(rects, confs, 0, 0.6).ravel() == (0, 1))) + def test_custom_layer(self): class CropLayer(object): def __init__(self, params, blobs):