O'Reilly logo

Computer Vision with Python 3 by Saurabh Kapur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Contour detection

Let's start with one of the easiest techniques of segmentation—contours. Simply put, contours are nothing but boundaries of objects in an image. Say, for example, you have different types of bottles in an image and you want to segment out each one of them. The contour detection algorithm will try to trace out the boundaries for each bottle and form a closed loop. Each closed loop in the image represents a contour. You might wonder, aren't contours similar to edges? There is a very subtle difference between them—contours always form closed loops whereas edges can remain open. A contour detection algorithm will try to group edges together that will result in a closed loop.

The following is the code used to extract contours ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required