Ask Your Question
1

Problem with groupRectangles().

asked Mar 31 '16

sjs7007 gravatar image
a = [[1,2,3,4],[1,2,3,4],[4,5,6,7],[4,5,6,7]]
cv2.groupRectangles(a,1,0)

This returns 2 rectangles [1,2,3,4] and [4,5,6,7] as expected. However if I add a big rectangle to the list, which covers them all, I get just that big rectangle whereas what I want is each rectangle individually.

a = [[1,2,3,4],[1,2,3,4],[4,5,6,7],[4,5,6,7],[0,0,100,100],[0,0,100,100]]
cv2.groupRectangles(a,1,0)

The result of this is just one rectangle [0,0,100,100]. I want [1,2,3,4],[4,5,6,7] and [0,0,100,100].

PS : This is just example data. The rectangles in the original data don't always have the exact same values.

Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Apr 1 '16

updated Apr 1 '16

Your problem is simple, if you look at the groupRectangles criteria. There is the eps parameter which you have set to 0. This last parameter to groupRectangles is epsilon ‘eps’, which controls how much overlap is required in order to merge rectangles. Standard it means that two rectangles need to overlap 20%. However in your case they do not need to overlap at all, which means that your biggest rectangle will always end as the final result.

How it is done in detail can be seen here!

I am pretty sure that demanding an overlap of like 0.85 would do the trick here!

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Mar 31 '16

Seen: 5,796 times

Last updated: Apr 01 '16