利用打码平台识别点选验证码

利用打码平台识别点选验证码,第1张

目录
        • 一、打码平台-超级鹰使用流程
        • 二、点选验证码注意事项
        • 三、最终代码

一、打码平台-超级鹰使用流程
  • 首先注册用户 ,然后登录
  • 到用户中心,生成一个软件ID
  • 根据自己的代码,下载接口调用代码demo,这里是python
  • 对于普通的字符验证码,我们可以用ddddocr/muggle_ocr识别即可
  • 对于点选验证码,先到这里根据实际情况确定验证码类型,一般点选我们选择如图中的
  • 最终代码调用结构大概如下, post_pic用于传验证码字节流,和验证码类型,然后获得识别结果;resport_error传图片id上报错误的图片识别,不扣分
二、点选验证码注意事项
  • 需要在底部加入提示文字,然后再上传新的拼接图片上去提交
  • 加入提示文字拼接的图片代码
三、最终代码
  • 其中python的超级鹰调用代码,以及点选图片验证码的处理代码如下,超级鹰的账号/密码/软件ID需要替换成自己的
    #!/usr/bin/env python
    # coding:utf-8
    
    import requests
    from hashlib import md5
    from PIL import Image, ImageDraw, ImageFont
    from io import BytesIO
    import cv2
    
    
    class CjyClient:
    
        def __init__(self, username, password, soft_id):
            self.username = username
            self.password = md5(password.encode('utf8')).hexdigest()
            self.soft_id = soft_id
            self.base_params = {
                'user': self.username,
                'pass2': self.password,
                'softid': self.soft_id,
            }
            self.headers = {
                'Connection': 'Keep-Alive',
                'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
            }
    
        def post_pic(self, im, code_type):
            """
            im: 图片字节
            code_type: 题目类型 参考 http://www.chaojiying.com/price.html
            9101 坐标选一,返回格式:x,y	 15
            9004 坐标多选,返回1~4个坐标,如:x1,y1|x2,y2|x3,y3	25
            默认超级鹰识别结果为小写,如果要区分大小写,则文字提示和图片通过程序合成一张图片再上传(点选也是)
            """
            params = {'codetype': code_type}
            params.update(self.base_params)
            files = {'userfile': ('ccc.jpg', im)}
            r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
            return r.json()
    
        def report_error(self, im_id):
            """
            im_id:报错题目的图片ID
            {"err_no":0,"err_str":"OK","pic_id":"1176318810001","pic_str":"241,108|178,62|69,45","md5":"5fd97b61393d02144f019"}
            """
            params = {'id': im_id}
            params.update(self.base_params)
            r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
            return r.json()
    
    
    class ImageProcess:
        @staticmethod
        def slice_img(img_content, save_path="bg.png", words=None):
            """
            合并图片,在底部加入文字提示图片
            Image.new(mode, size, color): 这个方法可以生成一张图片,有三个参数, mode:颜色空间模式,可以是'RGBA','RGB','L'等等模式,  size:图片尺寸,接收一个两个整数的元组,  color:图片的填充颜色,可以是red,green等,也可以是rgb的三个整数的元组。也就是背景颜色
            :param img_content: 传入图片字节流
            :param save_path: 图片保存路径
            :param words: 文字提示
            :return: 返回图片字节流
            """
            img_bg = Image.open(BytesIO(img_content))
            width, height = img_bg.size
            bg_img = Image.new("RGB", (width, height+30), (255, 255, 255))
            bg_img.paste(img_bg, box=(0, 0, width, height))
            if words:
                # 文字填充图片
                font_im = Image.new("RGB", (width, 30), (255, 255, 255))
                dr = ImageDraw.Draw(font_im)
                font = ImageFont.truetype("simsun.ttc", 12, encoding='utf-8')
                dr.text((10, 5), words, font=font, fill="#000000")
                bg_img.paste(font_im, box=(0, height, width, height+30))
            # 获得图片字节流
            bg_img.save(save_path)
            bytes_img_io = BytesIO()
            bg_img.save(bytes_img_io, format='PNG')
            return bytes_img_io.getvalue()
    
        @staticmethod
        def mark_img(path, xy_list):
            """在图片上标记坐标点"""
            image = cv2.imread(path)
            for xy in xy_list:
                image = cv2.circle(image, (xy[0], xy[1]), radius=3, color=(0, 0, 255), thickness=-1)
                cv2.imwrite('./label.png', image)
    
        @staticmethod
        def tran_xy(xy_list_str):
            """
            xy坐标转换
            :param xy_list_str: "241,108|178,62|69,45"
            :return: [[241, 108], [178, 62], [69, 45]]
            """
            xy_lis = [[int(t) for t in xy.split(",")] for xy in xy_list_str.split("|")]
            return xy_lis
    
    
    if __name__ == '__main__':
        Cjy = CjyClient('syy_name', 'w_pwd', '12323123')  # 用户名, 密码, 软件ID(用户中心>>软件ID 生成一个替换 12323123)
        Cjy.post_pic(open('out.png', 'rb').read(), 9004)  # 9004代表验证码类型
        # ImageProcess.slice_img(open('img.png', 'rb').read(), words="请依次点击:哈哈哈")
        # ImageProcess.mark_img('img.png', [(127, 54), (69, 65), (85, 112)])
        # print(ImageProcess.tran_xy("241,108|178,62|69,45"))
    
  • 利用yolov5训练点选
  • ddddocr识别点选

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/798398.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存