python - 我使用cv2.connectedComponentsWithStats时产生噪音

标签 python numpy opencv image-processing cv2

我想从这张图片中提取字母:
enter image description here

当我尝试使用connectedComponentsWithStats时,我得到了很多标签,但它们像下面的示例一样嘈杂:
enter image description here
这是我的代码中应该提取字母的部分:

def ExtractLetters(img):
    blur_radius = 0.1
    nlabel, labels,stats,centroids = cv2.connectedComponentsWithStats(img)
    thresh_size=30
    for i in range(1, nlabel):
        img = np.zeros(img.shape, dtype=np.uint8)
        if (stats[i, cv2.CC_STAT_WIDTH] > thresh_size) or (stats[i, cv2.CC_STAT_HEIGHT]>thresh_size):
            img[labels == i] = 255
            img = 255 - img
            cv2.imshow("test", img)
            cv2.waitKey()

您知道为什么会出现这些噪音吗?

最佳答案

在找到connectedComponentsWithStats之前,需要将图像RGBA转换为灰度和阈值。

关于python - 我使用cv2.connectedComponentsWithStats时产生噪音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61158938/

相关文章:

python - 使用 kenlm 的负面结果

python - 使用具有非唯一条目的辅助数组从主数组中查找索引列表

python - 将多项式回归从 R 移植到 python

python /数巴 : Trouble creating custom type using Numba Extension API

opencv - 正态贝叶斯分类器负样本

python - 合并来自不同文件夹的图像并将其存储到另一个文件夹

python - 方法调用后更改变量值

python - 单词搜索的递归函数

python - 将特定时间量添加到日期时间列

python - OpenCV:描述符矩阵的L1归一化