字符识别改进的降噪?

问题描述

我使用 KNN 来检测字符,但是,它对背景噪声很敏感。该图像基本上是我正在使用的图像,并且我开发了一个迷你脚本来尝试获得最佳阈值图像。有没有人有任何建议/改变以获得更好的结果?使 X 更易于查看。 (附加版本的当前输出和输入是什么)

import cv2
import numpy as np

image = cv2.imread("resize.png")
img = image




img = cv2.blur(img,(5,5))
imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)  # get grayscale image
imgBlurred = cv2.GaussianBlur(imgGray,(11,11),5)  # blur
# cv2.imshow("test",imgBlurred)

imgThresh = cv2.adaptiveThreshold(imgBlurred,# input image
                                  255,# make pixels that pass the threshold full white
                                  cv2.ADAPTIVE_THRESH_GAUSSIAN_C,# use gaussian rather than mean,seems to give better results
                                  cv2.THRESH_BINARY_INV,# invert so foreground will be white,background will be black
                                  13,# size of a pixel neighborhood used to calculate threshold value
                                  2)  # constant subtracted from the mean or weighted mean

imgThreshcopy = imgThresh.copy()  # make a copy of the thresh image,this in necessary b/c findContours modifies the image

kernel = np.ones((3,3),np.uint8)
kernel2 = np.ones((7,7),np.uint8)
kernel3 = np.ones((1,1),np.uint8)

imgThreshcopy = cv2.morphologyEx(imgThreshcopy,cv2.MORPH_OPEN,kernel)
imgThreshcopy = cv2.morphologyEx(imgThreshcopy,cv2.MORPH_CLOSE,kernel2)
imgThreshcopy = cv2.dilate(imgThreshcopy,kernel3,iterations=150)

res = imgThreshcopy

cv2.imwrite("test.jpg",res)
cv2.imshow("image",res)
cv2.waitKey(0)

output input

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)