我有下面列出的这 3 张验证码图像,我想使用 opencv 使文本尽可能干净。有没有可以实现我想要的管道?
这是我想要的一个例子:
这里最大的问题是字母的色差。任何帮助,将不胜感激!
这是我的代码中包含所有图像预处理的一些部分
raw_img = cv2.imread(image_file) #load image
img = cv2.cvtColor(raw_img, cv2.COLOR_RGB2GRAY) #grayscale
_,thresh = cv2.threshold(img,240,255, cv2.THRESH_BINARY_INV + cv2.THRESH_TRUNC) #thresholding
thresh = cv2.bitwise_not(thresh) #invert black and white
#resizing image
resized = cv2.resize(img, (140, 60), interpolation=cv2.INTER_AREA)
img_gray = cv2.copyMakeBorder(resized, 10, 10, 10, 10, cv2.BORDER_CONSTANT, value=[255, 255, 255])
#blur
blur = cv2.GaussianBlur(img_gray, (3, 3), 0)
# threshold again
_, img = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY or cv2.THRESH_OTSU)
cv2.imshow("Output", img)
cv2.waitKey()
但是,如果我将相同的代码应用于第二个 iamge,例如,这就是我得到的:
我对 OpenCV 比较陌生。我不确定我是否在这里使用了正确的方法,如果有人可以帮助我展示其他方法来清理这些图像,我会非常感激!