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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.