Reputation: 11
I'm trying to group rectangles together using cv2.groupRectangles()
but it returns empty tuple ()
I tried using 2 different versions of opencv-python (4.6.0.66 and 3.4.18.65)
This is the code:
# "do" object detection
rectangles = np.array([
[530, 119, 47, 47],
[641, 117, 53, 53],
[531, 89, 117, 117]])
print(rectangles)
print()
(rect, weights) = cv2.groupRectangles(rectangles, groupThreshold=1, eps=0.5)
print("rect after cv.groupRectangles:", rect)
And this is the output:
[[530 119 47 47]
[641 117 53 53]
[531 89 117 117]]
rect after cv.groupRectangles: ()
Upvotes: 0
Views: 149
Reputation: 15456
Here are your initial rectangles for reference. How were you wanting those to be merged?
You might have chosen groupThreshold
badly.
If that is more than 0, the function will remove any rectangles that aren't "confirmed" by nearby neighbors. With 0
, it's allowed to leave single rectangles alone...
>>> cv.groupRectangles(rectangles, groupThreshold=0, eps=0)
(array([[530, 119, 47, 47],
[641, 117, 53, 53],
[531, 89, 117, 117]]), array([1, 1, 1]))
But then it also doesn't seem to want to merge any of them. That eps
doesn't seem to behave all that "relatively". I get effects when I increase it beyond 1.0.
Documentation is very poor about this. Perhaps this function is broken. If not broken, then it's at least not documented well enough for me to make sense of it and I think I'm proficient with OpenCV.
Upvotes: 1