шумоподавление для улучшения распознавания символов?

#python #opencv #image-processing #character #noise-reduction

#python #opencv #обработка изображений #символ #шумоподавление

Вопрос:

Я использую 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)
 

вывод
ввод