当前位置:网站首页>Opencv learning note 5 - gradient calculation / edge detection

Opencv learning note 5 - gradient calculation / edge detection

2022-07-07 08:23:00 I am a little rice

To get the outline , An image can be expanded first and then corroded , Then the result of expansion minus the result of corrosion .

1. Sobel operator

 Please add a picture description
dst = cv2.Sobel(src, ddepth, dx, dy, ksize)

  • ddepth: The depth of the image
  • dx nucleus dy Horizontal and vertical directions respectively
  • ksize yes Sobel Operator size
image1 = cv2.imread('./ro.png')
plt.imshow(image1);

 Please add a picture description

image1 = cv2.imread('./ro.png')
plt.imshow(image1);
image2 = cv2.Sobel(image1, cv2.CV_64F, 1, 0, ksize=3)
plt.imshow(image2);

 Please add a picture description

The convolution calculation from white to black is positive , The convolution calculation from black to white is negative , All negative numbers will be truncated to 0, So take the absolute value

Calculation x Direction gradient

image2 = cv2.Sobel(image1, cv2.CV_64F, 1, 0, ksize=3)
image2 = cv2.convertScaleAbs(image2)
plt.imshow(image2);

 Please add a picture description

Calculation x Direction gradient

image3 = cv2.Sobel(image1, cv2.CV_64F, 0, 1, ksize=3)
image3 = cv2.convertScaleAbs(image3)
plt.imshow(image3);

 Please add a picture description

Get the outline of the image

image4 = cv2.addWeighted(image2, 0.5, image3, 0.5, 0)
plt.imshow(image4);

 Please add a picture description
Try another picture

import cv2
import matplotlib.pyplot as plt
image = cv2.imread('image.png')
image2 = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=3)
image2 = cv2.convertScaleAbs(image2)
image3 = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=3)
image3 = cv2.convertScaleAbs(image3)
image4 = cv2.addWeighted(image2, 0.5, image3, 0.5, 0)
image4 = cv2.cvtColor(image4, cv2.COLOR_BGR2RGB)
plt.imshow(image4);

 Please add a picture description

2. Scharr operator

 Please add a picture description
The usage is the same , But the calculated value will be relatively large , Will be more sensitive

3. laplacian operator

 Please add a picture description

原网站

版权声明
本文为[I am a little rice]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070518493513.html