[英]Converting greyscale to binary which detect threshold automatically - opencv - python
我正在尝试处理验证码图像。我想处理不同类型的验证码图像以提取实际文本。我正在使用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()
验证码1:
处理的图像:使用的阈值->低:180高-> 255,
验证码:2
处理的图像:使用的阈值->低:200高-> 255
验证码:3
已处理:低-> 165高:255
您是否尝试过直方图均衡化?
您可以使局部图像的数据散度更稳定。
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。
查看有关https://docs.opencv.org/3.4.0/d7/d4d/tutorial_py_thresholding.html的 opencv文档
该算法适合您的应用
我建议您研究图像二值化。
+)
您也可以看看其他解决方案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.