How should I modify a rotated rectangle to pass it to groupRectangles?

I am trying to detect boxes around objects (canny extracted contours) and sometimes an object would be read as 2 boxes instead of one. No big deal really, except for the fact that I am trying to count those objects. So, I’d like to combine boxes that are overlapping/nearby.

That’s what I’ve been trying so far:

minRect = [None]*len(contours)
for i, c in enumerate(contours):
    minRect[i] = cv2.minAreaRect(c)
minRect, _ = cv2.groupRectangles(minRect, 0)

This throws an error, and I understand why - a rotated rectangle ( minAreaRect output) is not something groupRectangles expects. How can I ‘feed’ a rotated rectangle to groupRectangles ? I’ve tried silly things like ripping out coordinates+measurements, and more reasonable things such as boxPoints . I’ve looked through SO, and OpenCV docs (even some of sources) but couldn’t find anything to answer my question.

you cannot use groupRectangles with RotatedRect,
however, there is a NMSBoxes method in the dnn module to filter “near duplicates”

1 Like

Well, that would remove duplicates. But it wouldn’t merge nearby/overlapping rectangles. Is there a way to combine rectangles?

something like weighted box fusion just for rotated rects …
unfortunately, we dont have it yet ;(