__author__ = "WSX"
import cv2 as cv
import numpy as np

def erode_demo(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, (15, 15)) #15*15 的 矩形
    dst = cv.erode(binary, kernel)  #15*15 的 矩形  腐蚀
    cv.imshow("erode_demo", dst)


def dilate_demo(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, (5, 5)) #5*5的 矩形
    dst = cv.dilate(binary, kernel) #膨胀
    cv.imshow("dilate_demo", dst)

 

相关文章:

  • 2022-12-23
  • 2022-02-01
  • 2021-10-05
  • 2021-11-02
  • 2021-05-13
  • 2022-12-23
  • 2022-01-09
猜你喜欢
  • 2021-06-20
  • 2022-02-20
  • 2021-12-15
  • 2021-07-18
  • 2021-08-06
  • 2022-12-23
相关资源
相似解决方案