Python OpenCV 形态学操作(腐蚀膨胀,开运算和闭运算)

Python OpenCV 形态学操作(腐蚀膨胀,开运算和闭运算)


过滤器生成

kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) # 椭圆结构
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3)) # 十字结构
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)) # 矩形结构



腐蚀膨胀开、闭运算

# -*-encoding:utf-8-*-
import pytesseract
from PIL import Image
from PIL import ImageFilter
from PIL import ImageFont
from PIL import ImageDraw
import numpy as np
from PIL import Image

import cv2


def main():
# img = cv2.imread("test001.jpg") #读取图片
# cv2.imshow("1",img) #显示图片
# cv2.waitKey(10000)# 延时10s

# image = Image.open("test002.png")
# img = image.convert('1') # 转化为灰度图

# img.show()

img = cv2.imread("test002.png", 0)
kernel = np.ones

你可能感兴趣的:(OpenCV)