The previous recipe introduced you to the two fundamental morphological operators—dilation and erosion. From these, other operators can be defined. This and the following recipe will present some of them. The opening and closing operators are presented in this recipe.
Opening and closing images using morphological filters
How to do it...
In order to apply higher level morphological filters, you need to use the cv::morphologyEx function with the appropriate function code:
- To create a closing or opening operator, we have to create a cv::Mat element that will be used as an opening/close kernel:
cv::Mat element5(5,5,CV_8U,cv::Scalar(1));
- Now, we have to create another cv::Mat to store the result of applying our morphological...