繁体   English   中英

如何使用 OpenCV 去除此图像的黑点?

[英]How to remove black dots of this image using OpenCV?

是否可以使用 OpenCV 去除那些黑点而不影响图像文本?

到目前为止,我已经尝试过 dilation、morphologyEx、erode 等。

在此处输入图像描述

也许尝试将字母连接到大斑点,并删除小斑点:

img = (cv2.imread(r"your_image.png",cv2.IMREAD_UNCHANGED)==0).astype(np.uint8)

mask=cv2.morphologyEx(img,cv2.MORPH_CLOSE,np.ones((20,40))) # this will connect letters together
out = cv2.connectedComponentsWithStats(mask, 4, cv2.CV_32S) # count pixel in each blob
bad = out[2][:,cv2.CC_STAT_AREA]<2000 %remove small blobs
mask = np.zeros_like(img,dtype=np.uint8)
for i in range(1,out[0]):
    if not bad[i]:
        mask[out[1] == i] = 1
img_clean = img & mask
plt.imshow(1-img_clean,interpolation="none",cmap='gray')

它并不完美,但它是一个开始,希望它有所帮助。 在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM