How it works...
The morphologyEx() function from opencv-python is used to apply morphological operations to an image. The function accepts the source image (that is, the binary image) and a morphological operation (such as cv2.MORPH_CLOSE and cv2.MORPH_OPEN) and the SE kernel (for example, np.ones((4,4),np.uint8) for a 4 x 4 square kernel) for the morphological operation.
The cv2.findContours() and cv2.drawContours() functions were used to find and draw the contours, respectively. Each contour on the output image was drawn with a random color outline and then displayed one at a time by looping over the contours found.
(np.random.randint(0,255), np.random.randint(0,255), np.random.randint(0,255)) was used to generate a random BGR tuple. The ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access