O'Reilly logo

OpenCV Computer Vision Application Programming Cookbook Second Edition by Robert Laganière

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

Detecting edges and corners using morphological filters

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.

Getting ready

In this recipe, the following image will be used:

Getting ready

How to do it...

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, ...

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