The morphological operations of erosion and dilation are implemented by the erode()
and dilate()
APIs of OpenCV. Since both of the APIs are quite similar in terms of the number and type of arguments that they accept, we would demonstrate them using a single snippet of code as shown here:
#include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> using namespace std; using namespace cv; int main() { Mat input_image = imread("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE); Mat dilated_image(input_image.size(), input_image.type()); Mat eroded_image(input_image.size(), input_image.type()); Mat element = getStructuringElement(MORPH_RECT, Size(5, 5), Point(-1, -1)); dilate(input_image, dilated_image, element, Point(-1, -1), 1); erode(input_image, eroded_image...