Thickening the shapes

We use an operation called dilation to achieve thickening. This is an operation that makes a shape thicker by adding boundary layers to all the shapes in the image:

Thickening the shapes

Here is the code to do this:

Mat performDilation(Mat inputImage, int dilationElement, int dilationSize) { Mat outputImage; int dilationType; if(dilationElement == 0) dilationType = MORPH_RECT; else if(dilationElement == 1) dilationType = MORPH_CROSS; else if(dilationElement == 2) dilationType = MORPH_ELLIPSE; // Create the structuring element for dilation Mat element = getStructuringElement(dilationType, Size(2*dilationSize + 1, 2*dilationSize + 1), Point(dilationSize, ...

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.