You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from __future__ importdivision, print_function# for compatibility with Py2
14
-
importpandasaspd
15
13
16
-
defPoint_in_Rectangle(Point, Rectangle):
17
-
'''Return True if a point (x,y) is contained in a Rectangle(x, y, width, height)'''
18
-
# unpack variables
19
-
Px, Py=Point
20
-
Rx, Ry, w, h=Rectangle
14
+
importcv2
21
15
22
-
return (Rx<=Px) and (Px<=Rx+w-1) and (Ry<=Py) and (Py<=Ry+h-1) # simply test if x_Point is in the range of x for the rectangle
23
16
24
-
25
-
defcomputeIoU(BBox1,BBox2):
26
-
'''
27
-
Compute the IoU (Intersection over Union) between 2 rectangular bounding boxes defined by the top left (Xtop,Ytop) and bottom right (Xbot, Ybot) pixel coordinates
28
-
Code adapted from https://www.pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/
29
-
'''
30
-
#print('BBox1 : ', BBox1)
31
-
#print('BBox2 : ', BBox2)
32
-
33
-
# Unpack input (python3 - tuple are no more supported as input in function definition - PEP3113 - Tuple can be used in as argument in a call but the function will not unpack it automatically)
34
-
Xleft1, Ytop1, Width1, Height1=BBox1
35
-
Xleft2, Ytop2, Width2, Height2=BBox2
36
-
37
-
# Compute bottom coordinates
38
-
Xright1=Xleft1+Width1-1# we remove -1 from the width since we start with 1 pixel already (the top one)
39
-
Ybot1=Ytop1+Height1-1# idem for the height
40
-
41
-
Xright2=Xleft2+Width2-1
42
-
Ybot2=Ytop2+Height2-1
43
-
44
-
# determine the (x, y)-coordinates of the top left and bottom right points of the intersection rectangle
- tableHit : (Panda DataFrame) Each row is a hit, with columns "TemplateName"(String),"BBox"(x,y,width,height),"Score"(float)
96
33
97
34
- scoreThreshold : Float (or None), used to remove hit with too low prediction score.
98
-
If sortDescending=True (ie we use a correlation measure so we want to keep large scores) the scores above that threshold are kept
99
-
While if we use sortDescending=False (we use a difference measure ie we want to keep low score), the scores below that threshold are kept
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
100
37
101
-
- N_object : number of best hit to return (by increasing score). Min=1, eventhough it does not really make sense to do NMS with only 1 hit
38
+
- N_object : maximum number of hit to return. Default=-1, ie return all hit passing NMS
102
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
103
40
- sortAscending : use True when low score means better prediction (Difference-based score), True otherwise (Correlation score)
104
41
105
42
OUTPUT
106
43
Panda DataFrame with best detection after NMS, it contains max N detection (but potentially less)
107
44
'''
45
+
listBoxes=tableHit["BBox"].to_list()
46
+
listScores=tableHit["Score"].to_list()
108
47
109
-
# Apply threshold on prediction score
110
-
ifscoreThreshold==None :
111
-
threshTable=tableHit.copy() # copy to avoid modifying the input list in place
112
-
113
-
elifnotsortAscending : # We keep rows above the threshold
0 commit comments