Include multiple objects in one contour
I have a problem and I am not sure how to accomplish it. I am working with binary Mat objects that contain many small objects in them. I have used findContours to generate each objects contour and used contourArea to calculate their area. If the objects are too small they are removed from the image. The next step tests for the distance between contours, if the contours are close enough they should be grouped together when their contour is drawn. The function works up until the objects need to be grouped into one contour. After a lot of reading and trying things out I am unable to figure this out. If any one is able to provide guidance I would appreciate it.
Here is an image for what I would like the output to be:
The white blobs are the objects and the red line is my desired contour.