Slimming the shapes

We can achieve this effect using an operation called erosion. This is an operation that makes a shape thinner by peeling the boundary layers of all the shapes in the image:

Slimming the shapes

Let's take a look at the function that performs morphological erosion:

Mat performErosion(Mat inputImage, int erosionElement, int erosionSize) { Mat outputImage; int erosionType; if(erosionElement == 0) erosionType = MORPH_RECT; else if(erosionElement == 1) erosionType = MORPH_CROSS; else if(erosionElement == 2) erosionType = MORPH_ELLIPSE; // Create the structuring element for erosion Mat element = getStructuringElement(erosionType, Size(2*erosionSize + 1, ...

Get OpenCV By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.