opencv腐蚀与膨胀

腐蚀

opencv腐蚀与膨胀_第1张图片opencv腐蚀与膨胀_第2张图片opencv腐蚀与膨胀_第3张图片opencv腐蚀与膨胀_第4张图片
腐蚀的API
erode(img,kernel,interation=1)

import cv2 as cv
import numpy as np


img = cv.imread('demo.jpg')
kernel = np.ones((3,3),np.uint8)
dst = cv.erode(img,kernel,iterations=2)

cv.imshow('dst', dst)
cv.imshow('img', img)
cv.waitKey(0)

opencv腐蚀与膨胀_第5张图片

卷积核的类型

cv.getStructuringElement(type,size)
size值为:(3,3),(5,5),(9,9)
type:
MORPH_RECT, MORPH_ELLIPSE, MORPH_CROSS

import cv2 as cv
import numpy as np


img = cv.imread('demo.jpg')
# kernel = np.ones((3,3),np.uint8)
kernel = cv.getStructuringElement(cv.MORPH_RECT, (7, 7))
print(kernel)
dst = cv.erode(img, kernel, iterations=1)


cv.imshow('dst', dst)
cv.imshow('img', img)
cv.waitKey(0)

膨胀运算

opencv腐蚀与膨胀_第6张图片
api
dilate(img,kernel,interation=1)

import cv2 as cv
import numpy as np


img = cv.imread('demo.jpg')
# kernel = np.ones((3,3),np.uint8)
kernel = cv.getStructuringElement(cv.MORPH_RECT, (7, 7))
print(kernel)
# dst = cv.erode(img, kernel, iterations=1)
dst = cv.dilate(img,kernel,iterations=1)

cv.imshow('dst', dst)
cv.imshow('img', img)
cv.waitKey(0)

opencv腐蚀与膨胀_第7张图片

你可能感兴趣的:(python基础,opencv,基础,opencv,计算机视觉,人工智能)