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

Morphological opening

This is the operation that opens a shape. This operator is frequently used for noise removal in images. It's basically erosion followed by dilation. Morphological opening removes small objects from the foreground in the image by placing them in the background:

Here is the function to perform morphological opening:

Mat performOpening(Mat inputImage, int morphologyElement, int morphologySize){    Mat outputImage, tempImage;    int morphologyType;    if(morphologyElement == 0)        morphologyType = MORPH_RECT;    else if(morphologyElement == 1)        morphologyType = MORPH_CROSS;    else if(morphologyElement == 2) morphologyType = MORPH_ELLIPSE; ...

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