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

一、简介

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

相关推荐
Sunflower_ac21 小时前
线性代数学习笔记(未完结)
人工智能·笔记·学习·线性代数·机器学习
一晌小贪欢21 小时前
Python安装最新(2026版)python最新版安装(图文并茂-详细)
开发语言·python·python安装·pycharm安装·python最新安装·pycharm最新安装
简简单单OnlineZuozuo21 小时前
构建能够从失败中学习的自进化AI代理
人工智能·深度学习·学习·语言模型·prometheus·图像识别
BBB努力学习程序设计21 小时前
深入理解 Python 中的__slots__:优化内存与属性管控的利器
python
机器懒得学习21 小时前
通达信分时资金流向分析系统【附源码】
开发语言·python
Goboy21 小时前
贷款上班的我与AI同行的日子
人工智能·机器学习·程序员
Hcoco_me1 天前
大模型面试题29:稀疏注意力是什么?
人工智能·rnn·深度学习·自然语言处理·word2vec
jackylzh1 天前
训练深度学习模型的提速方法
人工智能·深度学习
mg6681 天前
0基础开发学习python工具_____用 Python 从零写一个贪吃蛇游戏:完整实现 + 打包成 .exe(附源码)
python·游戏·pygame·python开发