image.png
开操作:目的去除小噪点,但原状大小不变
image.png
def open_function(image):
print(image.shape)
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
ret, binary = cv.threshold(
gray, 0, 255, cv.THRESH_BINARY | cv.THRESH_OTSU)
cv.imshow("binary", binary)
kernel = cv.getStructuringElement(cv.MORPH_RECT, (3, 3))
'''
cv.morphologyEx:
op :要执行的形态学操作是什么(开操作)
'''
dst = cv.morphologyEx(binary, op=cv.MORPH_OPEN, kernel =kernel)
cv.imshow("open_result", dst)
只是去掉小噪点
闭操作:目的填充小的封闭区域
image.png
dst = cv.morphologyEx(binary, op=cv.MORPH_CLOSE, kernel =kernel)
image.png
水平直线提取
#在开操作的结构元素大小取(30,1)
kernel = cv.getStructuringElement(cv.MORPH_RECT, (30, 1))
水平直线
垂直直线提取
kernel = cv.getStructuringElement(cv.MORPH_RECT, (1, 30))
垂直直线
网友评论