开运算opencv-python
时间: 2023-10-07 20:12:33 浏览: 110
Python-openCV开运算实例
开运算是一种形态学图像处理操作,通过先对图像进行腐蚀,再进行膨胀来实现。它能够排除小团块物体。在OpenCV中,可以使用`cv2.morphologyEx`函数来进行开运算操作。下面是一个示例代码:
```python
import cv2
import numpy as np
img = cv2.imread("./cycle.png", cv2.IMREAD_COLOR)
kernel = np.ones((5, 5), np.uint8)
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
cv2.imshow("opening", opening)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
运行以上代码,将会展示开运算后的图像。开运算在图像处理中常用于平滑图像、去除噪点和小物体等操作。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* *2* *3* [python-opencv 之开运算、闭运算、形态学梯度、“礼帽”和“黑帽”](https://blog.csdn.net/qq_38505858/article/details/126832149)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文