国家税务总局中文点选验证码识别

一、简介

2026年元旦节,国家税务总局中文点选验证码居然又更新了。这次更新对识别还是有很大的影响。

1、文字的位置变得随机

2、文字的旋转角度变得更乱

让识别变得更加困难。我们在元旦节期间快速反应,迅速的采集最新的图片,完成了数据标记与训练。最终正确率达到了99%。

二、识别说明

识别这个验证码需要两张原图

1、点击区大图

2、点击顺序的小图

三、识别代码

下面的代码是样例代码,需要制定两张图片的路径,img1是点击区大图,img2是点击顺序小图。图片顺序不能传错。

python 复制代码
import base64
import requests
import datetime
from io import BytesIO
from PIL import Image, ImageDraw, ImageFont

t1 = datetime.datetime.now()

#PIL图片保存为base64编码
def PIL_base64(img, coding='utf-8'):
    img_format = img.format
    if img_format == None:
        img_format = 'JPEG'

    format_str = 'JPEG'
    if 'png' == img_format.lower():
        format_str = 'PNG'
    if 'gif' == img_format.lower():
        format_str = 'gif'

    if img.mode == "P":
        img = img.convert('RGB')
    if img.mode == "RGBA":
        format_str = 'PNG'
        img_format = 'PNG'

    output_buffer = BytesIO()
    # img.save(output_buffer, format=format_str)
    img.save(output_buffer, quality=100, format=format_str)
    byte_data = output_buffer.getvalue()
    base64_str = 'data:image/' + img_format.lower() + ';base64,' + base64.b64encode(byte_data).decode(coding)
    # base64_str = base64.b64encode(byte_data).decode(coding)

    return base64_str

# 加载图片
img1 = Image.open(r'E:\Python\lixin_project\OpenAPI接口测试\test_img\85-1.jpg')
# 图片转base64
img1_base64 = PIL_base64(img1)
img2 = Image.open(r'E:\Python\lixin_project\OpenAPI接口测试\test_img\85-2.png')
# 图片转base64
img2_base64 = PIL_base64(img2)

验证码识别接口
可以根据自己网络情况选择不同接口
http://bq1gpmr8.xiaomy.net(电信)
http://220.167.181.200:9009(移动、电信、联通)

# 验证码识别接口
url = "http://220.167.181.200:9009/openapi/verify_code_identify/"
data = {
    # 用户的key
    "key": "qaXZNkpHniKPxw4ZYJj0",
    # 验证码类型
    "verify_idf_id": "85",
    # 点击区大图
    "img1": img1_base64,
    # 点击顺序小图
    "img2": img2_base64,
}
header = {"Content-Type": "application/json"}

# 发送请求调用接口
response = requests.post(url=url, json=data, headers=header)

# 获取响应数据,识别结果
print(response.text)
print("耗时:", datetime.datetime.now() - t1)

# 标记识别结果
draw = ImageDraw.Draw(img1)
# 字体设置
font_type = "./msyhl.ttc"
font_size = 20
font = ImageFont.truetype(font_type, font_size)
# 获取结果列表
y = response.json()['data']['res_str']
point_list = eval(y)
# 标记点击序号
for i, point in enumerate(point_list):
    draw.ellipse((point[0] - 15, point[1] - 15,point[0] + 15, point[1] + 15), fill=(255, 0, 0))
    draw.text((point[0] - 5, point[1] - 15), str(i + 1), fill=(255, 255, 255), font=font)

img1.show()

运行上面的代码会看到下面的点击效果

想了解更多验证码识别,请访问:http://bq1gpmr8.xiaomy.net/tool/verifyCodeHomePage2/?_=1767453173457

相关推荐
1941s2 分钟前
Google Agent Development Kit (ADK) 指南 第二章:环境搭建与快速开始
人工智能·python·adk·google agent
抓个马尾女孩5 分钟前
位置编码:绝对位置编码、相对位置编码、旋转位置编码
人工智能·深度学习·算法·transformer
天下无贼12 分钟前
【Python】2026版——FastAPI 框架快速搭建后端服务
后端·python·aigc
小蚂蚁i16 分钟前
LangChain 完全学习手册:看完就能上手
后端·python·ai编程
哥布林学者31 分钟前
高光谱成像基础(完)光谱融合(Spectral Fusion)
机器学习·高光谱成像
高工智能汽车39 分钟前
前沿之声 | 塑造自动驾驶体验的半导体技术
人工智能·机器学习·自动驾驶
Aawy1201 小时前
Python生成器(Generator)与Yield关键字:惰性求值之美
jvm·数据库·python
YFJ_mily1 小时前
【杭州线下召开】2026年计算智能与机器学习国际学术会议(CIML 2026)
人工智能·机器学习
这张生成的图像能检测吗1 小时前
(论文速读)SFAFBR:一种自监督的人工特征偏置校正框架
人工智能·深度学习·神经网络·机器学习·故障诊断·自监督学习
沐硕1 小时前
《基于改进协同过滤与多目标优化的健康饮食推荐系统设计与实现》
java·python·算法·fastapi·多目标优化·饮食推荐·改进协同过滤