我正在尝试处理验证码图像。我想处理不同类型的验证码图像来提取实际文本。我正在使用open cv来做这项工作,它工作得很好,但问题是我需要设置不同的下限阈值来将灰度转换为二进制图像。
主要目标:我试着去掉水平线,使字符清晰易读
使用的代码:
import cv2
# Load an color image in grayscale
img = cv2.imread('it_captcha3.jpg',0)
ret, thresh_img = cv2.threshold(img, 180, 255, cv2.THRESH_BINARY_INV)
cv2.imshow('grey image',thresh_img)
cv2.imwrite("result11.jpg", thresh_img)
cv2.waitKey(0)
cv2.destroyAllWindows()Captcha1:

处理后的图像:阈值使用->低: 180高->255,

验证码:2

已处理图像:阈值已用->低: 200高->255

验证码:3

已处理:低-> 165高: 255

发布于 2018-09-18 22:12:37
你试过直方图均衡化吗?
您可以使多个镜像的数据散度更稳定。
import cv2
# Load an color image in grayscale
img = cv2.imread('it_captcha3.jpg',0)
img = cv2.equalizeHist(img)
ret, thresh_img = cv2.threshold(img, 215, 255, cv2.THRESH_BINARY_INV)
cv2.imshow('grey image',thresh_img)
cv2.imwrite("result11.jpg", thresh_img)
cv2.waitKey(0)
cv2.destroyAllWindows()在我的试验中,阈值低值固定为215。
发布于 2018-09-19 23:56:49
查看有关https://docs.opencv.org/3.4.0/d7/d4d/tutorial_py_thresholding.html的opencv文档
此算法适用于您的应用程序
我建议你学习图像二值化。
+)
您还可以查看其他解决方案
https://stackoverflow.com/questions/52387590
复制相似问题