在进行爬虫识别图形验证码时,为提高准确度,需要自己进行灰度,二值化等操作。
阀值的不同,对结果也会有较大影响,所以,我想问:如何确定阀值的最佳值或范围。
import tesserocr
from PIL import Image
image = Image.open('F:/code.jpg')
image=image.convert('L')
threshold=120 #这个阀值是我一点点实验出来的
table=[]
for i in range(256):
if i<threshold:
table.append(0)
else:
table.append(1)
image=image.point(table,'1')
result = tesserocr.image_to_text(image)
print(result)