Skip to content

Commit dc1ca90

Browse files
committed
add cod for issue report
1 parent 67e83d6 commit dc1ca90

File tree

2 files changed

+268
-0
lines changed

2 files changed

+268
-0
lines changed

issue-NMS-github.txt

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
##### System information (version)
2+
- OpenCV => 4.3.0 (opencv-python via pip)
3+
- Operating System / Platform => Windows 64 Bit
4+
5+
6+
##### Detailed description
7+
When setting `top_k>0` in `NMSBoxes`, I dont always get the expected number of boxes in output.
8+
With top_k=4 I get 2 boxes, top_k=5 I get 3 boxes.
9+
10+
With top_k<0 the output make sense, such that I could recover the top_k after the NMS but that's not really optimal.
11+
I'm wondering if it's related to this PR https://github.com/opencv/opencv/pull/16828, but it should be fixed in 4.3.0 🤔
12+
I also tried casting the boxes to float (hence the lambda function) but it does not change the output.
13+
Or am I missing something in the function definition ?
14+
15+
I also observe it with some java binding (via javacv), so I think it might not be specific to those particular bindings.
16+
17+
18+
##### Steps to reproduce (python)
19+
```python
20+
import cv2
21+
listBoxes = [
22+
(946, 784, 414, 400),
23+
(1525, 968, 414, 400),
24+
(1533, 960, 414, 400),
25+
(947, 784, 400, 414),
26+
(1173, 1354, 414, 400),
27+
(1459, 474, 400, 414),
28+
(1021, 888, 414, 400),
29+
(1450, 492, 400, 414),
30+
(1398, 889, 414, 400),
31+
(1005, 872, 400, 414),
32+
(686, 1367, 414, 400),
33+
(697, 1371, 414, 400),
34+
(694, 1371, 414, 400),
35+
(1128, 1377, 414, 400),
36+
(950, 787, 414, 400),
37+
(1438, 481, 414, 400),
38+
(1064, 1238, 414, 400),
39+
(1455, 485, 414, 400),
40+
(111, 787, 414, 400),
41+
(109, 782, 414, 400)]
42+
43+
listScores = [
44+
1.0,
45+
0.5919371843338013,
46+
0.5894666314125061,
47+
0.5689446926116943,
48+
0.5510676503181458,
49+
0.5381054282188416,
50+
0.5311822891235352,
51+
0.5298448204994202,
52+
0.5123124122619629,
53+
0.511840283870697,
54+
0.5080571174621582,
55+
0.5080069303512573,
56+
0.5079731941223145,
57+
0.5000045895576477,
58+
0.49151238799095154,
59+
0.4728872776031494,
60+
0.4612887501716614,
61+
0.4540329873561859,
62+
0.4483684003353119,
63+
0.44806933403015137]
64+
65+
"""
66+
# Cast boxes to float (optional)
67+
convertBox = lambda box : list(map(float, box))
68+
listBoxes = list(map(convertBox, listBoxes))
69+
print (listBoxes)
70+
"""
71+
72+
indexes1 = cv2.dnn.NMSBoxes(listBoxes, listScores, score_threshold=0.4, nms_threshold=0.3, top_k=4)
73+
print(indexes1)
74+
"""
75+
-> only the top_2 ?
76+
[[0]
77+
[1]]
78+
"""
79+
80+
print("-------")
81+
82+
indexes2 = cv2.dnn.NMSBoxes(listBoxes, listScores, score_threshold=0.4, nms_threshold=0.3)
83+
print(indexes2)
84+
"""
85+
->
86+
[[ 0]
87+
[ 1]
88+
[ 4]
89+
[ 5]
90+
[10]
91+
[18]]
92+
"""
93+
94+
95+
##### Issue submission checklist
96+
97+
- [X] I report the issue, it's not a question
98+
<!--
99+
OpenCV team works with answers.opencv.org, Stack Overflow and other communities
100+
to discuss problems. Tickets with question without real issue statement will be
101+
closed.
102+
-->
103+
- [X] I checked the problem with documentation, FAQ, open issues,
104+
answers.opencv.org, Stack Overflow, etc and have not found solution
105+
<!--
106+
Places to check:
107+
* OpenCV documentation: https://docs.opencv.org
108+
* FAQ page: https://github.com/opencv/opencv/wiki/FAQ
109+
* OpenCV forum: https://answers.opencv.org
110+
* OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
111+
* Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
112+
-->
113+
- [X] I updated to latest OpenCV version and the issue is still there
114+
<!--
115+
master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
116+
OpenCV team supports only latest release for each branch.
117+
The ticket is closed, if the problem is not reproduced with modern version.
118+
-->
119+
- [X] There is reproducer code and related data files: videos, images, onnx, etc
120+
<!--
121+
The best reproducer -- test case for OpenCV that we can add to the library.
122+
Recommendations for media files and binary files:
123+
* Try to reproduce the issue with images and videos in opencv_extra repository
124+
to reduce attachment size
125+
* Use PNG for images, if you report some CV related bug, but not image reader
126+
issue
127+
* Attach the image as archite to the ticket, if you report some reader issue.
128+
Image hosting services compress images and it breaks the repro code.
129+
* Provide ONNX file for some public model or ONNX file with with random weights,
130+
if you report ONNX parsing or handling issue. Architecture details diagram
131+
from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
132+
-->

tutorials/IssueNMS.ipynb

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 15,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"[[0]\n",
13+
" [1]\n",
14+
" [4]]\n",
15+
"-------\n",
16+
"[[ 0]\n",
17+
" [ 1]\n",
18+
" [ 4]\n",
19+
" [ 5]\n",
20+
" [10]\n",
21+
" [18]]\n"
22+
]
23+
}
24+
],
25+
"source": [
26+
"import cv2\n",
27+
"listBoxes = [\n",
28+
" (946, 784, 414, 400),\n",
29+
" (1525, 968, 414, 400),\n",
30+
" (1533, 960, 414, 400),\n",
31+
" (947, 784, 400, 414),\n",
32+
" (1173, 1354, 414, 400),\n",
33+
" (1459, 474, 400, 414),\n",
34+
" (1021, 888, 414, 400),\n",
35+
" (1450, 492, 400, 414),\n",
36+
" (1398, 889, 414, 400),\n",
37+
" (1005, 872, 400, 414),\n",
38+
" (686, 1367, 414, 400),\n",
39+
" (697, 1371, 414, 400),\n",
40+
" (694, 1371, 414, 400),\n",
41+
" (1128, 1377, 414, 400),\n",
42+
" (950, 787, 414, 400),\n",
43+
" (1438, 481, 414, 400),\n",
44+
" (1064, 1238, 414, 400),\n",
45+
" (1455, 485, 414, 400),\n",
46+
" (111, 787, 414, 400),\n",
47+
" (109, 782, 414, 400)]\n",
48+
"\n",
49+
"listScores = [\n",
50+
" 1.0,\n",
51+
" 0.5919371843338013,\n",
52+
" 0.5894666314125061,\n",
53+
" 0.5689446926116943,\n",
54+
" 0.5510676503181458,\n",
55+
" 0.5381054282188416,\n",
56+
" 0.5311822891235352,\n",
57+
" 0.5298448204994202,\n",
58+
" 0.5123124122619629,\n",
59+
" 0.511840283870697,\n",
60+
" 0.5080571174621582,\n",
61+
" 0.5080069303512573,\n",
62+
" 0.5079731941223145,\n",
63+
" 0.5000045895576477,\n",
64+
" 0.49151238799095154,\n",
65+
" 0.4728872776031494,\n",
66+
" 0.4612887501716614,\n",
67+
" 0.4540329873561859,\n",
68+
" 0.4483684003353119,\n",
69+
" 0.44806933403015137]\n",
70+
"\n",
71+
"'''\n",
72+
"# Cast boxes to float\n",
73+
"convertBox = lambda box : list(map(float, box)) \n",
74+
"listBoxes = list(map(convertBox, listBoxes))\n",
75+
"print (listBoxes)\n",
76+
"'''\n",
77+
"\n",
78+
"indexes1 = cv2.dnn.NMSBoxes(listBoxes, listScores, score_threshold=0.4, nms_threshold=0.3, top_k=5)\n",
79+
"print(indexes1)\n",
80+
"\n",
81+
"print(\"-------\")\n",
82+
"\n",
83+
"indexes2 = cv2.dnn.NMSBoxes(listBoxes, listScores, score_threshold=0.4, nms_threshold=0.3)\n",
84+
"print(indexes2)"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": 9,
90+
"metadata": {},
91+
"outputs": [
92+
{
93+
"data": {
94+
"text/plain": [
95+
"'4.3.0'"
96+
]
97+
},
98+
"execution_count": 9,
99+
"metadata": {},
100+
"output_type": "execute_result"
101+
}
102+
],
103+
"source": [
104+
"cv2.__version__"
105+
]
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": null,
110+
"metadata": {},
111+
"outputs": [],
112+
"source": []
113+
}
114+
],
115+
"metadata": {
116+
"kernelspec": {
117+
"display_name": "Python 3",
118+
"language": "python",
119+
"name": "python3"
120+
},
121+
"language_info": {
122+
"codemirror_mode": {
123+
"name": "ipython",
124+
"version": 3
125+
},
126+
"file_extension": ".py",
127+
"mimetype": "text/x-python",
128+
"name": "python",
129+
"nbconvert_exporter": "python",
130+
"pygments_lexer": "ipython3",
131+
"version": "3.7.4"
132+
}
133+
},
134+
"nbformat": 4,
135+
"nbformat_minor": 4
136+
}

0 commit comments

Comments
 (0)