Skip to content

Commit 6128948

Browse files
committed
format doc
1 parent 1b9c3c6 commit 6128948

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

MTM/NMS.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
Non-Maxima Supression (NMS) for match template
3+
Non-Maxima Supression (NMS) for match template.
4+
45
From a pool of bounding box each predicting possible object locations with a given score,
56
the NMS removes the bounding boxes overlapping with a bounding box of higher score above the maxOverlap threshold
67
78
This effectively removes redundant detections of the same object and still allow the detection of close objects (ie small possible overlap)
89
The "possible" allowed overlap is set by the variable maxOverlap (between 0 and 1) which is the ratio Intersection over Union (IoU) area for a given pair of overlaping BBoxes
910
11+
Since version 1.6.0 the NMS is assured by opencv cv2.dnn.NMSBoxes function
1012
1113
@author: Laurent Thomas
1214
"""
@@ -15,33 +17,37 @@
1517

1618

1719
def NMS(tableHit, scoreThreshold=0.5, sortAscending=False, N_object=float("inf"), maxOverlap=0.5):
18-
'''
19-
Perform Non-Maxima supression : it compares the hits after maxima/minima detection, and removes the ones that are too close (too large overlap)
20-
This function works both with an optionnal threshold on the score, and number of detected bbox
21-
22-
if a scoreThreshold is specified, we first discard any hit below/above the threshold (depending on sortDescending)
23-
if sortDescending = True, the hit with score below the treshold are discarded (ie when high score means better prediction ex : Correlation)
24-
if sortDescending = False, the hit with score above the threshold are discared (ie when low score means better prediction ex : Distance measure)
25-
26-
Then the hit are ordered so that we have the best hits first.
27-
Then we iterate over the list of hits, taking one hit at a time and checking for overlap with the previous validated hit (the Final Hit list is directly iniitialised with the first best hit as there is no better hit with which to compare overlap)
20+
"""
21+
Perform Non-Maxima Supression (NMS).
2822
29-
This iteration is terminate once we have collected N best hit, or if there are no more hit left to test for overlap
23+
it compares the hits after maxima/minima detection, and removes detections overlapping above the maxOverlap
24+
Also removes detections that do not satisfy a minimum score
3025
31-
INPUT
32-
- tableHit : (Panda DataFrame) Each row is a hit, with columns "TemplateName"(String),"BBox"(x,y,width,height),"Score"(float)
26+
INPUT
27+
- tableHit : Pandas DataFrame
28+
List of potential detections as returned by MTM.findMatches.
29+
Each row is a hit, with columns "TemplateName"(String),"BBox"(x,y,width,height),"Score"(float).
3330
34-
- scoreThreshold : Float (or None), used to remove hit with too low prediction score.
35-
If sortAscending=False (ie we use a correlation measure so we want to keep large scores) the scores above that threshold are kept
36-
If True (we use a difference measure ie we want to keep low score), the scores below that threshold are kept
37-
38-
- N_object : maximum number of hit to return. Default=-1, ie return all hit passing NMS
39-
- maxOverlap : float between 0 and 1, the maximal overlap authorised between 2 bounding boxes, above this value, the bounding box of lower score is deleted
40-
- sortAscending : use True when low score means better prediction (Difference-based score), True otherwise (Correlation score)
31+
- scoreThreshold : Float, used to remove low score detections.
32+
If sortAscending=False, ie when best detections have high scores (correlation method), the detections with score below the threshold are discarded.
33+
If sortAscending=True, ie when best detections have low scores (difference method), the detections with score above the threshold are discarded.
34+
35+
- sortAscending : Boolean
36+
use True when low score means better prediction (Difference-based score), False otherwise (Correlation score).
37+
38+
- N_object : int or infinity/float("inf")
39+
maximum number of best detections to return, to use when the number of object is known.
40+
Otherwise Default=infinity, ie return all detections passing NMS.
41+
42+
- maxOverlap : float between 0 and 1
43+
the maximal overlap (IoU: Intersection over Union of the areas) authorised between 2 bounding boxes.
44+
Above this value, the bounding box of lower score is deleted.
45+
4146
42-
OUTPUT
43-
Panda DataFrame with best detection after NMS, it contains max N detection (but potentially less)
44-
'''
47+
Returns
48+
-------
49+
Panda DataFrame with best detection after NMS, it contains max N detections (but potentially less)
50+
"""
4551
listBoxes = tableHit["BBox"].to_list()
4652
listScores = tableHit["Score"].to_list()
4753

0 commit comments

Comments
 (0)