当前位置: 首页>>代码示例>>Python>>正文


Python image.ImageCaptcha方法代码示例

本文整理汇总了Python中captcha.image.ImageCaptcha方法的典型用法代码示例。如果您正苦于以下问题:Python image.ImageCaptcha方法的具体用法?Python image.ImageCaptcha怎么用?Python image.ImageCaptcha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在captcha.image的用法示例。


在下文中一共展示了image.ImageCaptcha方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_image_captcha

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def create_image_captcha(captcha_text):
    image_captcha = ImageCaptcha()
    # Create the captcha image.
    image = image_captcha.generate_image(captcha_text)

    # Add noise curve for the image.
    # image_captcha.create_noise_curve(image, image.getcolors())

    # Add noise dots for the image.
    # image_captcha.create_noise_dots(image, image.getcolors())

    # Save the image to a png file.
    image_file = "./captcha_"+captcha_text + ".png"
    imgByteArr = BytesIO()
    image.save(imgByteArr, format='PNG')
    imgByteArr = imgByteArr.getvalue()
    open("test.png", "wb").write(imgByteArr)
    #image_captcha.write(captcha_text, image_file)

    print(image_file + " has been created.")

# Create an audio captcha file. 
开发者ID:Igoorx,项目名称:PyRoyale,代码行数:24,代码来源:captcha_test.py

示例2: gen_captcha

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def gen_captcha(charset,nb_chars=None,font=None):
    if not font is None:
        image = ImageCaptcha(fonts=[font])

    buffer_index=1000
    buffer_size=1000
    nc_set = np.zeros(buffer_size)


    while True:
        if buffer_index==buffer_size:
            nc_set = np.random.randint(3, MAXLEN+1, buffer_size) if nb_chars is None else np.array([nb_chars] * buffer_size)
            buffer_index=0
        captcha_text = ''.join(random_chars(charset,nc_set[buffer_index]))
        buffer_index+=1

        img_text = ' '*np.random.randint(0,MAXLEN+1-len(captcha_text))*2+captcha_text #用空格模拟偏移
        captcha = image.generate(img_text)
        captcha_image = Image.open(captcha).resize((TARGET_WIDTH,TARGET_HEIGHT),Image.ANTIALIAS)
        #image.write(captcha_text, captcha_text + '.jpg')  # 写到文件
        captcha_array = np.array(captcha_image)
        yield captcha_array,captcha_text 
开发者ID:airaria,项目名称:CaptchaRecognition,代码行数:24,代码来源:GenCaptcha.py

示例3: __init__

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def __init__(self, img_width, img_height, ds_size, n_chars=4, chars=None):
        self.gen = ImageCaptcha(img_width, img_height)
        self.size = ds_size

        self.n_chars = n_chars

        if chars is None:
            self.chars = list('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
        else:
            self.chars = list(chars)

        self.tokenizer = Tokenizer(self.chars)

        self.first_run = True 
开发者ID:wptoux,项目名称:attention-ocr,代码行数:16,代码来源:dataset.py

示例4: __init__

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def __init__(self, h, w, font_paths):
        """
        Parameters
        ----------
        h: int
            Height of the generated images
        w: int
            Width of the generated images
        font_paths: list of str
            List of all fonts in ttf format
        """
        self.captcha = ImageCaptcha(fonts=font_paths)
        self.h = h
        self.w = w 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:16,代码来源:captcha_generator.py

示例5: main

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def main():
        parser = argparse.ArgumentParser()
        parser.add_argument("font_path", help="Path to ttf font file")
        parser.add_argument("output", help="Output filename including extension (e.g. 'sample.jpg')")
        parser.add_argument("--num", help="Up to 4 digit number [Default: random]")
        args = parser.parse_args()

        captcha = ImageCaptcha(fonts=[args.font_path])
        captcha_str = args.num if args.num else DigitCaptcha.get_rand(3, 4)
        img = captcha.generate(captcha_str)
        img = np.fromstring(img.getvalue(), dtype='uint8')
        img = cv2.imdecode(img, cv2.IMREAD_GRAYSCALE)
        cv2.imwrite(args.output, img)
        print("Captcha image with digits {} written to {}".format([int(c) for c in captcha_str], args.output)) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:16,代码来源:captcha_generator.py

示例6: get_challenge

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def get_challenge(self, obj: models.Captcha):
        # TODO Does this need to be stored in the object instance, in case this method gets called twice?
        challenge = ImageCaptcha().generate(obj.content).getvalue()
        return b64encode(challenge) 
开发者ID:desec-io,项目名称:desec-stack,代码行数:6,代码来源:serializers.py

示例7: generate_captcha

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def generate_captcha(text='1'):
    capt = ImageCaptcha(width=28, height=28, font_sizes=[24])
    image = capt.generate_image(text)
    image = np.array(image, dtype=np.uint8)
    return image 
开发者ID:Shirhe-Lyh,项目名称:multi_task_test,代码行数:7,代码来源:generate_train_data.py

示例8: gen_special_img

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def gen_special_img(text, file_path, width, height):
    # 生成img文件
    generator = ImageCaptcha(width=width, height=height)  # 指定大小
    img = generator.generate_image(text)  # 生成图片
    img.save(file_path)  # 保存图片 
开发者ID:nickliqian,项目名称:cnn_captcha,代码行数:7,代码来源:gen_sample_by_captcha.py

示例9: gen_special_img

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def gen_special_img():
    # 随机文字
    text = ""
    for j in range(char_count):
        text += random.choice(characters)
    print(text)
    # 生成img文件
    generator = ImageCaptcha(width=width, height=height)  # 指定大小
    img = generator.generate_image(text)  # 生成图片
    imgByteArr = io.BytesIO()
    img.save(imgByteArr, format='PNG')
    imgByteArr = imgByteArr.getvalue()
    return imgByteArr 
开发者ID:nickliqian,项目名称:cnn_captcha,代码行数:15,代码来源:webserver_captcha_image.py

示例10: gen_captcha_text_image

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def gen_captcha_text_image(c_set):
    """
    # 生成字符对应的验证码
    """
    image = ImageCaptcha(width=120, height=60)
    captcha_text = random_captcha_text(char_set=c_set)
    captcha_text = ''.join(captcha_text)

    captcha = image.generate(captcha_text)
    captcha_image = Image.open(captcha)
    captcha_image = np.array(captcha_image)

    return captcha_text, captcha_image 
开发者ID:jarvisqi,项目名称:deep_learning,代码行数:15,代码来源:tf_GAN.py

示例11: test_image_generate

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def test_image_generate():
        captcha = ImageCaptcha()
        data = captcha.generate('1234')
        assert hasattr(data, 'read')

        captcha = WheezyCaptcha()
        data = captcha.generate('1234')
        assert hasattr(data, 'read') 
开发者ID:lepture,项目名称:captcha,代码行数:10,代码来源:test_image.py

示例12: gen

# 需要导入模块: from captcha import image [as 别名]
# 或者: from captcha.image import ImageCaptcha [as 别名]
def gen(gen_dir, total_size, chars_num):
  if not os.path.exists(gen_dir):
    os.makedirs(gen_dir)
  image = ImageCaptcha(width=IMAGE_WIDTH, height=IMAGE_HEIGHT,font_sizes=[40])
  # must be subset of config.CHAR_SETS
  char_sets = 'ABCDEFGHIJKLMNPQRSTUVWXYZ'
  for i in xrange(total_size):
    label = ''.join(random.sample(char_sets, chars_num))
    image.write(label, os.path.join(gen_dir, label+'_num'+str(i)+'.png')) 
开发者ID:PatrickLib,项目名称:captcha_recognize,代码行数:11,代码来源:captcha_gen_default.py


注:本文中的captcha.image.ImageCaptcha方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。