如何使用 python 制作十字形内核以在 openCV 中应用形态变换?

How to make a cross shaped kernel to apply morphological transformations in openCV using python?

我是初学者,我不知道如何使用 python 在 openCV 中制作十字形内核?我想制作一个 3x3 十字形内核,这样我就可以对 A1 应用形态变换,而内核是 B1。

这是A1和B1的图片。

这就是我的内核,但我收到一个名称错误:名称 'array' 未定义。

# Cross-shaped kernel (structuring element)
cv.getStructuringElement(cv.MORPH_CROSS,(3,3))
kernel = array ([[0, 1, 0],
                [1, 1, 1],
                [0, 1, 0]], dtype = cv.uint8)

数组函数是numpy的一部分。这就是创建 kernel/array:

的方法
import numpy as np  

kernel = np.array([[0, 1, 0],
                [1, 1, 1],
                [0, 1, 0]], dtype = np.uint8)