cv2.ximgproc.thinning
时间: 2024-01-03 07:45:50 浏览: 46
cv2.ximgproc.thinning is a function in the OpenCV library that performs thinning on binary images. Thinning is the process of reducing the thickness of foreground regions in an image while preserving the connectivity of the foreground pixels. It is often used in image processing applications such as character recognition and computer vision.
The cv2.ximgproc.thinning function uses the Zhang-Suen algorithm to perform thinning. This algorithm iteratively removes pixels from the foreground until the image is completely thinned. The function takes a binary image as input and returns the thinned binary image as output.
Here is an example of how to use the cv2.ximgproc.thinning function in Python:
```
import cv2
# Read binary image
img = cv2.imread('binary_image.png', cv2.IMREAD_GRAYSCALE)
# Perform thinning
thinned_img = cv2.ximgproc.thinning(img)
# Display thinned image
cv2.imshow('Thinned Image', thinned_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
In this example, we first read a binary image and then apply the cv2.ximgproc.thinning function to obtain the thinned image. Finally, we display the thinned image using the OpenCV imshow function.