I am trying to write some easy code in python to produce bounding rectangles around objects in a binary image, where there may be 1 or more objects. This is fairly easy to achieve with cv2.boundingRect for a single object, or to draw a single rectangle around 2 objects, but it does not seem to handle the multiple separate objects case. For example see the image below:
I would like to get 2 bounding boxes that define the x/y/width/height (or alternatively x1/x2/y1/y2) for EACH object separately. Does anyone know how to do this? Thanks!