Next, a non-max suppression function needs to be invoked to avoid detection of the same object at multiple times and scales. The following code block shows how to implement it with the cv2 library functions:
from imutils.object_detection import non_max_suppression# convert our bounding boxes from format (x1, y1, w, h) to (x1, y1, x2, y2)rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in foundBoundingBoxes])# run non-max suppression on these based on an overlay op 65%nmsBoundingBoxes = non_max_suppression(rects, probs=None, overlapThresh=0.65)print(len(rects), len(nmsBoundingBoxes))# 357 1# draw the final bounding boxesfor (x1, y1, x2, y2) in nmsBoundingBoxes: cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), ...