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

Drawing the boundary

We achieve this using a morphological gradient. This is the operation that draws the boundary around a shape by taking the difference between the dilation and erosion of an image:

Let's look at the function to perform morphological gradient:

Mat performMorphologicalGradient(Mat inputImage, int morphologyElement, int morphologySize){    Mat outputImage, tempImage1, tempImage2;    int morphologyType;    if(morphologyElement == 0)        morphologyType = MORPH_RECT;    else if(morphologyElement == 1)        morphologyType = MORPH_CROSS;    else if(morphologyElement == 2)        morphologyType = MORPH_ELLIPSE;    // Create the structuring element for erosion Mat ...

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