Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Take a look at Erosion and Dilation.

Take a look at Erosion and Dilation.

EDIT:

As kbarni pointed out, I liked to just the tutorial on erosion and dilation. The next tutorial is on all the morphology operations, including the one you want, close.

Secondly, that code makes me sad. There is almost no time you want to new a cv::Mat. Especially not like this when it will cause a memory leak. Instead either just pass it (make sure to include the cv::Scalar parameter to initialize it to 255) or use the getStructuringElement method to create it.

Mat kernel = getStructuringElement( MORPH_ELLIPSE, Size( 15, 15 ) );
morphologyEx( image, image, MORPH_CLOSE, kernel );

creates the result

image description

The result you got is likely because you didn't initialize the value of your kernel to anything.