What
You want to use cv2.findContours()
with hierarchy enabled. Try retr_ccomp.
Why
That will try to find the regions that can be filled in. Or, more precisely, holes in closed contours. Since the sobel filter returned soft edges, we want to detect the closed contours among the soft edges, which will simply be the edges themselves. The holes are the objects.
How
You'll get both a contours
, a list of points, and hierarchy
, a list of tuples. If hierarchy[i][3] is positive, then contours[i] has a parent, and therefore is a hole, since ccomp only allows 2 levels.
I should note we've been working on the image segmentation problem for 50 years and no one has a great solution. You will find that this approach is often unreliable for arbitrary scenes.