當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。