O'Reilly logo

Learn OpenCV 4 by Building Projects - Second Edition by Prateek Joshi, Vinicius G. Mendonca, David Millan Escriva

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

Slimming the shapes

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

Let's 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, 2*erosionSize ...

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