0
votes

I have been testing background subtraction using gaussian state model. I am using opencv 2.1.0. I can generate binary image of foreground of the scene. Now all I want to do is Draw countour bounding rectangle to highlight the moving object. I have used cvCountourBoundingRect to obtain the rectangle covering countour. The issue I am facing is in case of multiple countour, sometime nearby rectangle overlaps. Here, can anyone suggest me to prevent overlapping of rectangle? In ideal case, two rectangle should not be overlapped. It rather should be draw a bigger rectagle which covers all two rectangles.

Any suggetion will be greatful.

1
If you have a function, which checks if two rects are intersecting and one to generate a rect that encloses two or more given rects, you just have to find the overlapping ones in your list and merge them, or did I misunderstand your problem?Tobias Hermann
@Dobi you undestande my problem very well. The logic you have explained here is ideal logic. I am looking for smarter way to achieve the same result what I can achieve from the logic you have mentioned. The problem with this is I need to go through the iterations. I though if there is any better alternative. Thanks anyway.sam18

1 Answers

1
votes

There's no ready possibility to do this in OpenCV. But actually the algorithm is very easy:

  1. Cycle through all rectangles and check if two rectangles overlap each other. This topic will be useful: Determine if two rectangles overlap each other?
  2. For every overlapped pair of rectangles create rectangle that contains both of them. To do this you should select one corner from first rectangle and another corner from second rectangle and these two corners will create rectangle for you. I don't think that it's a hard task - just simple math.