在python中使用opencv去除图像中的高密度噪声

时间:2019-02-23 05:40:42

标签: python opencv computer-vision

我正在尝试检测数字电表中的数字。我现在面临的问题是图像有低噪点,即使添加了许多滤镜,我也无法消除噪点而不会使数字失真。这是我到目前为止所实现的:

img = cv2.imread(image_path)
img = cv2.resize(img  , (280 , 70))

gamma = 2.5

# apply gamma correction and show the images
gamma = gamma if gamma > 0 else 0.1
img = adjust_gamma(img, gamma=gamma)

img = applyClahe(img)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.GaussianBlur(img, (3, 3), 0)
dst = cv2.fastNlMeansDenoising(img,None,3,10,21)
thresh = cv2.adaptiveThreshold(dst,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
            cv2.THRESH_BINARY,11,2)
kernel = np.ones((1,2), np.uint8)
thresh = cv2.erode(thresh, kernel, iterations=1)
thresh = cv2.fastNlMeansDenoising(thresh,None,30,15,30)
connectivity = 4 
thresh = cv2.medianBlur(thresh, 3)

1.jpg enter image description here

enter image description here enter image description here

还有没有更强大的算法可以过滤掉这些噪音?

1 个答案:

答案 0 :(得分:1)

尝试使用niBlackThreshold。我正在运行this example,结果是: enter image description here

还不错吗?