1 | initial version |
You can obtain the rectangle with minAreaRect. Or you could also try Non-Maximum Suppression.
rects = []
for cnt in contours:
if cv2.contourArea(cnt) >= limit_area:
x, y, w, h = cv2.boundingRect(cnt)
rects.append((x, y))
rects.append((x+w, y+h))
box = cv.minAreaRect(np.asarray(arr))
pts = cv.boxPoints(box) # 4 outer corners