gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 16:16:28 25 4
gpt4 key购买 nike

我想从这张图片中提取字母:
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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com