How to generate the captcha to train with Python

2024/10/11 10:20:52

I would like to use deep learning program for recognizing the captcha using keras with python.

But the big challenge is to generate massive captcha to train. I want to solve a captcha like this enter image description here enter image description here enter image description here

How can i easily generate above massive captcha to train.

Currently, i use python package captcha

from captcha.image import ImageCaptcha  # pip install captcha
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import random
import osnumber = ['0','1','2','3','4','5','6','7','8','9']
MAX_CAPTCHA = 6
WIDTH=100
HEIGHT=30image = ImageCaptcha(width=WIDTH, height=HEIGHT, font_sizes=[30])captcha_text = []
for i in range(MAX_CAPTCHA):c = random.choice(number)captcha_text.append(c)#print(captcha_text)
captcha_text = ''.join(captcha_text)
print(captcha_text)captcha = image.generate(captcha_text)
captcha_image = Image.open(captcha)
captcha_image = np.array(captcha_image)image.write(captcha_text, str(i)+'_'+captcha_text + '.png') 
plt.imshow(captcha_image)
plt.show()  
Answer

If there is no existing similar captcha datasets online I would tackle this problem in the following way:

  1. Get the MNIST dataset
  2. Take one image example and play with it in gimp or some image transformation librari like Open CV, to get a look similar to your captcha examples.
  3. Transform the MNIST examples in a way you find fit (some random noise, and randomized color on black pixels or something)
  4. Train a model on these augmented examples

Now for practical use it depends a little what kind of model you are implementing. If you have a model that can detect and classify all the numbers on the image then you are finished. But if you like to have a simple model that classifies only images with a single digit on them, then you can move a sliding window over your captcha image and only collect outputs of windows for wich the model has high enough confidence that there is some number pressent in the window.

https://en.xdnf.cn/q/118339.html

Related Q&A

Convert PNG to a binary (base 2) string in Python

I Basically want to read a png file and convert it into binary(base 2) and store the converted base 2 value in a string. Ive tried so many things, but all of them are showing some error

Turbodbc installation on Windows 10

I tried installing turbodbc and it gives me the following error and not sure whats wrong here.My python version is 3.7My command line output from Windows 10 Pro. C:\Users\marunachalam\Downloads>pip …

how to convert a text into tuples in a list in python

I am a beginner in python and desperately need someones help.I am trying to convert a text into tuples in a list. The original text was already tokenized and each pos was tagged as below:The/DT Fulton/…

Trying to call a function within class but its not working [duplicate]

This question already has answers here:TypeError: attack() missing 1 required positional argument: self(2 answers)Closed 3 years ago.I am trying to call a function but its not working. here is the code…

Tkinter Label not showing Int variable

Im trying to make a simple RPG where as you collect gold it will be showed in a label, but it doesnt!! Here is the code:def start():Inv=Tk()gold = IntVar(value=78)EtkI2=Label(Inv, textvariable=gold).pa…

How to refer a certain place in a line in Python

I have this little piece of code:g = open("spheretop1.stl", "r") m = open("morelinestop1.gcode", "w") searchlines = g.readlines() file = "" for i, line…

List comprehension output is None [duplicate]

This question already has answers here:Python list comprehension: list sub-items without duplicates(6 answers)Closed 8 years ago.Im new to python and I wanted to try to use list comprehension but outco…

error while inserting into mysql from python for loop [duplicate]

This question already has answers here:Closed 12 years ago.Possible Duplicate:convert list to string to insert into my sql in one row in python scrapy Is this script correct. I want to insert the scra…

Half of Matrix Size Missing

I wanted to ask why is it that some of my matrices in Python are missing a size value? The matrices/arrays that re defined show the numbers in them, but the size is missing and it is throwing me other…

Clicking Side Panel Elements in Selenium Without IFrames

I want to download U.S. Department of Housing and Urban Development data using Pythons Selenium. Heres my code. import os from selenium import webdriver from webdriver_manager.chrome import ChromeDrive…