Steps to download requirements below:
sudo aptget install libopencvdev pythonopencv
bash installopencv.sh
on your terminal.
Edge detection principle
Edge detection involves mathematical methods to find the points in an image where the brightness of the pixels changes distinctly.
Note. In computer vision, the transition from black to white is considered a positive slope, and the transition from white to black — negative.

Derived image calculation
A digital image is represented by a matrix that stores the RGB / BGR / HSV value (which color space the image belongs to) of each pixel in rows and columns.
The derivative of the matrix is calculated by an operator called the Laplacian . To compute the Laplacian, you will need to compute the first two derivatives, called Sobel derivatives, each of which accounts for changes in the gradient in a particular direction: one horizontal, the other vertical.
Ratio = 11 — 2 2 2 2 2 = 3
Offset = 0
Weighted sum = 124 * 0 + 19 * ( 2) + 110 * ( 2) + 53 * 11 + 44 * ( 2) + 19 * 0 + 60 * ( 2) + 100 * 0 = 117
O [4,2] = (117/3) + 0 = 39
So at the end, to get the Laplacian (approximation), we will need to combine the two previous results (Sobelx and Sobely) and save it in Laplacians.
Parameters :
cv2.Sobel (original_image, ddepth, xorder, yorder, kernelsize)
where the first parameter is — original image, second parameter — depth of the target image. When ddepth = 1 / CV_64F, the destination image will have the same depth as the source. The third parameter — this is the order of the derivative of x. The fourth parameter — this is the order of the derivative y. When calculating Sobelx, we will set xorder to 1 and yorder to 0, while when calculating Sobly, the case will be the opposite. The last parameter — this is the size of the extended Sobel kernel; it should be 1, 3, 5 or 7.
cv2.Laplacian (frame, cv2.CV_64F)first parameter — the original image, and the second parameter — depth of the target image. When depth = 1 / CV_64F, the final image will have the same depth as the original image.
Applications for edge detection