Morphological filters can also be used to detect specific features in an image. In this recipe, we will learn how to detect contours and corners in a gray-level image.
In this recipe, the following image will be used:
The edges of an image can be detected by using the appropriate filter of the
cv::morphologyEx function. Refer to the following code:
// Get the gradient image using a 3x3 structuring element cv::Mat result; cv::morphologyEx(image,result, cv::MORPH_GRADIENT,cv::Mat()); // Apply threshold to obtain a binary image int threshold= 40; cv::threshold(result, ...