【问题标题】:noise when i use cv2.connectedComponentsWithStats我使用 cv2.connectedComponentsWithStats 时的噪音
【发布时间】:2020-07-24 07:16:32
【问题描述】:

我想从这张图片中提取字母:

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

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()

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

【问题讨论】:

    标签: python numpy opencv image-processing cv2


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      看起来您的二进制图像已保存为 JPEG,从而引入了压缩伪影。当重新读入图像时,它不再只有两个不同的值。

      在进行连通分量分析之前对图像设置阈值可以解决您的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-05
        • 1970-01-01
        • 1970-01-01
        • 2019-10-04
        • 2018-10-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多