How it works...

The Canny operator is generally based on the Sobel operator (presented in Chapter 6, Filtering the Images), although other gradient operators can also be used. The key idea here is to use two different thresholds in order to determine which point should belong to a contour a low or a high threshold.

The low threshold should be chosen in a way that it includes all edge pixels that are considered to belong to a significant image contour. For example, by using the low-threshold value specified in the example of the preceding section and applying it on the result of a Sobel operator, the following edge map will be obtained:

Get OpenCV 4 Computer Vision Application Programming Cookbook - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.