如何在opencv中去除图像中的噪声(见输入图片)?我想要实现的输出,我将得到白色背景和黑色的文本只。
发布于 2022-05-24 19:05:48
假设灰度图像,您可以部分地消除这样的噪声:
# thresholding
thresh, thresh_img = cv.threshold(img, 128, 255, 0, cv.THRESH_BINARY)
# erode the image to *enlarge* black blobs
erode = cv.erode(thresh_img, cv.getStructuringElement(cv.MORPH_ELLIPSE, (3,3)))
# fill in the black blobs that are not surrounded by white:
_, filled, _, _ = cv.floodFill(erode, None, (0,0), 255)
# binary and with the threshold image to get rid of the thickness from erode
out = (filled==0) & (thresh_img==0)
# also
# out = cv.bitwise_and(filled, thresh_img)
输出不干净(文本行之间的一些黑点,可以通过阈值连接组件的大小来进一步去除),但这应该是一个好的开始:
https://stackoverflow.com/questions/72367780
复制相似问题