使用 OpenCV 对图像执行闭运算
在此程序中,我们将使用 cv2.morphologyEx() 函数执行闭运算。闭运算会消除前景中的小孔,将背景的小孔变为前景。此技术还可以用于在图像中查找特定形状。我们将用于此任务的函数为 cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel)。
原始图像

算法
Step 1: Import cv2 and numpy. Step 2: Read the image. Step 3: Define the kernel. Step 4: Pass the image and kernel to the cv2.morphologyex() function. Step 4: Display the output.
示例代码
import cv2
import numpy as np
image = cv2.imread('testimage.jpg')
kernel = np.ones((5,5), np.uint8)
image = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel)
cv2.imshow('Closing', image)输出

广告
数据结构
网络
关系型数据库管理系统(RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP