<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 4.2</li>
<li>Operating System / Platform =&gt; Ubuntu 18.04</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">Incorrect output from cv2.dnn.NMSBoxes. I think it can because of incorrect rounding in python bindings.</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">Incorrect</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import cv2                                                                                                     

rect1 = [0.0, 0.0, 0.2, 0.2]                                                                                   
rect2 = [0.2, 0.2, 0.4, 0.4]  
cv2.dnn.NMSBoxes([rect1, rect2], [1.0, 1.0], 0.5, 0.5)

# output: array([[0]], dtype=int32)"><pre class="notranslate"><code class="notranslate">import cv2                                                                                                     

rect1 = [0.0, 0.0, 0.2, 0.2]                                                                                   
rect2 = [0.2, 0.2, 0.4, 0.4]  
cv2.dnn.NMSBoxes([rect1, rect2], [1.0, 1.0], 0.5, 0.5)

# output: array([[0]], dtype=int32)
</code></pre></div>
<p dir="auto">Let's multiply each value of rectangles by 10. Now, output is correct</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import cv2                                                                                                     

rect1 = [0.0, 0.0, 2.0, 2.0]                                                                                   
rect2 = [2.0, 2.0, 4.0, 4.0]  
cv2.dnn.NMSBoxes([rect1, rect2], [1.0, 1.0], 0.5, 0.5)

# output: array([[0], [1]], dtype=int32)"><pre class="notranslate"><code class="notranslate">import cv2                                                                                                     

rect1 = [0.0, 0.0, 2.0, 2.0]                                                                                   
rect2 = [2.0, 2.0, 4.0, 4.0]  
cv2.dnn.NMSBoxes([rect1, rect2], [1.0, 1.0], 0.5, 0.5)

# output: array([[0], [1]], dtype=int32)
</code></pre></div>
<p dir="auto">Also, code in c++ works correct:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#include &lt;iostream&gt;
#include &lt;vector&gt;

#include &lt;opencv2/imgproc.hpp&gt;
#include &lt;opencv2/highgui.hpp&gt;
#include &lt;opencv2/dnn.hpp&gt;
using namespace cv;
using namespace cv::dnn;
using namespace std;

int main() {
    int a;
    vector&lt;float&gt; confidences = {1.0, 1.0};
    float confThreshold = 0.5;
    float nmsThreshold = 0.5;
    std::vector&lt;int&gt; indices;
    vector&lt;Rect2d&gt; boxes = {{0, 0, 0.2, 0.2}, {0.2, 0.2, 0.3, 0.3}};
    NMSBoxes(boxes, confidences, confThreshold, nmsThreshold, indices);
    for (auto i: indices)
        cout&lt;&lt;i&lt;&lt;endl;
    return 0;
}
//Output:
//0
//1"><pre class="notranslate"><code class="notranslate">#include &lt;iostream&gt;
#include &lt;vector&gt;

#include &lt;opencv2/imgproc.hpp&gt;
#include &lt;opencv2/highgui.hpp&gt;
#include &lt;opencv2/dnn.hpp&gt;
using namespace cv;
using namespace cv::dnn;
using namespace std;

int main() {
    int a;
    vector&lt;float&gt; confidences = {1.0, 1.0};
    float confThreshold = 0.5;
    float nmsThreshold = 0.5;
    std::vector&lt;int&gt; indices;
    vector&lt;Rect2d&gt; boxes = {{0, 0, 0.2, 0.2}, {0.2, 0.2, 0.3, 0.3}};
    NMSBoxes(boxes, confidences, confThreshold, nmsThreshold, indices);
    for (auto i: indices)
        cout&lt;&lt;i&lt;&lt;endl;
    return 0;
}
//Output:
//0
//1
</code></pre></div>
<h5 dir="auto">Issue submission checklist</h5>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I report the issue, it's not a question

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I checked the problem with documentation, FAQ, open issues,<br>
answers.opencv.org, Stack Overflow, etc and have not found solution

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I updated to latest OpenCV version and the issue is still there

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> There is reproducer code and related data files: videos, images, onnx, etc

</li>
</ul>
<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 4.0.1</li>
<li>Operating System / Platform =&gt; macOS 10.14.6</li>
<li>Compiler =&gt; Apple Clang 11.0.0 (clang-1100.0.33.16)</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto"><code class="notranslate">cv::dnn::NMSBoxes</code> can accept <code class="notranslate">std::vector&lt;Rect2d&gt;</code> but only the one for <code class="notranslate">std::vector&lt;Rect&gt;</code> can be called from python.</p>
<h5 dir="auto">Steps to reproduce</h5>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="boxes_zero = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
conf = [.6, .5, .2]
print(cv2.dnn.NMSBoxes(boxes_zero, conf, 0, 0))  # returns [[0]]

boxes0 = [[1, 2, 3, 4], [2, 1, 3, 4], [4, 3, 2, 1]]
print(cv2.dnn.NMSBoxes(boxes0, conf, 0, 0))  # returns [[0], [2]]

boxes1 = [[float(elem) for elem in box] for box in boxes0]
print(cv2.dnn.NMSBoxes(boxes1, conf, 0, 0))  # returns [[0], [2]]

boxes2 = [[elem * 0.1 for elem in box] for box in boxes1]
print(cv2.dnn.NMSBoxes(boxes2, conf, 0, 0))  # returns [[0]]

boxes3 = np.array(boxes0)[np.newaxis, :]
print(cv2.dnn.NMSBoxes(boxes3, conf, 0, 0))  # returns [[0], [2]]

boxes4 = boxes3.astype(np.float64)
print(cv2.dnn.NMSBoxes(boxes4, conf, 0, 0))  # returns [[0], [2]]

boxes5 = boxes4 * 0.1
print(cv2.dnn.NMSBoxes(boxes5, conf, 0, 0))  # returns [[0]]

boxes6 = boxes5.astype(np.float32)
print(cv2.dnn.NMSBoxes(boxes6, conf, 0, 0))  # returns [[0]]

boxes7 = boxes6 * 10
print(cv2.dnn.NMSBoxes(boxes7, conf, 0, 0))  # returns [[0], [2]]"><pre class="notranslate"><span class="pl-s1">boxes_zero</span> <span class="pl-c1">=</span> [[<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>], [<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>], [<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>]]
<span class="pl-s1">conf</span> <span class="pl-c1">=</span> [<span class="pl-c1">.6</span>, <span class="pl-c1">.5</span>, <span class="pl-c1">.2</span>]
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">NMSBoxes</span>(<span class="pl-s1">boxes_zero</span>, <span class="pl-s1">conf</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>))  <span class="pl-c"># returns [[0]]</span>

<span class="pl-s1">boxes0</span> <span class="pl-c1">=</span> [[<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>], [<span class="pl-c1">2</span>, <span class="pl-c1">1</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>], [<span class="pl-c1">4</span>, <span class="pl-c1">3</span>, <span class="pl-c1">2</span>, <span class="pl-c1">1</span>]]
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">NMSBoxes</span>(<span class="pl-s1">boxes0</span>, <span class="pl-s1">conf</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>))  <span class="pl-c"># returns [[0], [2]]</span>

<span class="pl-s1">boxes1</span> <span class="pl-c1">=</span> [[<span class="pl-en">float</span>(<span class="pl-s1">elem</span>) <span class="pl-k">for</span> <span class="pl-s1">elem</span> <span class="pl-c1">in</span> <span class="pl-s1">box</span>] <span class="pl-k">for</span> <span class="pl-s1">box</span> <span class="pl-c1">in</span> <span class="pl-s1">boxes0</span>]
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">NMSBoxes</span>(<span class="pl-s1">boxes1</span>, <span class="pl-s1">conf</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>))  <span class="pl-c"># returns [[0], [2]]</span>

<span class="pl-s1">boxes2</span> <span class="pl-c1">=</span> [[<span class="pl-s1">elem</span> <span class="pl-c1">*</span> <span class="pl-c1">0.1</span> <span class="pl-k">for</span> <span class="pl-s1">elem</span> <span class="pl-c1">in</span> <span class="pl-s1">box</span>] <span class="pl-k">for</span> <span class="pl-s1">box</span> <span class="pl-c1">in</span> <span class="pl-s1">boxes1</span>]
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">NMSBoxes</span>(<span class="pl-s1">boxes2</span>, <span class="pl-s1">conf</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>))  <span class="pl-c"># returns [[0]]</span>

<span class="pl-s1">boxes3</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-s1">boxes0</span>)[<span class="pl-s1">np</span>.<span class="pl-s1">newaxis</span>, :]
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">NMSBoxes</span>(<span class="pl-s1">boxes3</span>, <span class="pl-s1">conf</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>))  <span class="pl-c"># returns [[0], [2]]</span>

<span class="pl-s1">boxes4</span> <span class="pl-c1">=</span> <span class="pl-s1">boxes3</span>.<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">float64</span>)
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">NMSBoxes</span>(<span class="pl-s1">boxes4</span>, <span class="pl-s1">conf</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>))  <span class="pl-c"># returns [[0], [2]]</span>

<span class="pl-s1">boxes5</span> <span class="pl-c1">=</span> <span class="pl-s1">boxes4</span> <span class="pl-c1">*</span> <span class="pl-c1">0.1</span>
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">NMSBoxes</span>(<span class="pl-s1">boxes5</span>, <span class="pl-s1">conf</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>))  <span class="pl-c"># returns [[0]]</span>

<span class="pl-s1">boxes6</span> <span class="pl-c1">=</span> <span class="pl-s1">boxes5</span>.<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>)
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">NMSBoxes</span>(<span class="pl-s1">boxes6</span>, <span class="pl-s1">conf</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>))  <span class="pl-c"># returns [[0]]</span>

<span class="pl-s1">boxes7</span> <span class="pl-c1">=</span> <span class="pl-s1">boxes6</span> <span class="pl-c1">*</span> <span class="pl-c1">10</span>
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-s1">dnn</span>.<span class="pl-v">NMSBoxes</span>(<span class="pl-s1">boxes7</span>, <span class="pl-s1">conf</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>))  <span class="pl-c"># returns [[0], [2]]</span></pre></div>