Skip to content

Commit

Permalink
Switched overlap to IoU.
Browse files Browse the repository at this point in the history
  • Loading branch information
Namburger committed Jul 17, 2020
1 parent df65a77 commit 119385e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions imutils/object_detection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# import the necessary packages
import numpy as np

def non_max_suppression(boxes, probs=None, overlapThresh=0.3):
def non_max_suppression(boxes, probs=None, iouThresh=0.3):
# if there are no boxes, return an empty list
if len(boxes) == 0:
return []
Expand Down Expand Up @@ -53,13 +53,15 @@ def non_max_suppression(boxes, probs=None, overlapThresh=0.3):
w = np.maximum(0, xx2 - xx1 + 1)
h = np.maximum(0, yy2 - yy1 + 1)

# compute the ratio of overlap
overlap = (w * h) / area[idxs[:last]]
# compute the IoU
intersections = w * h
IoU = intersections / (area[idxs[:last]] + area[i] - intersections)

# delete all indexes from the index list that have overlap greater
# than the provided overlap threshold
idxs = np.delete(idxs, np.concatenate(([last],
np.where(overlap > overlapThresh)[0])))
np.where(IoU > iouThresh)[0])))

# return only the bounding boxes that were picked
return boxes[pick].astype("int")
return boxes[pick].astype("int")

0 comments on commit 119385e

Please sign in to comment.