python opencv cv2.erode
时间: 2023-10-11 19:07:08 浏览: 85
python2的opencv库
4星 · 用户满意度95%
The cv2.erode() function in OpenCV is used to perform erosion on an image. Erosion is a morphological operation that shrinks the boundaries of foreground objects in an image.
Syntax:
cv2.erode(src, kernel, iterations)
Parameters:
- src: Input image
- kernel: Structuring element used for erosion
- iterations: Number of times erosion is applied
Return Value:
The function returns the eroded image.
Example:
```
import cv2
import numpy as np
# Read input image
img = cv2.imread('input.jpg', 0)
# Define kernel
kernel = np.ones((5,5), np.uint8)
# Perform erosion
eroded_img = cv2.erode(img, kernel, iterations=1)
# Display images
cv2.imshow('Input Image', img)
cv2.imshow('Eroded Image', eroded_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
In this example, we perform erosion on the input image using a 5x5 kernel with one iteration. The eroded image is then displayed using OpenCV's imshow() function.
阅读全文