How it works...

The Sobel operator is a classic edge-detection linear filter that is based on a simple 3x3 kernel that has the following structure:

-1

0

1

-2

0

2

-1

0

1

-1

-2

-1

0

0

0

1

2

1

If we view the image as a two-dimensional function, the Sobel operator can then be seen as a measure of the variation of the image in the vertical and horizontal directions. In mathematical terms, this measure is called a gradient, and it is defined as a 2-D vector that is made from the function's first derivatives in two orthogonal directions:

Therefore, the Sobel operator gives you an approximation ...

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.